Skip to content

[PR] fix: two adjacent ranges in one compress batch both claimed the shared seam tool pair — first-come-first-served - #7428

Merged
ranxianglei merged 4 commits into
masterfrom
2026-11-21_fix-batch-seam-double-claim
Nov 21, 2026
Merged

ranxianglei merged 4 commits into
masterfrom
2026-11-21_fix-batch-seam-double-claim

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

⚠️ MODEL-FACING TEXT CHANGE (top-priority, per review rules)

The #4521 no-op warning ("folded nothing … do not resend this range") gains a SECOND, more accurate wording for the case where every resolvable message of the range is already covered by active block(s) — the previous "all of its content is protected or filtered" wording is kept VERBATIM for its original class.

Scope of the new wording (corrected at review, 54f37fb): the covered wording fires in TWO cases: (a) the NEW case this fix turns into a no-op instead of a double-claim — a same-batch sibling claimed the seam tool pair; and (b) a PRE-EXISTING block straddling the range edge (a sub-range request whose anchor lies outside the covering block) — this case existed before the fix and previously received the inaccurate "protected or filtered" wording. The wording therefore states only what is true in both: "every message in it is already covered by active block(s) … reference them by block ID instead." The first draft's clause "including block(s) created earlier in this same batch" was FALSE in case (b) (no block was created in that batch) and was removed at review.

Regression inference (consumption chain):

  • What the model does with the text: it stops resending the range; if it wanted to rewrite/merge the covering blocks, it is told to reference them by block ID — consistent with the adjacent no-overlap livelock guard's existing guidance.
  • What it records for its next turn: the range is covered; target different ranges or block boundaries next.
  • Adversarial pass: the text carries NO numbers, refs, or counts the model could anchor and propagate (no phantom-value class). Worst misread — the model resends the same covered range anyway — lands on the same no-op again, which is livelock-safe by design (Compression conflict banner (bili v0.1.205, node v24.19.0, win32-x64) #4521).
  • Receipt-level test: the regression tests assert the no-op warning shape (/folded nothing/ + /do not resend this range/); test 3 additionally pins the covered wording for the pre-existing case and asserts the warning contains NO same-batch claim.

What is broken (plain words)

When the model asks to compress TWO adjacent ranges in one call (very common — the batch seam sits on a tool pair), BOTH ranges claimed the tool pair on their shared boundary. Result seen live (pi session 01a1f6ff on v0.1.216): two sibling blocks (b100/b101) directly owned the same two messages; a later fold then consumed one of them positionally although its ref range lay completely outside that block's range — the "nested compression" confusion reported in the web UI.

Root cause

The no-overlap contract (kernel/src/compress.ts file header: "no two active sibling blocks may claim the same message directly") was enforced on every path EXCEPT same-batch siblings: the coverage snapshot (collectCoverage) was frozen once, before the batch started (const at the apply loop), so each range's projection judged "already covered" without seeing what an earlier sibling in the SAME batch had just claimed. The overlap check also only compares block spans, and a just-applied block still carries its un-snapped projection span until the block is sealed — so even a check against just-applied siblings would not have caught it.

Fix

  • The apply loop now refreshes the coverage snapshot each iteration: first-come-first-served. The earlier range keeps the seam tool pair; the later range shrinks to its own new ids — or, if the seam was its only content, becomes the existing Compression conflict banner (bili v0.1.205, node v24.19.0, win32-x64) #4521 idempotent no-op (warning, not an error; the batch and its siblings survive).
  • The no-op warning distinguishes the "all covered by active block(s)" class from the original "protected or filtered" class (see model-facing note above).

No binary split of any range, no new config knob, no wire/protocol change, no storage format change. This restores the declared invariant on its last bypassing path — the sibling-claim decision was always "first-come-first-served" by design; the snapshot just went stale within one batch.

Reproduction & evidence

  • New regression test kernel/tests/regression-batch-seam-double-claim.test.ts: two adjacent batch ranges over a shared tool pair. RED before the fix with exactly the live shape: message c1 is directly claimed by BOTH block b1 and block b2. GREEN after (disjoint claims + clean no-op on the empty remainder). Test 3 (added at review): a pre-existing covering block (no same-batch block) gets the covered wording, and the warning is asserted to contain no same-batch claim.
  • Kernel suite: 1647/1647 pass (targeted, re-based head).
  • npm run typecheck clean.
  • tests/wire-contract*.test.ts 36/36 (golden pins untouched — behavior constants, nudge floor/cap, prompts, wire markers all unchanged).
  • Local full-suite runs in this sandbox show environmental failures (port-restricted firewalls → 15s watchdog timeouts in attach/model-resolve/title-push clusters); baseline comparison confirmed those failures are identical on pristine master. The authoritative full-suite verdict is the CI test lanes on this head.

kernel-change: mechanical-bug exemption (owner policy 2026-11-06) — a single-point state-refresh omission with a reproducing regression test (red before / green after); the human review tier still gates this merge.

Review (2026-11-21, head 54f37fb)

Fixes #7429

ework-agent added 2 commits November 21, 2026 10:59
do not resend this range") gains a second, more accurate wording for the
case where every resolvable message of a range is already covered by
active block(s) — the previous "all of its content is protected or
filtered" wording is kept VERBATIM for its original class; the new
wording only appears for the newly-impossible-to-misread covered case
(it names the covering class and points to block-ID refs).

kernel: refresh batch coverage snapshot per range (seam double-claim fix)

Two adjacent ranges in ONE compress batch both claimed the tool pair on
their shared seam: the coverage snapshot (collectCoverage) was frozen
before the batch, so each range's projection judged "already covered"
without seeing what an earlier sibling had just claimed. Result: two
active sibling blocks directly owning the same messages, overlapping
seq intervals, and a later fold consuming one of them positionally
although its ref range lay outside the newer block's range (pi session
01a1f6ff: b100/b101 shared two directMessageIds; b102 then consumed b101
across its ref range).

