Skip to content

[PR] fix: refuse coverage-regressing folds before commit (#3322) - #3353

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-16_issue3322-coverage-backstop
Oct 20, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-16_issue3322-coverage-backstop

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Refs #3322

What

A committed fold must never leave a previously-covered message without ANY covering block. On full-resend hosts (compressMessages = raw history, #2627) the kernel's turn-integrity gate judged splits against the fold's own set instead of post-fold coverage: ids carried by non-consumed sibling blocks were withdrawn from the new block while their source blocks deactivated — they lost ALL coverage. Production shape (#3322): one block-range batch stripped ~305 previously-covered ids, doubled the processed live view (253→519), blew the local estimate past the model window (1.65M vs 750K) and bricked the session behind permanent preflight fail-fasts while upstream still had headroom (566K billed).

This PR adds a host-side backstop in applyRanges (shared by relay and plugin lanes): measure active-block coverage before vs after on the clone returned by applyCompression; if any previously-covered id loses every covering block, refuse the fold BEFORE committing — state untouched, prefix cache untouched, receipt tells the model why and how to retry. Healthy folds never trip it: fresh folds add coverage, refolds preserve it, integrity withdrawals only touch direct ids of the folded range.

Behavior change (disclosed)

Folds that used to commit while regressing coverage (then brick the session behind permanent preflight rejections) are now refused: outcome refused, reason gate:coverage-regression. Refusal happens strictly before the state commit — accepted folds, receipts, logs and the #2748 net-shrink gate are untouched. No config surface changes.

Scope note

The root-cause fix lives in the kernel (the judgment input inside projectUnit, #3236 shared-judgment structure) and ships separately under owner approval with a kernel-change declaration. This host gate pins the commit contract regardless of producer and also catches future kernel regressions of the same class.

Tests

A committed fold must never leave a previously-covered message without ANY covering block. On full-resend hosts the kernel's turn-integrity gate judged splits against the fold's own set instead of post-fold coverage, so ids carried by non-consumed sibling blocks were withdrawn from the new block while their source blocks got deactivated - they lost ALL coverage, the processed view doubled (253->519), the local estimate blew past the model window and preflight fail-fasted forever while upstream still had headroom (566K/750K).

Add a pre-commit backstop in applyRanges (both relay and plugin lanes share it): measure active-block coverage before vs after on the clone returned by applyCompression; if any previously-covered id loses every covering block, refuse the fold BEFORE committing - state untouched, prefix cache untouched, receipt tells the model why and how to retry. Healthy folds never trip it: fresh folds add coverage, refolds preserve it, integrity withdrawals only touch direct ids of the folded range.

Behavior change (disclosed): folds that used to commit while regressing coverage (and then brick the session behind permanent preflight rejections) are now refused with outcome 'refused' / reason 'gate:coverage-regression'. Nothing else changes: the refusal happens strictly before the state commit, so accepted folds, receipts, logs and the #2748 net-shrink gate are untouched.

Refs #3322 (root-cause kernel fix follows separately under owner approval).
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-16_issue3322-coverage-backstop (f14abb2)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3956-pr.3353.620dd5b

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

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复——#3353 是 #3322 在途的唯一修复 PR(floor 9 已纠正此前误链的 #3325);无其他在途 PR 触碰 applyRanges。

独立审核(非复读 issue 结论)

方向(①):#3322 的根因已在前序会话用最小 fixture 复现钉死(kernel turn-integrity 判定输入错误)。本 PR 定位是「宿主侧提交契约护栏」而非根因修复——这个切分是对的:护栏与 producer 无关、能兜住未来同类 kernel 回归,且完全无决策依赖,按「无决策依赖的部分先修」应当先行;kernel 根治走决策 A 单独声明。方向成立。

代码(③):逐行读过 diff(src/stream.ts +35、新测试 +120,别无其他)。关键事实我已独立核验:

回归清点(②)——diff 触碰路径承担的既有行为逐项过:

既有行为 结论
healthy compress fold 提交路径 保持(门直通,后续代码逐字节未动)
parse 失败 / no-visible-context / stub-resubmission(#2749)门 保持(都在 kernel 调用前,未动)
#2748 no-net-shrink 门 保持,顺序不变(仍在新门之后、提交前)
refused 结果契约 有意扩展:+1 个 reason 字符串,全部 6 类调用点原本就泛化处理 refused
失败计数/循环熔断 保持(新 key 用法同 #2748;不武装 loop breaker)
prefix cache / state 引用 保持(拒绝严格先于提交;测试 1 断言 session.state === 折叠前引用)
输出格式/时序/默认值/阈值 不涉及

未发现无意回归。

测试有效性(④):双向钉住,断言有牙。测试 1 若门被移后/弱化 → state 引用变化或 fold 被提交,必红;测试 2 若门过紧(误伤嵌套消费)→ applied 变 refused,必红。monkeypatch core.applyCompression 模拟事故形态是 host 护栏的正确测法(契约与 producer 解耦);kernel 真实病态路径由决策 A 的 kernel 修复自带测试钉住,边界披露清楚。

diff 整洁度(⑤/⑤b):单 commit,两文件,+155 行,每行都与目的相关;命名达意(lostCoverage/receipt 文案)、注释讲为什么(引用 #3322/#2748/#2146)、风格与邻域一致。干净。

本地验证(f14abb2,worktree 实测)

CI 现状(f14abb2)

40 个 check run:0 failure / 0 cancelled;全部静态门绿(static-gates/docs-sync/version-guard/kernel-guard/config-surface-guard/lane-guard/lock-sync/test-import-graph/unused-exports/docs-coverage/plan/gate);仅剩 2 个 test shard 在跑(windows-22#2、ubuntu-24#1),其余 test shard 已绿。base 新鲜(PR head 包含当前 master 745be9f,rebase 干净自动合并)。

结构化八问

  1. 是什么问题:full-resend 宿主上多 block 批量折叠时,一批已覆盖消息会丢掉全部覆盖块,processed view 翻倍、本地估算冲窗,会话坠入永久 preflight fail-fast([bug] Collapsing the "block range" compress actually doubled the live view size (253→519 msgs) → local estimate blew past the window → preflight permanently fail-fast (while the same payload would have passed upstream at 566K/750K) | [bug] 折叠「块范围」的 compr… #3322 生产事故形态)。
  2. 什么原因导致的:kernel 层——turn-integrity 用「本次 fold 自己的消息集」而非「fold 后的全局覆盖」判 split,跨非消费兄弟 block 的同轮消息被误判为被拆散,继承 id 被整体撤回而源块停用。本 PR 修的是宿主侧后果防线,根因在 kernel(决策 A)。
  3. 影响范围与严重程度:触发条件=full-resend 宿主(compressMessages=raw history,dsh plugin lane 等)+ 多 block-range 批量折叠 + 跨块同轮消息;严重度=会话完全死亡(永久 502、状态跨重启持久、无 admin 逃生口)。单块常规折叠不受影响。
  4. 怎么修复的:在唯一提交入口 applyRanges 内、commit 之前,对 applyCompression 返回的 clone 做前后 active-block 覆盖集合对比;任何先前被覆盖的 id 失去全部覆盖块 → 整体拒绝(outcome=refused,reason=gate:coverage-regression),state/prefix cache 不动,receipt 向模型解释原因并给重试建议(整轮边界/少选块/跳过)。
  5. 是否有回归问题:无。上表 7 项既有行为逐项核过:healthy 路径字节级不变,三个前置门不变,手动 compress 仍接受零/负净收益折叠,先改写缓存再提示上下文增长 #2748 门顺序不变,refused 契约仅加 reason 且所有调用点已泛化处理,失败计数纪律不变,prefix cache/state 引用在拒绝时不变(有测试钉死),日志盐化。
  6. 是否破坏缓存:否——拒绝严格先于提交,session.state 引用不变,prefix cache 完整(测试 1 显式断言引用相等)。
  7. 是否改了设计方向:无转向。新增一条宿主侧提交契约不变量(committed fold 不得减少覆盖),与 kernel 根治正交互补;顺带把 preflight 自折也纳入保护(其调用点已正确处理 refused)。
  8. 是否引入了新的配置:无(config-surface-guard 绿,零新 env/key)。

行为变更披露(旧→新)

备注

判定:可合并——无拦截项;待剩余 2 个 CI shard 转绿即可(当前 0 失败)。

ranxianglei added a commit that referenced this pull request Oct 20, 2026
[PR] Batch-B integration: fold budget/eligibility — merge #3353 #3943 #3952 #3867 #2660 #3677 (#3916)
@ranxianglei
ranxianglei merged commit c3c68c6 into master Oct 20, 2026
40 checks passed
@ranxianglei ranxianglei changed the title fix: refuse coverage-regressing folds before commit (#3322) [PR] fix: refuse coverage-regressing folds before commit (#3322) Oct 20, 2026
ranxianglei pushed a commit that referenced this pull request Oct 27, 2026
kernel-change: merging existing blocks retracted their own coverage. The
turn-integrity gate judged the fold over this unit's ids only and withdrew ids
carried solely by the consumed blocks; those blocks deactivate on apply and the
new block does not inherit them, so the folded messages lose all coverage and
the host pre-commit guard refuses the fold (gate:coverage-regression), causing
repeated rejections of legitimate merges.

Fix lives in projectUnit's integrity step, scoped to merges (consumedBlockIds >
0); fresh folds keep the legacy behavior verbatim:
- judge post-fold coverage as this unit's ids PLUS every still-active sibling
  block's coverage, so a tool half already covered by an unconsumed sibling reads
  as folded rather than as a spurious visible half (#3322 facet);
- unfold only ids whose coverage does not depend on a consumed block, re-checking
  to a fixed point; if consistency would force unfolding such an id, fail honestly
  (split fatal) instead of emitting a doomed regressive candidate.

Host coverage guard (src/stream.ts, #3353/#3322) left intact as defense-in-depth.
Regression tests: kernel/tests/issue4484-merge-coverage.test.ts (interior
hard-protected tool; tail cut mid-tool-group; clean-merge control). Bumps
acp-kernel 0.0.161 -> 0.0.162.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant