Repository navigation
fix: fold-reconcile survives cross-model re-serialization churn (pi model switch) — assistant-turn key + image-capability variant passes - #2644
Conversation
…odel switch) — assistant-turn key + image-capability variant passes (#2636) A host replaying one conversation onto a different model re-serializes every thinking-bearing assistant turn (pi's transformMessages: isSameModel=false inlines thinking as plain text) and swaps image parts for fixed placeholder lines on text-only targets. The kernel mints ids over the changed shapes, so every covered assistant/user core goes missing at once: 211/211 on the reporting session — the originals replayed unfolded and the fold substrate escalated to destroyed (#2636). Pass 0 positional identity cannot pair these (a pair↔merged shape change misaligns positions at the first thinking turn), toolCallId only saves tool results (16 there). Two new exact-match passes close the gap: - Pass 3 — assistant-turn key: the anchor carries the normalized FULL turn text (reasoning + seam + reply; both seam forms, pi joins with ""), so pair→merged claims both member ids onto the one merged witness and merged→pair claims both new cores. Duplicated turns stay unmatched. - Pass 4 — image-capability variants: a trailing NON_VISION placeholder line stripped/appended, exact normalized identity, unique witness or k-th family pairing. Claims are now Map<old, new[]> (1→N and N→1); rewriteBlocks splices targets in and removes the second member of an N→1 collapse so a block never lists an id twice. Turn keys are seeded lazily (#2334: steady state pays zero) and backfilled once for pre-existing anchors (bare assistant cores only — user/tool anchors never carry one). Offline sim on the reporting session's real jsonl (692 messages, qwen→glm both directions mixed): 347 unmatched → 16, all 16 = pi's dropped "Attached image" wrappers (honestly absent from the new wire). 377 turns re-anchored via the turn key, 16 tool results via toolCallId. Fixes #2636
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2861-pr.2644.891d603This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2644.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Review 结论(结构化八问):可合 —— 方向对、根因分层正确、实现正确且防护到位、测试有牙、既有 reconcile 路径零回归、稳态成本不变、持久化向后兼容。合并前需 rebase(当前 ① 是什么问题:pi 会话切模型后 fold-reconcile 把整段已压缩历史判成「丢失」并升级成 substrate-destroyed。#2636 的真实触发不是模型能力变化本身,而是 pi ② 什么原因导致的:内核 message id = role|contentType|toolName|toolCallId|text 的内容哈希,形状一变 id 就变。同模型下是「reasoning core + text core」两核,跨模型下 pi 用 ③ 影响范围与严重程度:仅影响「同一 pi session 内切换了不同模型」的场景;单模型长会话完全不受影响(稳态 early-return 不触碰新路径)。严重度:特定条件下功能受损——该场景下旧会话的压缩历史被误判销毁、触发 substrate-destroyed 降级,但不会静默丢数据(有 guard,拿不准就不认领)。 ④ 怎么修复的:在既有 ladder 之上加两道精确匹配 pass(绝不 fuzzy、不动内核):
⑤ 是否有回归问题:无。逐项核查既有行为:
⑥ 是否破坏缓存:不涉及。缓存账本(cache-ledger-prompt-switch 29/29 通过)不受影响;改动只在协调层重写 fold-block 的 id 引用列表,不触碰 prompt/wire 字节。 ⑦ 是否改了设计方向:不涉及架构转向。是在既有「多 pass 精确协调」框架内新增两个 pass,方向与 #2334/#2390/#2476 一脉相承,边界清晰(host churn 明确划出 scope)。 ⑧ 是否引入了新的配置:不涉及。无新 env/config/默认值。 测试有效性(④):高质、有牙。10 个 plan-level case 断言精确 claim 映射(如 我的独立定向验证:两棵 worktree 均无 node_modules(全量 npm ci 属 CI 职责,本地不预跑)。改为零依赖 standalone 脚本跑纯函数真实场景(verbatim 函数体,node:crypto only):8/8 PASS —— pi seamless 无尾换行 cand==p2 且 !=p(seamed)、尾换行 cand==p&p2 双中、显式 \n seam cand==p、image append 方向 stripped==anchor.n、image strip 方向 appended==anchor.n、不同 turn key 不相撞(never-fuzzy 前提)。独立佐证了作者离线 sim 的核心碰撞机制。 两处非阻塞小观察(不建议为此推 commit,PR 正 behind 待 rebase):
判定:可合。请 rebase 到最新 master 后等 CI 全量绿再人工合并。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.229-master.fefb16f # this exact build
npm install -g billion-context@master # always the newest merged build
|
A host metadata-table refresh can re-serialize every past thinking turn of one session in a different wire form (reasoning_content field vs reasoning spliced into content), minting new ids for unchanged content. Fold re-anchor then reports 'covered id(s) missing with no anchor match' on every request: the turn-key pass only understood bare-concat merges, and pre-#2644 anchors lack p/x entirely — while the wire-side backfill can never fire because the flip puts the old id off the wire on the very pass that also rolls the order backbone forward without it. - fold-reconcile: extractThinkingMerge mirrors the kernel's demoted-thinking FORMS so merged-form cores register the same turn keys as split-form anchors (turnContexts + Pass 3 candidate side); ReconcileOptions.storedMessages rebuilds eligible legacy anchors from stored decompositions BEFORE the plan runs, so the flip pass itself claims. - storage: UnifiedStore.messagesForIds (+seq±1 neighbors for rc-pair adjacency), shadow/persist pass-throughs gated on full mode. - new fold-decomposition-lookup: per-pass capped lookup with a tried-set (index absence is stable, index unavailability retries). - import entry: record/session/ingest carry an optional decompositionLog (external converter payload) interned first at ingest; consume-once at save keeps the #3133 delta fast path intact; buildRecord never emits it. No new config surface. Additive optional fields only (ReconcileOptions. storedMessages, LegacySessionLike.decompositionLog, PersistedSession. decompositionLog) plus an internal metadata bookkeeping key foldStoredTried. No kernel/ changes. Fixes #3301
A host metadata-table refresh can re-serialize every past thinking turn of one session in a different wire form (reasoning_content field vs reasoning spliced into content), minting new ids for unchanged content. Fold re-anchor then reports 'covered id(s) missing with no anchor match' on every request: the turn-key pass only understood bare-concat merges, and pre-#2644 anchors lack p/x entirely — while the wire-side backfill can never fire because the flip puts the old id off the wire on the very pass that also rolls the order backbone forward without it. - fold-reconcile: extractThinkingMerge mirrors the kernel's demoted-thinking FORMS so merged-form cores register the same turn keys as split-form anchors (turnContexts + Pass 3 candidate side); ReconcileOptions.storedMessages rebuilds eligible legacy anchors from stored decompositions BEFORE the plan runs, so the flip pass itself claims. - storage: UnifiedStore.messagesForIds (+seq±1 neighbors for rc-pair adjacency), shadow/persist pass-throughs gated on full mode. - new fold-decomposition-lookup: per-pass capped lookup with a tried-set (index absence is stable, index unavailability retries). - import entry: record/session/ingest carry an optional decompositionLog (external converter payload) interned first at ingest; consume-once at save keeps the #3133 delta fast path intact; buildRecord never emits it. No new config surface. Additive optional fields only (ReconcileOptions. storedMessages, LegacySessionLike.decompositionLog, PersistedSession. decompositionLog) plus an internal metadata bookkeeping key foldStoredTried. No kernel/ changes. Fixes #3301
…ei#3301) A host metadata-table refresh can re-serialize every past thinking turn of one session in a different wire form (reasoning_content field vs reasoning spliced into content), minting new ids for unchanged content. Fold re-anchor then reports 'covered id(s) missing with no anchor match' on every request: the turn-key pass only understood bare-concat merges, and pre-ranxianglei#2644 anchors lack p/x entirely — while the wire-side backfill can never fire because the flip puts the old id off the wire on the very pass that also rolls the order backbone forward without it. - fold-reconcile: extractThinkingMerge mirrors the kernel's demoted-thinking FORMS so merged-form cores register the same turn keys as split-form anchors (turnContexts + Pass 3 candidate side); ReconcileOptions.storedMessages rebuilds eligible legacy anchors from stored decompositions BEFORE the plan runs, so the flip pass itself claims. - storage: UnifiedStore.messagesForIds (+seq±1 neighbors for rc-pair adjacency), shadow/persist pass-throughs gated on full mode. - new fold-decomposition-lookup: per-pass capped lookup with a tried-set (index absence is stable, index unavailability retries). - import entry: record/session/ingest carry an optional decompositionLog (external converter payload) interned first at ingest; consume-once at save keeps the ranxianglei#3133 delta fast path intact; buildRecord never emits it. No new config surface. Additive optional fields only (ReconcileOptions. storedMessages, LegacySessionLike.decompositionLog, PersistedSession. decompositionLog) plus an internal metadata bookkeeping key foldStoredTried. No kernel/ changes. Fixes ranxianglei#3301 (cherry picked from commit b5756bb)
Fixes #2636
What breaks today
A host replaying one conversation onto a different model re-serializes every thinking-bearing assistant turn (pi's
transformMessages:isSameModel === falseinlines thinking as plain text parts; same-model replay keeps the structuredreasoningchannel) and replaces image parts with fixed placeholder lines when the target is text-only. The kernel derives message ids over the resulting core shapes, so every covered assistant/user core goes missing at once — on the reporting session 211/211 covered ids missed, the originals replayed unfolded (context blow-up), and after 3 passes the drift escalated tocompression substrate appears destroyed(fold state effectively lost).Why the existing passes don't catch it
The fix — two exact-match passes on top of the existing ladder
Pass 3 — assistant-turn key (#2636). The anchor now carries a turn key: the normalized FULL turn text (reasoning + seam + reply), whichever wire form the turn was replayed in. pi joins the parts with
"", other hosts with"\n"— pairs carry both seam forms (p/p2) and the matcher probes both; equality only when normalization collapses the difference. Matches both directions:claims: Map<old, new[]>);Pass 4 — image-capability variants (#2636). A covered user text flips between
textandtext + "\n" + (image omitted: model does not support images)across the switch (pi'sNON_VISION_USER_IMAGE_PLACEHOLDER, byte-stable). The pass tries one trailing placeholder line stripped/appended against the anchor's normalized identity — unique witness, or k-th family pairing when K anchors share one key with K candidates (identical "Attached image" wrappers). Tool-role messages keep going through pass 1 (toolCallId, no length guard).Plumbing.
claimsis nowMap<old, new[]>(1→N and N→1);rewriteBlockssplices targets in, dedupes, and REMOVES the second member of an N→1 collapse so a block never lists an id twice. Turn keys are seeded lazily (#2334: steady state pays zero extra normalizations — perf suite pins this) and backfilled once for anchors persisted before this change (bare assistant cores only; user/tool anchors never carry a turn key, so theirp === undefinedsteady shape must not re-trigger a rebuild every pass).Evidence
convertMessagesfor each model and diffs the kernel cores): unmatched 347 → 16. All 16 residuals are pi's dropped "Attached image(s) from tool result:" wrappers — honestly absent from the new wire (pi synthesizes them only for vision targets), kept unmatched by design. 377 assistant turns re-anchored via the turn key, 16 tool results via toolCallId.#2636describes intests/fold-reconcile.test.ts(10 plan-level cases + 2 integration cases incl. the no-escalation regression).tests/fold-reconcile.test.ts+tests/fold-reconcile-positional.test.ts= 80/80.origin/master(2d31e42): all are the known sandbox-network class intests/dsh-native.test.ts/tests/claude-native.test.ts("manifest registration failed (fetch failed)", 15s timeouts). Zero branch-only failures.npm run buildclean (new code present in dist).Non-goals / boundaries