The no-overlapping-active-siblings invariant (file header) now holds on
the last path that bypassed it: the apply loop refreshes the snapshot
each iteration (first-come-first-served seam ownership); a range left
with nothing new becomes the #4521 idempotent no-op (warning, no error,
batch survives).

kernel-change: mechanical-bug exemption (owner policy 2026-11-06) — a
single-point state-refresh omission with a reproducing regression test
(kernel/tests/regression-batch-seam-double-claim.test.ts, red before /
green after; full kernel suite 1647/1647 green). The human review tier
still gates the merge.
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-21_fix-batch-seam-double-claim (54f37fb)

Latest build — install this exact version

npm install -g billion-context@0.0.11135-pr.7428.756aaa3

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
54f37fb billion-context@0.0.11135-pr.7428.756aaa3 build
0f4e18d billion-context@0.0.11134-pr.7428.b650df8 build
6d1f5c2 billion-context@0.0.11132-pr.7428.9752d4d build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: two adjacent ranges in one compress batch both claimed the shared seam tool pair — first-come-first-served [PR] fix: two adjacent ranges in one compress batch both claimed the shared seam tool pair — first-come-first-served Nov 21, 2026
ci-check added 2 commits November 21, 2026 11:19
The top commit bumped kernel/package.json to 0.0.201 but skipped lockfile
regen, leaving acp-kernel at 0.0.200 in both package-lock.json (root,
acp-kernel entry) and kernel/package-lock.json. The lock-sync CI job (#2704
drift guard) regenerates via 'npm install --package-lock-only' and fails on
any residual diff. This commit is the exact output of that regeneration
(idempotent fixed point): 3 version lines 0.0.200 -> 0.0.201, no registry
churn. Fixes the red lock-sync check on PR #7428.
…ame-batch involvement (false for pre-existing covering blocks)

