Skip to content

[PR] fix(pi): charge policy-gate refusals to the compress failure ledger - #6753

Merged
ranxianglei merged 2 commits into
ranxianglei:masterfrom
sx4im:fix-6728-policy-gate-ledger
Nov 15, 2026
Merged

ranxianglei merged 2 commits into
ranxianglei:masterfrom
sx4im:fix-6728-policy-gate-ledger

Conversation

@sx4im

@sx4im sx4im commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

What broke

The two compress.requireNudge / compress.requireRecommendation policy gates in applyRanges returned their REFUSED receipt before any ledger call, unlike every other reject path. A model re-submitting a range bili will never fold got byte-identical receipts forever and the circuit breaker never armed — 9 consecutive verbatim refusals in 125 s in the reported pi session, ~176K uncached input burned, ended only by the human typing "stop calling compress".

What changed

  • Both gate branches now charge the failure ledger (recordCompressFailure + noteCompressLoopFailure), so the breaker arms by the 3rd consecutive refusal and the receipt escalates to the stop wording.
  • Repeat gate refusals collapse to a one-liner from the 2nd identical call (same shape as the parse-failure collapse).
  • When no compressible ranges remain at all (no offer and no live ranges), the scope-gate receipt uses terminal wording ("already at its minimum; continue the task without compressing") instead of pointing at acp_status, which is a dead end in that state.
  • Preflight lane untouched: it rides loopTracking:false and never reaches the gates, so bili’s own overflow backstop is unaffected.

How verified

  • New tests/issue6728-policy-gate-ledger.test.ts: 8/8 green (red before the fix, green after), covering breaker arming on both gates, disarm on success, repeat-collapse, terminal wording + its negative direction, and the preflight exemption.
  • Neighbors green: issue5683 gate suite (22), ledger/loop/breaker suites and other compress suites (70 + 46 + 19 tests).
  • Full local typecheck could not finish in this sandbox (tsc OOM-killed at the 6 GB limit; a capped run is still going) — CI is the gate.
  • No kernel/ change, no config-surface change.

Fixes #6728

Policy-gate REFUSED receipts (compress.requireNudge /
compress.requireRecommendation) returned before any ledger call, so a
model re-submitting a range bili will never fold got byte-identical
receipts forever and the circuit breaker never armed. Charge both gate
branches like every other reject path (recordCompressFailure +
noteCompressLoopFailure), collapse repeat gate refusals to a one-liner
from the 2nd identical call, and use terminal wording when no
compressible ranges remain at all instead of pointing at acp_status.

Fixes ranxianglei#6728
…cy-gate branches

Review nit from ranxianglei#6753: in both gate branches the repeatGuard value was
always empty at its only use site — the repeat-collapse (occurrences >= 2,
trackLoop is true whenever the gate is defined) returns before the full
receipt could render it, and the gate branches are unreachable from the
untracked lane where the parse path's guard does render. Keep the ledger
charge (the point of the fix); drop the dead variable and the never-rendered
custom advice string. Behavior byte-identical; 8/8 issue6728 suite + 48
neighbor tests green, typecheck clean.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Review of #6753 (fixes #6728) — verified independently, one small cleanup pushed to the branch, verdict: mergeable.

查重 (dedup): 不重复 — #6753 is the only open PR targeting #6728. Related open issue #6520 (requireNudge 1-round vs 20-round credit semantics) is the same gate family but a different mechanism — not the ledger-charging defect fixed here. No parallel mirror [PR] row for this thread.

What I verified (evidence, not trust):

  • Root cause confirmed on master: both gate branches in applyRanges (src/stream.ts:1069, :1220) return their REFUSED receipt before any ledger call, while all six other reject paths (parse failure, lost-in-transit, no-visible-context, stub resubmission, kernel error, catch) charge recordCompressFailure + noteCompressLoopFailure. So neither the spec ring (出现持续压缩失败,无法自动恢复 #847) nor the session streak (dsh内部问题 出现这个错误后,重启dsh可以发消息 但陷入无限压缩失败 #2146, threshold 3) ever advanced on gate refusals — byte-identical receipts forever, breaker never arms. Matches the reported incident (9 verbatim refusals in 125 s, ~176K uncached input).
  • Red→green: tests/issue6728-policy-gate-ledger.test.ts is 6/8 RED on master, 8/8 GREEN on the PR head (the 2 that pass on master are the negative-direction tests — non-empty set keeps the acp_status advice, preflight lane exempt — which is correct).
  • Typecheck on the PR head: clean (the author's sandbox OOM-killed tsc at 6 GB; it passes here).
  • Neighbors: 48/48 green (issue5683 gate suite, compress-refused-ledger-align, issue2146 breaker, issue4812 armed receipt, issue2432 breaker awareness). loop-compress.test.ts shows 4 failures that are byte-identical on master and PR head — pre-existing/environmental, not a regression.
  • CI (read live from the mirror cache): 0 failures; kernel-guard / config-surface-guard / lane-guard / pi-subagents-guard / architecture-docs / docs-sync / plan all green; 7 guard lanes still queued. Diff = src/stream.ts +59/−2 plus the new test file — no kernel/ change, no config-surface change.
  • Preflight exemption is structural, not incidental: gate = trackLoop ? unpromptedGateOf(...) : undefined (src/stream.ts:1068) — both gates read gate, so the loopTracking:false overflow backstop never reaches them or the new ledger calls.
  • Disarm path: the success path clears both ledgers (src/stream.ts:1514-1515), so gate refusals now behave like every other failure — 3 consecutive → armed, 1 success → disarmed (test 3 pins this).

Behavior changes (old → new, all intended):

  1. 2nd+ identical gate refusal: full lecture re-broadcast byte-identically → one-liner "REFUSED again … do not re-send this call verbatim" (same collapse shape as the parse-failure path).
  2. 3rd+ consecutive gate refusal: no breaker paragraph ever → the COMPRESS CIRCUIT BREAKER stop paragraph is appended.
  3. Scope-gate refusal with an EMPTY recommendation set (no offer, no live ranges): "Call acp_status … and stay within them" (a dead end — acp_status shows nothing) → terminal wording "No compressible ranges remain — the context is already at its minimum; continue the task without compressing." Non-empty set keeps the old advice (tested, negative direction).
  4. The FIRST refusal of each gate is byte-identical to master.

Small fix pushed to the PR branch (independently labeled commit 412bb635d6): both gate branches captured repeatGuard from recordCompressFailure, but its non-empty value was unreachable — the repeat-collapse (occurrences ≥ 2) returns before the full receipt could render it, and the gate branches are unreachable from the untracked lane where the parse path's guard does render. The nudge gate also passed a custom advice string that could never be shown. Dropped the dead variable/interpolation and the dead advice string; the ledger charge (the point of the fix) is untouched. Behavior byte-identical; re-verified typecheck clean + 8/8 + 48/48 green. CI will re-run on the new head.

八问:

  1. 是什么问题: 两个策略门(compress.requireNudge / compress.requireRecommendation)的 REFUSED 回执不计入失败账本——模型反复提交 bili 永不折叠的范围时,永远收到逐字相同的回执,熔断器永不启动(报告案例:125 秒内 9 次逐字重复拒绝,烧掉 ~176K 未缓存输入,直到人工输入 "stop calling compress" 才结束)。
  2. 什么原因导致的: applyRanges 里两个门分支在任何账本调用之前就直接 return——而其他六条拒绝路径(parse 失败、传输截断、no-visible-context、stub 重提、kernel 错误、catch)都会计 recordCompressFailure + noteCompressLoopFailure。于是 spec 级重复环(出现持续压缩失败,无法自动恢复 #847)与会话级连续失败计数(dsh内部问题 出现这个错误后,重启dsh可以发消息 但陷入无限压缩失败 #2146,阈值 3)在门拒绝上永远不推进。
  3. 影响范围与严重程度: 仅影响开启了这两个 opt-in 策略门、且模型重复提交会被拒范围的路由;后果是无上限的上下文烧钱与会话卡死,需人工干预才能退出——p2(能用但有明显问题,需绕行)。
  4. 怎么修复的: 两个门分支与其他拒绝路径一样计双账本(spec 键重复环 + 会话连续失败计数)→ 第 3 次连续拒绝熔断启动、回执升级为停止措辞;第 2 次相同调用起回执折叠为一行(与 parse 失败折叠同形);推荐集为空(无 offer 且无 live 范围)时 scope 门回执改用终局措辞,不再指向 acp_status 死胡同。preflight 车道经 trackLoop 结构性不可达,溢出兜底不受影响。
  5. 是否有回归问题: 逐项审过——首次拒绝回执与 master 逐字一致(已核实);非空推荐集保留 acp_status 建议(负向测试钉住);preflight 车道不变(测试钉住);成功路径清账本行为不变(src/stream.ts:1514-1515,测试 3 钉住);门的启用条件、nudge 信用窗口、kernel/wire 形状均未动。loop-compress.test.ts 的 4 个本地失败在 master 上同样存在,非本 PR 引入。
  6. 是否破坏缓存: 不破坏。回执是工具结果,不进前缀缓存;账本状态存在 session.metadata(既有持久化字段,其他拒绝路径早已在用);缓存账本路径未触碰。
  7. 是否改了设计方向: 没有——把门分支对齐到既有账本架构(出现持续压缩失败,无法自动恢复 #847 + dsh内部问题 出现这个错误后,重启dsh可以发消息 但陷入无限压缩失败 #2146),没有新机制、新边界。
  8. 是否引入了新的配置: 无。

Verdict: mergeable — single-module scoped fix, regression test reproduces the bug (red→green verified locally), clean diff, references #6728, no kernel/config change; the only wire-visible delta is the model-facing receipt text disclosed above. CI is the final gate (0 failures so far; guard lanes still running on the new head after the cleanup commit).

@ranxianglei
ranxianglei merged commit a2cf2f0 into ranxianglei:master Nov 15, 2026
50 checks passed
@ranxianglei

Copy link
Copy Markdown
Owner

Closes pair #6728 was auto-closed by the batch merge.

Superseded by #6765 (merged to master as a2cf2f0).

Your commit 412bb63 is in master verbatim — same content, same authorship, only the object ID changed (the batch used a real git merge, no rebase or cherry-pick rewrite). Merged under a different branch name, so GitHub does not flip this PR by itself.

Thanks for the fix — it is live in master from a2cf2f0 onward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants