Repository navigation
[PR] fix(storage): retire superseded same-msg_id generations on non-completeLog saves (#4392 facet C) - #4888
ranxianglei wants to merge 7 commits into
Conversation
…teLog saves (#4392 facet C) A genuine content rewrite under a stable client id mints a NEW identity (identity is content-derived; identity.ts strips only id/wireIndex/ledgerSeq), so remapPlanToAbsolute gave the fresh generation a new seq while the prior same-msg_id byte-row stayed resident. The #3285 sweep retires such stale rows only when opts.completeLog === true; envelope renders (completeLog-less) skip it, so the stale row rode every unified replay forever — permanent DIGEST DRIFT plus unbounded growth (triggered by subagent session-id sharing, #4769). Add a targeted sibling of that sweep in the full ingest path: when completeLog is not true and the session is not lane-owned, retire prior same-msg_id generations whose identity is absent from this ingest while their superseding generation is present. Targeting only msg_ids actively in the render keeps pruned renders safe (the very reason the global sweep stays gated on completeLog); lane sessions opt out (#3248 positional audit floor). Same retire-not-delete + media-ref discipline as the existing sweep — text CAS refs are kept, media refs released, reactivate-on-return still works. Regression test: tests/issue4392-msgid-supersede.test.ts (one live row per msg_id after a non-completeLog rewrite carries the latest content; an unchanged re-ingest churns nothing). Addresses #4392 (facet C — the reported [diverged: lastMessages] content divergence). Companion facets: #4685 (facet B, canonicalize key ordering); #4192/#4242 (facet A, top-level field list, already merged — unreleased). Trigger: #4769. Related storage workstream: #4316/#4532/#4540.
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.7335-pr.4888.2000ff4This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr4888.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复 —— 本 PR 是 #4392 下的 facet C(稳定 client id 内容被改写后旧代字节行永久驻留),与 facet A(#4192/#4242,已合未发)和 facet B(#4685)机制不同;未发现同机制的并行 PR。相关项:#4769(subagent 复用父会话 id,触发场景)、#3285/#4390/#4793(相邻 sweep 纪律)。 标签:bug / p1 / scope/storage / claude-code / codex(存储行无界增长属缓存泄露类,按 owner 2026-10-19 修订定 p1);顺手清掉了 #4392 上重复的 p2(严重度应恰好一个)。 本 PR 是我此前开的,按 [PR] 协议复核而非重做:拉了分支 结构化八问:
一处偏差需要你知晓:你在 #4392 批准的 Option B 原话是「删掉旧行」,实现是 retire-not-delete(墓碑)——与 #4390 既定的 historian 纪律一致:回放效果相同(每个 msg_id 一行活行,getMessages 过滤 retired),但字节保留到归档/复活、media ref 释放。比批准措辞更保守更安全,建议保持;若你坚持物理删除我再改。 review 中发现的一个同族残留(未擅自并入本 PR):MySQL 后端有自己的 ingestSession 拷贝(src/storage/mysql.ts:394-428),同样只有 completeLog 门控的 sweep、缺这个兄弟块——同一机制家族在 opt-in MySQL 后端上的同款缺陷。mysql.ts 当前有并行在途工作(#4678 v8 dedup),且本 PR CI 已全绿,我没有单方面扩大 diff;已作为子缺陷记入 #4392 清单。要并入本 PR 说一声即可(机械镜像 + contract-suite 场景,很小)。 判定:可合入,待人工 review —— p1 承重存储面,方向与你批准的 Option B 一致,机制镜像相邻已证明的 sweep 纪律,回归逐项审过无意向漂移,CI 全绿。合并动作仍留给人工。 |
… into sync-4888-master
What & why
Fixes facet C of #4392 — the
[diverged: lastMessages]content divergence reported on v0.1.207 (@BangDoll98): a stable client id whose message content was rewritten (a subagent re-dispatch reusing the parent session id, #4769) left BOTH the old and new byte-rows live in the unified store, so every replay carried the stale generation → permanentDIGEST DRIFT+ unbounded row growth.Root cause
identityis content-derived (identity.tsstrips onlyid/wireIndex/ledgerSeq), so a genuine text edit takes a NEW identity →remapPlanToAbsolutemints a fresh seq for the new generation while the prior same-msg_id row stays resident. The only thing that retires such stale rows is the#3285sweep, gated onopts.completeLog === true. Envelope renders are completeLog-less pruned views, so the sweep is skipped — correctly, since a global sweep on a partial view would delete live rows merely outside the render window. On the reporter's save class the stale generation therefore never got retired.Companion facets under the same issue/symptom, tracked separately: facet A (top-level field list) already merged as #4192/#4242 but unreleased; facet B (canonicalize key ordering) is #4685.
Fix
A targeted sibling of that sweep in the full ingest path (
src/storage/store.ts, immediately after it): whencompleteLog !== trueand the session is not lane-owned, retire prior same-msg_id generations whose identity is absent from this ingest while their superseding generation is present. Touching only msg_ids actively in the render preserves pruned-render safety (the reason the global sweep stays gated); lane sessions opt out (#3248 positional audit floor). It mirrors the existing sweep's discipline exactly — retire-not-delete (retired_attombstone), media refs released, text CAS ref kept, reactivate-on-return intact — so full and non-full paths now converge.Behavior change (disclosed)
retired_atcolumn, schema v8).Test
tests/issue4392-msgid-supersede.test.ts: after a non-completeLog rewrite of a stable client id, exactly one live row survives per msg_id carrying the latest content; an unchanged re-ingest churns nothing.Review note
Could not run tests/typecheck locally (no native
better-sqlite3build in this sandbox) — CI is the verifier. This touches p1 load-bearing storage under active development (#4316/#4532/#4540), so it needs careful human review; the change is minimal and mirrors the adjacent sweep's proven discipline. Happy to fold into the maintainers' storage workstream if sequencing prefers that.