Review finding (reproduced with a two-turn probe): the new allCovered
no-op wording fired for a PRE-EXISTING block covering a requested
sub-range (anchor outside the range, so the block is not nested in it)
— a case that existed before this fix and previously got the
'protected or filtered' wording. There the clause 'including block(s)
created earlier in this same batch' asserted same-batch involvement
that did not exist (no block was created in this batch).

Fix: drop the clause — the actionable guidance ('do not resend this
range; reference them by block ID instead') is identical in both
cases, so the clause carried no decision value, only the false claim.
The wording now states only what is true in every case reaching this
branch: every resolvable message is covered by an active block.

Added regression test 3: pre-existing covering block (no same-batch
block) gets the covered wording and the warning is asserted to NOT
contain a same-batch claim. kernel-change: mechanical-bug exemption
(provably-false guard text + reproducing test); human review tier
still gates this merge.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI fix run — PR #7428 (mirror #7430), head now 0f4e18dda41

Re-verified live state first: the only red check was lock-sync (everything else success/skipped; the test matrix was skipped because it's gated behind lock-sync).

Root cause: the PR's top commit 6d1f5c2a396 bumped kernel/package.json to 0.0.201 but skipped lockfile regeneration, leaving acp-kernel at 0.0.200 in both package-lock.json (root, the acp-kernel entry) and kernel/package-lock.json. The lock-sync job (#2704 drift guard) runs npm install --package-lock-only and fails on any residual diff — exactly the drift it guards.

Fix: regenerated both lockfiles with the exact command CI uses (npm install --package-lock-only --ignore-scripts --no-fund --no-audit). Diff = 3 version lines 0.0.200 → 0.0.201, no registry churn. Verified idempotent (re-run adds no further diff → the committed state is a fixed point CI will accept). Pushed as the final unmarked head 0f4e18dda41 (no [ework:ci-held] — this is the branch's one full CI pass).

Verified live: lock-sync is now success on head 0f4e18dda41. The test matrix (13 shards) is now in_progress — it was skipped before because it's gated behind lock-sync; my change is lockfile version metadata only and cannot affect test outcomes. Honest boundary: the mirror-cache snapshot was at 03:22:21 and did not refresh further during this run, so I could not confirm the test matrix's final verdict live — reporting last known state, not guessing.

七问

  1. 是什么问题:PR 的 lock-sync 检查红了,是本次 CI 唯一红项(其余全绿或 skipped)。
  2. 什么原因导致的:PR 顶部提交把 kernel/package.json bump 到 0.0.201 但漏了重新生成 lockfile,acp-kernel 在 root package-lock.json(acp-kernel 条目)和 kernel/package-lock.json 里都停在 0.0.200;lock-sync(package-lock.json version metadata lags package.json (bili 0.1.190 vs 0.1.191, kernel 0.0.112 vs 0.0.114) #2704 漂移守卫)跑 npm install --package-lock-only 后 git diff --exit-code,版本不一致即红——正是它要拦的漂移。
  3. 影响范围与严重程度:仅本 PR 的 CI 门禁(lock-sync 红 → 下游 test 矩阵被 skip 跑不了);无用户侧/线上影响,属 CI 机械性卡点,不改任何运行时行为。
  4. 怎么修复的:用 CI 同款命令重生成两份 lockfile,把 acp-kernel 版本对齐到 0.0.201;diff 仅 3 行版本号、无 registry 抖动;本地验证幂等(重跑无新增 diff,提交态即 CI 接受的不动点);作为最终无标记 head 推送(不带 [ework:ci-held],触发本分支唯一一次完整 CI)。
  5. 是否有回归问题:无。只动两份 lockfile 版本字段(元数据),不碰源码/配置/内核逻辑,不改运行时行为;kernel-guard 对 kernel/package-lock.json 有豁免(生成态非内核源码),不会因本次改动转红。
  6. 是否破坏缓存:不涉及。lockfile 版本字段不参与任何缓存/重试/去重键。
  7. 是否改了设计方向 / 引入新配置:不涉及。无新 env/config/默认值,无架构/边界/数据流转向。

结论:lock-sync 已修复并实测转绿;test 矩阵(完整 CI)已随之启动运行,本次改动为纯 lockfile 元数据、不影响测试结果。本 run 收工。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Duplicate screening: not a duplicate — searched open+closed issues/PRs by failure signature ("batch seam double-claim adjacent ranges", "01a1f6ff nested compression", "seam tool pair sibling blocks", "compress batch adjacent ranges claim"): no matches; no parallel [PR] on the same topic.

Review of PR #7428 complete. The core fix (refresh the coverage snapshot at the top of the apply loop → first-come-first-served) is correct and verified: the new regression test is RED on master with exactly the live shape (message c1 is directly claimed by BOTH block b1 and block b2) and GREEN on the PR head; 92 relevant kernel tests pass; typecheck clean. Three findings during review, all closed:

  1. New no-op wording contained a false clause (fixed in passing, 54f37fb) — "including block(s) created earlier in this same batch" is FALSE for the pre-existing-covering-block case, disproving the PR body's claim that the new wording "only appears in a case that could not happen before this fix". Reproduced with a two-turn probe (turn 1 folds m00001..m00004; turn 2 requests sub-range m00002..m00004 → no same-batch block exists, new wording still fired). Fix: clause removed (actionable guidance unchanged; no design decision needed) + test 3 added pinning the wording (asserts /already covered by active block/, doesNotMatch /same batch/). PR body's MODEL-FACING section corrected accordingly.
  2. CI lock-sync red (fixed by the author session, 0f4e18d) — the kernel 0.0.201 bump left the root package-lock.json "kernel" entry and kernel/package-lock.json at 0.0.200. CI Control Center: Centralized CI Failure Handling & Status Sync (Comment all CI issues here; do not open new issues) | CI 总控: CI 失败集中处理与状态同步(所有 CI 问题在此评论, 勿开新 issue) #4599 floor 1607: master green → the PR's own fault. The author session's 0f4e18d is byte-identical to my local fix (0-line diff verified); I dropped my duplicate commit and rebased onto it.
  3. Promised companion issue never filed (filed in passing, GitHub Compressing two adjacent ranges in one batch makes both sibling blocks claim the same boundary tool pair (live incident: pi session 01a1f6ff) #7429 / mirror [PR] feat(storage): index.db backup and corruption recovery commands bili storage backup / repair (#7156) | feat(storage): index.db 备份与损坏恢复命令 bili storage backup / repair(#7156) #7431) — the PR body promised "Companion issue ... to be filed separately"; a bare PR without an issue is not acceptable. Filed via the mirror API with the 来源 marker → PR [PR] fix: two adjacent ranges in one compress batch both claimed the shared seam tool pair — first-come-first-served #7428, labeled bug/p2/pi/scope/kernel; PR body now references it with "Fixes Compressing two adjacent ranges in one batch makes both sibling blocks claim the same boundary tool pair (live incident: pi session 01a1f6ff) #7429".

8问结论

  1. 是什么问题:模型一次 batch 压缩两个相邻 range 时,两个 sibling block 都声称了共享边界上的同一对 tool call(live incident pi session 01a1f6ff, v0.1.216:b100/b101 直接拥有同两条消息,后续 positional fold 消费了其中一个 → web UI「nested compression」困惑)。
  2. 什么原因导致的:coverage 快照(collectCoverage)在 batch 开始前冻结一次,batch 内每个 range 看不到同 batch 更早 sibling 刚声称的内容,no-overlap 契约在最后一处路径被绕过;batch overlap 检查只比较 pair-adjustment 前的 span(相邻 range 天然不相交),也抓不到。
  3. 影响范围与严重程度:p2 —— 会话可用,无数据丢失(消息仍被覆盖),无缓存泄露;代价是状态不一致 → 后续 fold 行为困惑。触发条件:batch 含两个相邻 range 且 seam 落在 tool pair 上(常见形状)。
  4. 怎么修复的:apply loop 顶部每轮刷新 coverage 快照(first-come-first-served)—— 早到的 range 保留 seam tool pair,晚到的缩到自己的新消息,或退化为 Compression conflict banner (bili v0.1.205, node v24.19.0, win32-x64) #4521 幂等 no-op(warning 非 error,batch 不丢)。无二分、无新配置、无 wire/协议/存储变更。
  5. 是否有回归问题:无。diff 触碰路径的既有行为逐项审过:Compression conflict banner (bili v0.1.205, node v24.19.0, win32-x64) #4521 no-op 语义(原「protected or filtered」措辞对原场景逐字保留)、batch overlap 检查(未动)、blockVisibleInRange 嵌套判定(未动)、wire-contract golden pins(36/36,行为常量/nudge/prompts/wire markers 均未变)。
  6. 是否破坏缓存:否 —— 未触碰缓存/重试/增量游标/去重键逻辑。
  7. 是否改了设计方向:否 —— 修复恢复的是已声明不变量(两个 active sibling block 不得直接声称同一条消息)在最后一处绕过路径上的执行;first-come-first-served 即原设计。
  8. 是否引入了新的配置:否。

MODEL-FACING TEXT CHANGE (top priority per review rules): the #4521 no-op warning gains a second, more accurate wording for the all-covered case (the old "protected or filtered" wording was inaccurate for it). The new wording carries no numbers/refs/counts the model could anchor (no phantom-value class); worst misread (resend the same range) lands on the same no-op — livelock-safe by design (#4521). The false "same batch" clause was removed at review (finding 1).

标签:PR #7428 已打 bug/p2/pi/scope/kernel(按 PR 自身 diff 判定:kernel batch-apply 缺陷、pi 车道显现、可用但状态不一致 → p2);mirror issue 7430 与 companion issue #7429(mirror #7431)同标。

CI: review 时唯一红项(lock-sync)已修(0f4e18d);新 head 54f37fb 的 30 项 check 运行中,目前 0 failed。

Verdict: fix correct, tests real (red-before/green-after, 3 cases), diff clean, all three review findings closed. It touches kernel/ → human-only review tier; I cannot merge — please review and merge yourself: #7428

@ranxianglei
ranxianglei merged commit ba2e819 into master Nov 21, 2026
92 of 132 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1245-master.ba2e819 (rolling master tag).

npm install -g billion-context@0.0.1245-master.ba2e819  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

ranxianglei pushed a commit that referenced this pull request Nov 21, 2026
Second master sync (a446a3c -> bf778d9, 101 commits). Conflicts were kernel version lines only (branch 0.0.200 vs master 0.0.201, the #7428 batch-seam fix bump); resolved to 0.0.202 because the merged tree carries this PR's kernel/src changes on top of master's kernel, which kernel-guard version discipline requires a bump for. compress.ts auto-merged: master's batch-seam coverage refresh and no-op wording preserved, PR's supersedesBlockId lineage wiring intact. Verified: root + kernel typecheck clean, kernel suite 1654/1654, host targeted suites 45/45 (5 skipped), lockfiles idempotent.
ranxianglei pushed a commit that referenced this pull request Nov 21, 2026
…lict at 0.0.202

Master advanced 122 commits past the PR base (batch-seam double-claim fix
#7428 -> kernel 0.0.201, storage backup/repair #7156/#7431, ingest-band
default-off #7426, pf-tail-ids cap #7381, OpenAI reasoning alias #7432,
dsh-mneme scan #7430, and more). Content hunks auto-merged (kernel/src/
compress.ts, all four storage-render goldens); the only conflicts were the
three kernel version lines, resolved at 0.0.202 = master's 0.0.201 + this
PR's kernel/src change, per the CI-enforced kernel version discipline.

Targeted local verification: tests/golden-storage-render.test.ts +
tests/storage-state-fields.test.ts 7/7, kernel issue6116/issue3769/
hide-consumed suites 27/27.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p2 pi scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compressing two adjacent ranges in one batch makes both sibling blocks claim the same boundary tool pair (live incident: pi session 01a1f6ff)

1 participant