Repository navigation
[PR] Recover legacy cross-session fold blocks stuck in parent sessions (#5312) - #5343
Conversation
(ai: vllm-qwen/qwen3.8-27b) 查重:重复(置信度 100%)——本 PR(#5343)与在途 PR #5334 是同一问题的两份并行交付:
标签: 审核进度(进行中):我已独立通读 #5343 全部 601 行 diff 与 #5334 全部 432 行真实 diff(未照抄任何一侧结论)。两者判据核心相同且都成立(零交集 = 可证明外来;retire-don't-delete 保证健康折叠的结构性豁免);差异在归档机制与风险面,见后续对比表。当前状态:两分支都与最新 master 在 |
054510c to
cdcf6be
Compare
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.7530-pr.5343.1cc3fa3This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5343.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(bot) 🏷 (ai: vllm-qwen/qwen3.8-27b) Review 结论#5343 实现方向正确、工程质量过关,但与 #5334 构成 100% 重复(同机制、同 issue 家族)。D2 被并行立了两票(#5308 @04:54Z 先,#5312 @06:15Z 后),两个 agent 各自交付 PR(#5334 @08:52Z,本票 #5343 @09:41Z)。先来后到:建议保留 #5308/#5334,关闭 #5312/#5343(duplicate 标签已打好,关闭由 owner 执行)。以下是对本 PR 代码本身的独立审核(未照抄 issue 侧结论,diff 已逐文件通读并在 rebased head 结构化八问(本 PR #5343)
回归审查(既有行为清单)
测试有效性审查6 个测试都是真行为测试(byte-exact round-trip 断言、策略双向 stub、真 index.db e2e),非假测试。缺口三处:① 核心安全前提「retired 行也算存在」只在测试名/注释里写了,没有任何测试真的 retire 一行再断言——未来谁给那条 SQL 加 retired_at 过滤,整个安全前提崩塌而测试全绿(B 同样缺这条 pin);② restore-against-already-live-twin 路径无测试(缺陷①正藏在那);③ apply 的 exit-code 语义未钉住。 缺陷清单(无论哪个 PR 存活,合并前应修)若本 PR 存活,必修五项:
A/B 对比(独立判断)
两者都是同一 option-A 设计的合格实现,差别在形状:A 更彻底(物理清理+内置恢复),B 风险面更小。 决策请求(owner 拍板)
我未向本分支推任何 nit 修复——查重判定下本票大概率关闭,推修复是浪费;以上清单可直接移植给存活 PR。 判定:review 完成——#5343 方向正确、无回归、质量过关,但与 #5334 平行重复;建议按选项 1 收口(关本票、保 #5334),待 owner 拍板。 |
… residue (#5312) D2 leg of #5095: fold blocks created under the <=v0.1.208 shared parent session-id era linger forever in the parent session after upgrade — the zombie-reap e-gate never accrues for a block whose covered ids never appear on the current wire, and syncBlocks' stillPresent collision keeps any shared-file-read block active every turn. Host-side option A (this PR): `bili sessions foreign-blocks` judges each persisted block against its session's FULL transcript (live + retired rows). Zero intersection = provably foreign -> reversibly archived (new block-level archive primitive, byte-exact round-trip); any intersection = collision that needs the kernel lineage field (option B, tracked separately) -> left alone. Dry-run by default; empty-transcript sessions are skipped (never mass-archived). Healthy folds are structurally spared because their covered ids stay in the persistent transcript. No config surface added (reuses the sessions CLI).
… test Review-driven, test-only (no production change). The sweep's entire safety argument rests on a healthy fold's covered messages staying queryable in the session transcript even after they are consumed/rewound. The first test was named "live + retired" but only ever created live rows, so a future regression that turned the historian sweep's RETIRE into a DELETE would slip through. Rewind id A out of the authoritative view (completeLog re-ingest of [B,C]) and assert allMessageIds still returns it alongside live B/C.
Review-driven one-line hardening in runForeignBlocks. Splitting on the FIRST colon truncated a session id that itself contains ':' (sid cut short, bid wrong). Block ids are plain (bNN) and never carry a colon, so lastIndexOf is strictly safer and byte-identical for every normal <sid>:<bid> input. typecheck clean + foreign-block sweep suite 6/6.
9727b4a to
7b78137
Compare
…flation when a live twin exists (review finding 1)
7b78137 to
93d3a88
Compare
…-export sweep-only types - config-surface-guard: --apply/--restore now referenced under 'bili sessions' (README) - unused-exports: ForeignBlockFinding/ForeignBlockApplyResult are only used inside foreign-block-sweep.ts — drop the leading export keywords
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.960-master.a13132b # this exact build
npm install -g billion-context@master # always the newest merged build
|
…e environment (corrects 9eb1aa3) 9eb1aa3 regenerated outside the suite's preload chain, so it captured the display-gate ON bytes (default since #5368) while every CI leg pins BILI_MESSAGE_TIMESTAMPS=0 via tests/preload-test-env.mjs — the committed digests could never match the pinned runners. This run uses the exact CI invocation (node --import ./tests/preload-storage-baseline.mjs --import ./tests/preload-test-env.mjs --import tsx), so wire bodies are back on the pre-flip gate-off values and the stateDigest fields pick up the persisted-state contract moves that landed on master after the goldens' last refresh (#5338 cost ledger, #5412 async latch parity, #5343 block archive). Turns=15/foldAt=9 unchanged; verified green locally under the same preloads (storage-engine-proofs + golden-storage-render).
Fixes #5312
What
Adds a host-side, reversible sweep that recovers legacy foreign fold
blocks stranded in a parent session by the old shared-parent-session-id era
(<=v0.1.209):
bili sessions foreign-blocks [--apply] [--json] [--restore <sid>:<bid>].Why (root cause, verified at current master head)
Fold blocks created while a sub-agent shared the parent's session id keep
living in the parent session after upgrade because two mechanisms reinforce
each other:
src/fold-reconcile.ts) never accrues a deathstreak for a block whose covered ids never appear on the current wire —
a foreign block's covered messages were never part of this session, so its
presence is permanently 0 and it is never reaped;
syncBlocks'stillPresentcheck (kernel/src/sync.ts) keeps any blockactive whenever one of its covered ids hashes-collides with a message in
the session — parent and child reading the same files produce identical
content-hash message ids, so the collision is structural, not accidental.
Neither the e-gate nor
orphan-gc(which only reaps full wire-orphans over3 consecutive turns) can catch a block with even a single recurring collision.
How
The sweep judges each persisted block against its session's full persisted
transcript (live AND retired rows — the unified store retires rows, never
deletes them, #4390). This is the decisive separation from the e-gate:
this session's own history) → overlap >= 1 → spared;
overlap == 0 → provably foreign.
Zero-overlap blocks are archived through a new block-level reversible
archive primitive (
UnifiedStore.archiveBlock/restoreBlock, byte-exactround-trip of row + content, logged to
block-archive.jsonl). Any-overlapblocks are reported as
collisionand left alone — they need the kernellineage field (option B below), not a host-side guess.
Safety properties, each pinned by a test:
--applyacts;#suffixvariantstill counts as present), so we under-report rather than mis-archive;
Config surface
None. Reuses the existing
bili sessionsCLI; no new config key, env var, orCLI flag beyond the additive
--apply/--restoreon this subcommand.Behavior changes
Purely additive. No existing path is modified. New: a
sessions foreign-blockssubcommand (dry-run default). Archiving a block takes effect on the next
session load/restart (a running proxy keeps its in-memory copy until reload).
--restore <sid>:<bid>brings a previously archived block back.Option B (tracked separately, NOT in this PR)
Collision-bearing foreign blocks cannot be distinguished from healthy folds
host-side (the
blockstable carries no conversation-origin field). The rootfix is a kernel change: give each block a creation-time conversation-key
lineage field and have
syncBlocksactivate only lineage-matching blocks.That is a
kernel-changerequiring owner approval + human-only review, filedas a separate p1 decision request.
Verification (on rebased head = current master)
npm run typecheckclean;tests/foreign-block-sweep.test.ts(6 tests: engine round-trip, policyclassification, empty-transcript/no-covered guards, failed-archive surfacing,
full facade e2e) green;
storage-archive-gc,storage-maintenance-cli,doctor(39 total);sessions foreign-blocksrenders the plan,--applyparses, unknown-action guard intact.