Skip to content

[Bug][pi] Policy-gate REFUSED receipts (compress.requireNudge / requireRecommendation) charge no failure ledger — endless byte-identical refusals, breaker never arms | 策略门 REFUSED 回执不计入失败账本:逐字重复拒绝、熔断永不启动 #6728

Description

@ackalker

Summary

The two #5683 policy gates (compress.requireNudge, compress.requireRecommendation) return a model-facing REFUSED receipt that charges nothing to the compress failure ledger — neither recordCompressFailure (repeat advice / #4812 short receipt) nor noteCompressLoopFailure (#2146/#847 circuit breaker). So a model that keeps re-submitting a range bili will never accept gets the byte-identical receipt, with no repeat-collapse and no terminal "STOP calling compress" path. In one real pi session that was 9 consecutive verbatim refusals in 125 seconds, ending only when the human typed "please stop calling the compress tool".

Measured cost of that one session: 176K uncached input + 16K output + 253K cache-read tokens on refusal rounds alone, with the prefix cache degrading every round.

This is the half of #6520 that the credit-window fix (#5943, shipped in v0.1.214) does not close: with a live nudge credit the timing gate passes, and the surviving endless-refusal producer is the scope gate.

Environment

  • bili 0.1.213 in the live incidents below (pi plugin mode, [plugin] lane lines in bili.log); re-verified on current master 9495c764d (= v0.1.214 + 2 commits) with the runnable probe below.
  • Host: pi (npm:billion-context plugin entry). Mechanism is lane-neutral — applyRanges is the single execution point for every model-initiated compress across lanes; only the evidence is pi.
  • Client config: compress.requireNudge: true, compress.requireRecommendation: true (both opt-in, both ON for this user).
  • Model: local qwen3.8-flash-next-iq3_s via llama-swap. OS linux.

Live incident A — pi session 01a1d501-0735-73a2-9d98-06c0e35e78fe (Strata, 2026-11-13)

13 compress calls: 3 OK, 10 REFUSED … (compress.requireRecommendation); longest streak 9. bili.log lines 61290–61438 (the receipt names the same spans over and over):

14:18:59  refused out-of-recommendation — span(s) m00159–m00162, m00164–m00167 …
14:19:17  refused out-of-recommendation — span(s) m00159–m00162, m00164–m00167 …
14:19:33  refused out-of-recommendation — span(s) m00159–m00162, m00164–m00167 …
14:19:48  refused out-of-recommendation — span(s) m00159–m00162, m00164–m00167 …
14:20:03  refused out-of-recommendation — span(s) m00159–m00162, m00164–m00167 …
14:20:16  refused out-of-recommendation — span(s) m00159–m00162, m00164–m00167 …
14:20:29  refused out-of-recommendation — span(s) m00158–m00162, m00164–m00167 …
14:20:45  refused out-of-recommendation — span(s) m00158–m00162, m00164–m00167 …
14:21:04  refused out-of-recommendation — span(s) m00158–m00167 outside the current recommendation set

The model was learning (it merged its two block headers into one span m00158–m00167) and still got the same receipt. And bili had already told it to stop, 29 s before the streak, on the success receipt at 13:18:30:

No compressible ranges remain — the context is already at its minimum; continue the task without compressing.

That stop wording lives on the success footer only. Each following refusal receipt re-opens the door — "Call acp_status for the current compressible ranges and stay within them" — which has no answer, and nothing charges the failure ledger to escalate. Only the human ended it (13:21:04, the same second as the 9th refusal):

user: Please stop calling the `compress` tool, it isn't working out, and is a sepparate issue which is out of scope.

Live incident B — pi session 01a1cbcf-a4c5-75fa-9e96-3bc246aafb22 (Strata, 2026-11-11)

