Repository navigation
[PR] fix: parity digest compares ref-map contents, not key order (#4986) - #4997
ranxianglei wants to merge 4 commits into
Conversation
The sampled ingest read-back verify false-alarmed DIGEST DRIFT on every save of a session whose in-memory messageRefs key order diverges from the stored refs-row order: the expect leg carries the kernel-mutated in-memory order (#4316 ledger-aligned byRef is rebuilt in ledger-seq order) while the got leg rebuilds from rows in ingest ord, which finishPlan froze at the last full ingest. Identical content under different key insertion orders then dropped the ingest watermark and forced a full-tail re-ingest on the next save, with an error-level log line each time (repro: tests/storage-json-writer-off.test.ts). shadowDigest now normalizes plain-object/Map/Set key order before hashing, at its single private definition so both verify legs (sync sqlite and async mysql) are covered at once. Real divergences stay visible: key sets and values still compare byte-for-byte. No persisted digest or golden depends on shadowDigest output (private to shadow.ts, both legs always hash under one build), so cross-version comparability is unaffected; canonicalize itself is untouched. Same philosophy as #3407's orderedBlockContents and #3113's sortObjectKeys golden pins. Behavior change (intended): order-only differences between the two legs are no longer reported as drift. Pre-fix this class fired on every affected save; post-fix it never fires. Content-drift detection is unchanged — issue4323-drift-escalation, storage-ingest-watermark and issue3919-shadow-drift-forensics still catch real drift and escalate. Regression test: tests/issue4986-digest-drift-ref-order.test.ts (red on master — verifyDrift 1 vs expected 0 — green post-fix).
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.6619-pr.4997.2935b1aThis exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr4997.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重结论:本 PR 代码本身无重复实现,但与在途 PR #4685 重叠——同一机制的两个修法,需 owner 拍板走哪条车道。
标签:bug + scope/storage + p2(存储层采样校验假阳性:无数据丢失、能用,但受影响会话每次保存都有写放大 + error 日志噪音)。 独立核验(未照抄 PR 描述,逐条对过代码与本地实测)机制查证:
本地定向实测:
CI(镜像快照 @17:47Z,sha 03f4f3d):6 绿 + 11 skipped + 13 运行中/排队,0 红;最终判定等 CI 全量跑完。 结构化八问
代码质量(从严标准):命名达意、注释讲为什么、无死代码/魔法数、风格一致;回归测试有牙(断言 corpus 前置条件防空转通过 + verifySamples/verifyDrift/verifyOk 三向断言)——合格。 结论:代码本身干净、可合(待 CI 全绿)。但因与 #4685 同机制重叠,建议 owner 先拍板车道再合,避免合完再拆冗余。 决策请求:#4997 与 #4685 走哪条车道?
推荐:B。 理由:在共享 canonical form 的定义点修更近根因(canonical form 本就不该含序列化顺序,正是 #3113「pin logical content, not serialization order」的哲学),且堵住后续摘要路径的同类坑;#4685 已经两轮 review 收敛,弃掉已通过审阅的外部贡献不符合仓库惯例。配套动作:#4685 合并后把 #4997 标 superseded 关闭,并将其回归测试 |
(ai: vllm-qwen/qwen3.8-27b) 收工状态确认(完整 review 见上方楼层,此处为收尾摘要):
|
(ai: vllm-qwen/qwen3.8-27b) CI 已修,push 完成,新一轮 CI 已在 八问:
备注两点:①镜像 git 端点当时返回 502,本次直接 push 到 GitHub(PR 分支的规范位置,CI 触发正常);②#4599 floor 394 有另一个 agent 报告该 twin-ladder 套件的 e2e case 2 断言对 master 文案可能"先天红"——但 ci-fixes 验证 run 的 8 个 shard 全绿说明它在 CI 矩阵下能过(e2e 段大概率被门控);若本轮重跑仍有单个 shard 红且签名指向那里,请在 #4599 跟进,不在本 PR 处理。 判定:修复动作已完成,等 |
…est from ranxianglei#4997) ranxianglei#4997 opened for ranxianglei#4986 the same root cause ranxianglei#4685 fixes in canonicalize. Its regression test fails on master b08fbf3 (DIGEST DRIFT for corpus-folded) and passes here without the shadowDigest change, so it carries over unchanged.
|
I support option B from the review above. Here is the evidence. I copied this PR's regression test,
So the #4685 also has If you prefer option A, for the smallest golden change, that works for us too. Merge this PR, and I will trim #4685 down to the wording fix and the shared skip table. |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) merge-guard 同步已完成:master 对 #4685 侧 option B 证据的独立核验(拉了实际树):head A/B 车道决策留给 owner(agent 无权合并/关闭):floor 3 review 推荐 B(在共享 canonical form 定义点修更近根因),#4685 作者证据进一步支持 B。B = 合 #4685 → 本 PR 标 superseded、#4392/#4986 并案(owner 执行关单);A = 合本 PR → #4685 裁成「文案修正 + 共享跳过表」follow-up。除同步 push 外未做任何改动,等 owner 拍板。 |
|
plan b合并 |
Closes #4986
Problem
The ingest read-back verify reported DIGEST DRIFT on EVERY save of sessions whose in-memory
messageRefskey order diverges from the stored refs-row order (the folded-corpus shape; also after #4316 ledger alignment). Cost per affected save: error-level log + dropped ingest watermark + full-tail re-ingest next save. No data loss, but write amplification + log noise on a hot path, and repeated streaks feed the #4323 escalation path.Root cause
The parity digest (
shadowDigest→canonicalize) treats plain-object/Map key insertion order as content:loadLegacyViewover stored rows — rows carryord, whichfinishPlanfroze at the byRaw key order of the LAST full ingest.Identical keys and values under different insertion orders → hash mismatch → false drift on every sampled save (the first ingest of a fresh sidecar is always sampled).
Fix (direction A from the issue)
Normalize key/entry order before hashing, inside
shadowDigest's single private definition — both verify legs (sync sqlite AND async mysql) are covered at once. Same philosophy as #3407'sorderedBlockContentsand #3113'ssortObjectKeysgolden pins ("pin logical content, not serialization order"). Key order of these lookup maps carries no contract meaning (identity is per-key lookup, never position), so an order-only difference is ALWAYS a false positive; sorting removes the whole class while every real divergence stays visible (key sets and values still compare byte-for-byte).Why not direction B (keep producer order aligned): row order is frozen at full-ingest time, so alignment would require rewriting persisted ord bytes on every save (more write amplification than the bug itself), changes persisted envelope bytes (persistence-format territory), and makes every future byRef mutation site a latent drift source. B does not remove the verifier's fragility; A removes the false-positive mechanism itself.
Behavior change disclosure (intended)
Audit (per the issue's "must audit other shadowDigest consumers")
shadowDigestis private tosrc/storage/shadow.ts; only callers are the two verify legs. No persisted digest, golden pin, or cross-version comparison depends on its output — both legs always hash under one build.canonicalizeuntouched → corpus manifest pins (scripts/update-storage-corpus.ts) and all test-side digests unaffected.describeViewDivergenceuntouched (runs only on detected real drift).Verification (targeted local runs on rebased head; full-suite verdict = CI on the pushed head)
tests/issue4986-digest-drift-ref-order.test.ts: RED on master (verifyDrift actual=1 vs expected=0, DIGEST DRIFT line fired), GREEN post-fix. Asserts the corpus precondition (byRef order ≠ row-projected order) so it cannot pass vacuously.tests/storage-json-writer-off.test.ts(the issue repro): 3/3 green, DIGEST DRIFT line gone.npm run typecheckclean.