Skip to content

[PR] fix: only a substantial fold disarms the compress-loop breaker (root-cause: compress-gate — #7197 + #7300) - #7326

Open
ranxianglei wants to merge 2 commits into
masterfrom
2026-11-19_rcagg-compress-gate
Open

ranxianglei wants to merge 2 commits into
masterfrom
2026-11-19_rcagg-compress-gate

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

⚠️ MODEL-FACING TEXT CHANGE: the breaker disarm wording now says "one substantial fold/success (a trivial one that saves almost nothing does not count)" instead of "one successful fold/success". The armed receipt, the substrate-destruction paragraph, and the acp_status armed note all moved from "any success disarms" to "a success that saves ≥500 tokens disarms". This is a prompt-surface change the model reads on every armed-breaker receipt.

Root cause (compress-gate)

Two open issues share one root cause — the compress circuit breaker (compressFailStreak) does not arm when it should:

Fix

  1. [Bug][dsh] Circuit breaker armed by compress.requireRecommendation range misses: receipt forbids the only recovery the code still allows | 范围猜错三次即武装熔断,而熔断文案禁止了代码仍允许的自救动作 #7197 (cherry-picked from PR [PR] fix: scope-gate (requireRecommendation) refusals no longer arm the compress breaker (#7197) #7209, authorship preserved with -x): the scope gate now charges only the spec-repeat ledger (recordCompressFailure), never the session breaker (noteCompressLoopFailure). The scope gate is a range-correctness gate, not a fold-feasibility signal; its recovery is always available, so arming the breaker would forbid it.

  2. billion-context 0.1.216 — compress no-op: symptoms, root cause, and proposed patch | billion-context 0.1.216 — compress 空转:现象、根因、可提的补丁 #7300: a success discharges the streak only when it is a SUBSTANTIAL fold. r.tokensCompressed is the TOTAL folded mass (the kernel sums the folded message tokens and never subtracts the new summary), so a barely-over-minimum range reads ~1250 even when the NET saving is 86–290 tokens. The streak now discharges only when the NET saving (folded mass minus the new summary mass of the block(s) this fold created/updated) is ≥ COMPRESS_LOOP_DISCHARGE_MIN_TOKENS (500). A trivial fold is the model still probing, not "compression is working".

Tests

  • New: tests/issue7300-compress-loop-trivial.test.ts — pins both directions (trivial success does NOT discharge; substantial success DOES; trivial success alone is a no-op).
  • Updated the three existing assertions that quoted the old disarm wording (issue2432-breaker-awareness, issue4812-armed-breaker-short-receipt).
  • All 37 tests in the breaker/gate suite pass; typecheck clean.

Supersedes PR #7209

This PR cherry-picks PR #7209's exact commit (the #7197 fix) and adds the #7300 fix. It is the single root-cause PR for the compress-gate batch. PR #7209 (the single-issue #7197 PR) is now redundant and can be closed once this merges.

Fixes #7197
Fixes #7300

ci-check added 2 commits November 19, 2026 22:28
…mpress breaker (#7197)

⚠️ MODEL-FACING TEXT CHANGE: scope-gate refusal receipts no longer carry
the 'COMPRESS CIRCUIT BREAKER: ARMED — STOP calling compress now: do not
try other ranges, do not re-issue any previous range, and do not poll
acp_status.' paragraph. The core refusal wording is unchanged. The model
now sees the refusal + advice ('Call acp_status ... stay within them')
and follows it with an in-recommendation retry — the recovery the removed
paragraph forbade. No number/ref/position the model propagates moves.

The out-of-recommendation scope gate is a range-correctness gate
('your span was wrong'), not a fold-feasibility signal. Its recovery
(acp_status -> an in-recommendation retry) is always available and
succeeds if followed, so arming the session-level breaker (which orders
'do not try other ranges ... do not poll acp_status') forbade the only
recovery the code still allowed: an obedient model lost compression for
the whole session while a disobedient one recovered on the next call.

Remove noteCompressLoopFailure from the scope-gate branch; keep
recordCompressFailure so the #6728 repeat-collapse still fires on
identical re-submission. The nudge gate keeps the breaker charge (its
recovery is 'wait for a nudge' - no self-recovery).

Update tests/issue6728-policy-gate-ledger.test.ts: the requireRecommendation
test now asserts the breaker stays disarmed and the repeat-collapse still
fires.

(cherry picked from commit 97c4a1e)
…stantial fold/success (a trivial one that saves almost nothing does not count)" instead of "one successful fold/success" — the armed receipt, the substrate-destruction paragraph, and the acp_status armed note all moved from "any success disarms" to "a success that saves ≥500 tokens disarms".

fix: only a substantial fold discharges the compress-loop breaker (#7300)

The breaker streak (compressFailStreak) reset on ANY successful compress, so
the incident's "fail×N → trivial-success×1 → fail×N" loop (bili 0.1.216:
398 compress calls, 289 "too small" fails, 92 trivial successes netting
only 86–290 tokens) never armed the 3-strike breaker and the model burned
tokens probing forever.

r.tokensCompressed is the TOTAL folded mass (the kernel sums the folded
message tokens and never subtracts the new summary), so a barely-over-minimum
range reads ~1250 even when the NET saving is 86–290 tokens. Discharge the
streak only when the NET saving (folded mass minus the new summary mass of
the block(s) this fold created/updated) is ≥ COMPRESS_LOOP_DISCHARGE_MIN_TOKENS
(500): a trivial fold is the model still probing, not "compression is
working".

Tests: tests/issue7300-compress-loop-trivial.test.ts pins both directions
(trivial success does NOT discharge; substantial success DOES). Updated the
three existing assertions that quoted the old disarm wording.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-19_rcagg-compress-gate (da7bda3)

Latest build — install this exact version

npm install -g billion-context@0.0.11004-pr.7326.22e3f77

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
da7bda3 billion-context@0.0.11004-pr.7326.22e3f77 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr7326.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: only a substantial fold disarms the compress-loop breaker (root-cause: compress-gate — #7197 + #7300) [PR] fix: only a substantial fold disarms the compress-loop breaker (root-cause: compress-gate — #7197 + #7300) Nov 19, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Dup check: not a duplicate — related to #7209 (the single-issue #7197 PR): this PR cherry-picks #7209's exact commit (verified: same patch, -x marker present, authorship preserved) and supersedes it. #7209 is still open; per the PR body it is redundant once this merges — I cannot close it (agent close policy), so that is yours to do after merge.

Live state (verified just now): PR open, mergeable, blocked (awaiting review); CI on head da7bda3 fully green — all 11 test shards (ubuntu 22/24 ×3, windows 22 ×5) plus every guard lane (kernel-guard, lane-guard, static-gates, docs-sync, …) succeeded; the 35 cancelled runs belong to the superseded earlier run. Labels bug / p2 / scope/kernel / root-cause meet the bar.

What I verified independently:

  • Pulled the branch and read the full diff (6 files, +209/−32, all on-topic).
  • Confirmed the kernel claim: r.tokensCompressed is the TOTAL folded mass — kernel/src/compress.ts:863 accumulates outcome.tokens, which sums countMessageTokens over folded messages (plus consumed-block summary mass) and never subtracts the new summary. So the net-saving computation (folded mass − new summary mass of the blocks this fold created/updated) is the correct discharge measure.
  • Confirmed the single clearCompressLoopStreak call site sits on the committed-success path (after the coverage-regression and 手动 compress 仍接受零/负净收益折叠,先改写缓存再提示上下文增长 #2748 net-benefit gates), so the discharge only ever runs on a real fold; beforeIds/beforeSummaries are in scope and defaultCountTokens is imported.
  • Confirmed the nudge gate (requireNudge) keeps its breaker charge while the scope gate (requireRecommendation) no longer charges it — exactly as the PR states, and the [Bug][pi] Policy-gate REFUSED receipts (compress.requireNudge / requireRecommendation) charge no failure ledger — endless byte-identical refusals, breaker never arms | 策略门 REFUSED 回执不计入失败账本:逐字重复拒绝、熔断永不启动 #6728 repeat-collapse ("again" one-liner) still fires on identical re-submission.
  • Ran the four PR test files (25 tests) plus the six other breaker-related test files (42 tests) locally: 67/67 pass; npm run typecheck clean.
  • Model-facing text consumption chain: the new wording adds no number/ref/position the model could propagate (no phantom-anchor class); all three armed surfaces (acp_status note, substrate-destruction paragraph, armed refusal receipt) moved consistently to "substantial" wording, and loopNoisePauseParagraph (which states no disarm condition) is untouched — no contradictory receipts.

Behavior changes (disclosed per policy, old → new + why):

  1. Any successful compress reset the breaker streak → only a fold with NET saving ≥ 500 tokens does. Why: a trivial fold (86–290 tok net in the billion-context 0.1.216 — compress no-op: symptoms, root cause, and proposed patch | billion-context 0.1.216 — compress 空转:现象、根因、可提的补丁 #7300 incident) is the model still probing; resetting on it is what kept the 3-strike breaker from ever arming.
  2. Scope-gate (requireRecommendation) refusals charged the session breaker → they now charge only the spec-repeat ledger. Why: that gate's recovery (acp_status + in-recommendation retry) is always available, and the armed wording forbids exactly it.
  3. Model-facing disarm wording: "one successful fold/success" → "one substantial fold/success (a trivial one that saves almost nothing does not count)" — flagged at the top of the PR body.

八问(中文,供审核):

  1. 是什么问题:压缩断路器(连续 3 次失败武装)有两个缺陷——① scope gate(requireRecommendation)的拒收会计入断路器,武装后的措辞却禁止了代码唯一允许的恢复路径(acp_status + 在推荐范围内重试);② 失败连击在"任何一次成功压缩"后清零,事故循环"失败×N → 微小成功×1 → 失败×N"(398 次调用、92 次净省仅 86–290 token 的微小成功)让断路器永远无法武装,模型无限烧 token 试探。
  2. 什么原因导致的:同一根因——断路器的武装/解除决策绑错了信号:scope gate 是范围正确性门(其拒收不是"折叠不可行"的信号),而"成功"没有区分实质折叠与微小试探(r.tokensCompressed 是总折叠质量,kernel 从不减去新 summary,勉强过线的范围读起来 ~1250 而净省只有 86–290)。
  3. 影响范围与严重程度:① 影响开了 compress.requireRecommendation 的会话(dsh 车道,[Bug][dsh] Circuit breaker armed by compress.requireRecommendation range misses: receipt forbids the only recovery the code still allows | 范围猜错三次即武装熔断,而熔断文案禁止了代码仍允许的自救动作 #7197);② 影响任何落入微小试探循环的会话(billion-context 0.1.216 — compress no-op: symptoms, root cause, and proposed patch | billion-context 0.1.216 — compress 空转:现象、根因、可提的补丁 #7300)。严重度 p2——能用但明显有问题:模型在唯一恢复路径被禁止的情况下失去整个会话的压缩能力(直到 10 分钟衰减),或断路器永不武装、token 持续燃烧。非数据丢失/不可用类。
  4. 怎么修复的:在决策点修,不在回执层打补丁——① scope gate 路径移除 session 断路器计费,只保留 spec-repeat 账本([Bug][pi] Policy-gate REFUSED receipts (compress.requireNudge / requireRecommendation) charge no failure ledger — endless byte-identical refusals, breaker never arms | 策略门 REFUSED 回执不计入失败账本:逐字重复拒绝、熔断永不启动 #6728 重复折叠回执不受影响);nudge gate 保留计费(其恢复是"等 nudge",模型无法自救)。② 解除条件改为"净省 ≥ 500 token"(净省 = 总折叠质量 − 本次折叠创建/更新的块的新 summary 质量);微小折叠视为试探,不清连击。500 为硬编码常量(与既有 COMPRESS_LOOP_THRESHOLD 同一纪律,未新增配置面)。
  5. 是否有回归问题:逐项审过触碰路径的既有行为——拒收回执核心措辞不变;spec-repeat 折叠("again" 一行回执)第 3 次相同调用仍触发;nudge gate / parse-failure / no-visible-context / truncated-upstream 各路径的断路器计费不变;成功路径的提交、ledger-align、观测不变;10 分钟衰减解除不变(无永久锁死可能);三处 model-facing 武装措辞一致更新,loopNoisePauseParagraph(不陈述解除条件)未动,无矛盾回执。本地 67 个断路器相关测试全过(PR 的 4 个文件 25 个 + 另跑的 6 个既有文件 42 个),typecheck 干净,CI 全绿。
  6. 是否破坏缓存:否。不触碰前缀缓存/重试/增量游标/去重键路径;netSaved 是提交后的只读旁路计算。
  7. 是否改了设计方向:否。架构/边界/数据流不变;kernel/ 零改动(Kernel Boundary 完好)。
  8. 是否引入了新的配置:否。COMPRESS_LOOP_DISCHARGE_MIN_TOKENS = 500 是硬编码常量,同 COMPRESS_LOOP_THRESHOLD = 3 的纪律。

判定:可合。 合并后请关闭被取代的 #7209(我按政策不能关)。

This branch has not been deployed

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