17 compress calls: 6 OK, 5 requireRecommendation refusals (18:23:30–18:27:21), 4 requireNudge refusals (19:39:36–19:42:12 — 0.1.213 wording no nudge was injected this turn, fixed by #5943), 1 parse failure (kind=content-not-array, the form bili's own examples taught — fixed by #6438). Two human interventions:

18:27:59 user: Please *stop* calling the `compress` tool, it only results in more failures and dilutes the context.
19:41:13 user: Please stop looping trying to call the `compress` tool, it is useless. There is a
                serious issue in `billion-context` with no known fix yet.

The #5943 credit window removes the timing half of this; the scope-gate half is this issue.

Retrying verbatim is rewarded, and that is what teaches the loop

The recommendation set is recomputed per round and the protected-recent boundary moves as messages arrive, so an identical retry often lands moments later:

refused folded same target
11-13 13:18:09 m00112–m00157 11-13 13:18:30 Compressed m00112–m00130, m00131–m00157 21 s later
11-11 18:25:49 m00042–m00046 11-11 18:26:11 Compressed m00042–m00046 22 s later
11-11 18:27:08 / 18:27:21 m00048–m00051 11-11 18:30:03 Compressed m00001–m00001, m00047–m00056 3 min later

A receipt that never escalates therefore looks, to the model, like a transient condition worth retrying — until it isn't, and then nothing stops it.

Mechanism (current master)

src/stream.ts — the two gate returns happen before any ledger call and never reach one:

  • :1068-1070 requireNudge → return compressResult("[Compression REFUSED: unprompted …", "refused", 0, "unprompted")
  • :1218-1223 requireRecommendation → return compressResult("[Compression REFUSED: out-of-bounds …", "refused", 0, "out-of-recommendation")

Every other reject path charges the ledger: :803, :1134, :1242, :1285, :1346, :1462-1463, :1708-1709 (recordCompressFailure + noteCompressLoopFailure). The breaker text exists and is decisive for the FAILED path:

 [COMPRESS CIRCUIT BREAKER: N consecutive compress failures in this session — …
  STOP calling compress now: do not try other ranges, do not re-issue any previous range …]

(src/stream.ts:260, armed by recordCompressFailure.) Repeated identical receipts are also collapsed for the FAILED path (e03cc4bfc), not for REFUSED.

Runnable probe on current master (9495c764d)

Three cases against applyRanges directly (fresh session, 9 × 5000-char messages, preserveRecentMessages: 2, prepare-time offer m00001–m00004):

// CONTROL — unknown refs, repeats the same payload 6×
applyRanges(parseCompressInput({ content: [{ startId: "m00099", endId: "m00100", summary: SUM }] }), ctx);
// A — credit live (nudgeInjected:true), requireRecommendation ON, submit m00005–m00007 (outside the offer) ×8
storeUnpromptedGate(ctx.session, { nudgeInjected: true, requireNudge: false, requireRecommendation: true });
// B — requireNudge ON, no credit, submit m00001–m00004 (inside the offer) ×8
storeUnpromptedGate(ctx.session, { nudgeInjected: false, requireNudge: true, requireRecommendation: false });

Measured:

=> control:            breakerArmed=true                      (arms by call ≤6, #847/#4812 path works)
=> reqRecommendation:  calls=8 identicalReceipts=true  breakerOrLoopGuardAppeared=false
=> reqNudge:           calls=8 identicalReceipts=true  breakerOrLoopGuardAppeared=false

So the FAILED path escalates and terminates; the two policy-gate paths escalate nothing, 8 times over.

Impact

  • Endless refusal loops on any lane once a model wants to fold something bili will not fold (newest messages, sub-floor spans, spans outside the offer) — pi, proxy, dsh, opencode all share applyRanges.
  • Cost is paid per round on a full history resend; the observed session burned ~176K uncached input tokens in 10 rounds and its cache-read stayed pinned at 28,609 while uncached input grew 8K→19K per round.
  • Availability: this user's mitigation was to uninstall the pi plugin entirely (bili plugin remove pi, 2026-11-13 14:36) — the compression capability went to zero for that lane. That is arguably an availability outcome, not just noise.

Suggested fix (smallest first)

  1. Charge the ledger in both gate branches (src/stream.ts:1069, :1223): call recordCompressFailure(ctx.session, specKey) and, when trackLoop, noteCompressLoopFailure(ctx, specKey) before returning the receipt. Preflight/self-save already bypass these branches (loopTracking:false never reaches the gates), so bili's own overflow backstop is unaffected — availability preserved, exactly the property Provide a non-intrusive feature to disable compression, and allow web-based configuration. | 提供非注入禁止压缩功能,并允许web配置 #5683 was built to keep.
  2. Make the scope-gate receipt terminal when it cannot be satisfied. If recommendedIntervals(ctx) is empty (the "already at its minimum" state), the advice "call acp_status and stay within them" is a dead end; emit the Error: [Compression FAILED: no valid ranges parsed (kind=content-not-array, dropped=1).刷屏 #4812-style stop wording instead ("continue the task; compression happens again only when there is genuinely new content to fold").
  3. Repeat-collapse for REFUSED receipts (same mechanism as e03cc4bfc for parse failures), so the 6 verbatim copies in incident A collapse to one line + a counter.

Items 1 and 2 are ~6 lines in src/stream.ts; item 3 reuses the existing collapse helper.

Prior art / related

Suggested triage

bug · p2 (config workaround exists — turn a knob off; no data loss; folds still work; escalate to p1 if the "lane gets uninstalled" reading counts as an availability defect) · lane pi (mechanism cross-lane) · scope/wiring · category H pi 车道 (mechanism sits under C 压缩引擎行为 / B 折叠预算与资格判定).


中文摘要

compress.requireNudge / compress.requireRecommendation 两个策略门的 REFUSED 回执(src/stream.ts:1069、:1223)在返回前不记入任何失败账本:既不调 recordCompressFailure,也不调 noteCompressLoopFailure。结果是模型连续提交同一个 bili 永远不会折叠的范围时,收到的是逐字重复的拒绝回执——没有重复回执折叠(e03cc4bfc 只覆盖 parse 失败),也没有 #2146/#847 的熔断 STOP 回执。实测:pi 会话 01a1d501…(v0.1.213)9 次连续逐字拒绝(125 秒内),10 个拒绝轮烧掉 ~176K 未缓存 input + 253K cache-read,前缀缓存逐轮劣化;最终靠人工输入"别调 compress"才终止,随后该用户把 pi 插件整个卸载。#5943(已发版 v0.1.214)修掉的是 requireNudge 计时半区;本 issue 记录仍存活的 scope 门半区,并在 master 9495c764d 上用 applyRanges 直接复现:FAILED 路径 ≤6 次内熔断,两个门路径 8 次全同、账本为零。建议:两处门分支补记账(preflight 已由 loopTracking:false 天然豁免),推荐集为空时把回执改成终止型措辞(#4812 风格),并给 REFUSED 补重复折叠。

Activity

  1. ackalker commented on Nov 14, 2026

    @ackalker
    Author

    (ai: llama-swap/qwen3.8-flash-next-iq3_s)

    Triage: p2 · lane pi (mechanism is lane-neutral — applyRanges is the single execution point) · scope/wiring · 主题类别 H pi 车道(机制面属 C 压缩引擎行为 / B 折叠预算与资格判定).

    优先级口径说明:p2 因为存在配置绕行(关掉一个门即可),无数据丢失,折叠本身正常;若把「用户因此整条车道卸载插件」按 §7.3 可用性缺陷读,可升 p1 —— 由 owner 定。

    复现说明:正文里的 probe 是在 master 9495c764d 上实跑后删除的临时文件(未提交)。三段对照已实测:FAILED 路径 ≤6 次内熔断;requireRecommendation / requireNudge 两条 REFUSED 分支各 8 次,回执逐字相同、账本零记账。

    另:#6520 的收尾结论「20 轮窗口下被拒后反复重试的病理会消失」只对 timing 门成立,#6520 本身仍 open;本 issue 带测量数据补上 scope 门那一半。

  2. ranxianglei commented on Nov 14, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

    查重:不重复。 #6728 是唯一针对「策略门 REFUSED 回执不计入失败账本」的 issue。相关但不同:#5889(post-compress footer 措辞,机制不同)、#5943/#5945/#5948(nudge credit window,已关闭)。

    状态:PR #6753 已存在,修复完整,CI 运行中。

    独立验证结论:本会话在 master a8bbb8d231 上独立实现了同一修复并验证通过(typecheck + 27 个门测试 + 13 个相邻测试全绿),确认 PR #6753 的核心修复方向正确。

    PR #6753 与本会话实现的差异(供 reviewer 参考):

    维度 PR #6753 本会话实现
    repeat-collapse ✅ 第 2 次起回执简化为一行 ❌ 跳过(认为 guard/breaker 文本已使回执不再逐字相同)
    空 ranges 处理 ✅ nudge 门 specKey 回退 "unprompted" ❌ 未处理(边缘 case)
    forcedCause ❌ 不传 ✅ 传 "unprompted" / "out-of-recommendation"
    终止措辞检查 recommendedIntervals().length===0 && liveCompressionRanges()?.ranges.length===0(双重检查,冗余) recommended.length===0(单一检查,recommendedIntervals 已含 live 回退)
    测试位置 新文件 tests/issue6728-policy-gate-ledger.test.ts(8 测试) 追加到 tests/issue5683-forbid-unprompted-compress.test.ts(+5 测试)

    按 HARD RULE(一个 thread 一个 fix PR),本会话未开并行 PR,也未向 fork 分支推送(无写权限)。

    八问:

    1. 是什么问题:两个策略门(compress.requireNudge / compress.requireRecommendation)的 REFUSED 回执不计入压缩失败账本——模型反复提交同一范围时收到逐字相同的拒绝,重复失败守卫和循环熔断器均不触发。
    2. 什么原因导致的:src/stream.ts 的两个策略门分支在返回 REFUSED 时未调用 recordCompressFailure(重复失败账本)和 noteCompressLoopFailure(循环熔断器),而其余所有拒绝路径(no-visible-context、truncated-upstream、parse-failure、stub-resubmission、kernel-error、commit-error)均有调用。
    3. 影响范围与严重程度:所有启用策略门的会话。p2——存在配置绕行(关掉门即可),无数据丢失,折叠本身正常。实际事故:9 次逐字拒绝 / 125 秒,用户手动终止后卸载了 pi 插件。若按「用户因此卸载」读为可用性缺陷可升 p1,由 owner 定。
    4. 怎么修复的:PR [PR] fix(pi): charge policy-gate refusals to the compress failure ledger #6753 在两个策略门分支中加入 recordCompressFailure + noteCompressLoopFailure 调用,将 ${guard}${loopGuard} 嵌入回执文本;另加 repeat-collapse(第 2 次起简化为一行)和空推荐集终止措辞(避免死胡同建议)。
    5. 是否有回归问题:改动仅在两个策略门分支内,不影响其他拒绝路径。preflight(loopTracking:false)不受影响(gate 为 undefined,不进门)。现有 22 个门测试 + PR 新增 8 个测试覆盖。
    6. 是否破坏缓存:不涉及。
    7. 是否改了设计方向:不涉及。
    8. 是否引入了新的配置:不涉及。

    收工判定:修复已由 PR #6753 完整覆盖,CI 运行中(30 checks,0 failed,7 pending)。本会话独立验证确认修复方向正确,无并行 PR。等待 CI 结果 + owner 审核。

  3. ranxianglei commented on Nov 14, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

    收到 triage。补充两点:

    1. PR [PR] fix(pi): charge policy-gate refusals to the compress failure ledger #6753 已覆盖 scope 门修复——两个策略门(requireNudge / requireRecommendation)的 REFUSED 回执现在均计入 recordCompressFailure + noteCompressLoopFailure,重复失败守卫第 2 次触发、熔断器第 3 次触发,回执不再逐字相同。CI 运行中。

    2. The requireNudge plugin mode passes through for the current round, which is inconsistent with the documented 20-round cr | requireNudge 插件模式按本轮放行,与文档 20 轮信用窗口不符,导致模型被拒后反复重试 #6520 关联确认——The requireNudge plugin mode passes through for the current round, which is inconsistent with the documented 20-round cr | requireNudge 插件模式按本轮放行,与文档 20 轮信用窗口不符,导致模型被拒后反复重试 #6520 的「20 轮窗口下被拒后反复重试的病理会消失」结论确实只对 timing 门(no-visible-context)成立,因为那条路径已有 forcedCause 传入 noteCompressLoopFailure。本 issue 补上的 scope 门(requireNudge / requireRecommendation)此前完全没有账本调用,所以 The requireNudge plugin mode passes through for the current round, which is inconsistent with the documented 20-round cr | requireNudge 插件模式按本轮放行,与文档 20 轮信用窗口不符,导致模型被拒后反复重试 #6520 的结论不覆盖这两条分支。PR [PR] fix(pi): charge policy-gate refusals to the compress failure ledger #6753 修复后,scope 门的 REFUSED 回执也进入同一账本/熔断机制,The requireNudge plugin mode passes through for the current round, which is inconsistent with the documented 20-round cr | requireNudge 插件模式按本轮放行,与文档 20 轮信用窗口不符,导致模型被拒后反复重试 #6520 的收尾结论即可扩展到全部拒绝路径。

    p2/p1 定级由 owner 拍板。

  4. added 3 commits that reference this issue on Nov 15, 2026
    2c4ea46
    017ad42
    97c4a1e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions