Skip to content

[PR] fix: re-anchor folded history across host wire-shape flips (#3301) - #3316

Closed
ranxianglei wants to merge 4 commits into
masterfrom
2026-10-16_shape-flip-reanchor
Closed

ranxianglei wants to merge 4 commits into
masterfrom
2026-10-16_shape-flip-reanchor

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #3301

背景

宿主(opencode)元数据表刷新后,同一会话早先的思考消息整段换成另一种 wire 形态(reasoning_content 字段 ↔ 合并进正文),内容哈希 id 空间非平稳,已折叠锚点认不回来([fold-reconcile] resent history drifted: N covered id(s) missing)→ 原文重新上线、上下文上涨、重复压缩。

顺序为中心的对账梯队(#2821/#2915)契约前提是结构稳定(条数/顺序不变,id 可重铸);形态翻转是重塑形(每个 thinking turn 2 核→1 核),超出其生存域——属上游前提被破坏,不是机制失效。根因修复在产生端:opencode-acp#483 请求时归一化历史思考形态(见相关)。本 PR 只保留对自愈够不到的历史损伤的确定性恢复。

改造说明

初版含运行时形态猜测(extractThinkingMerge)。owner 评审认定为打膏药(新变体出现需再追一轮),已撤除(commit 8a00b3d);产生端钉死由 opencode-acp#483 承担,本 PR 不再做任何运行时猜测。

修复内容(全部确定性,零猜测)

Part B — 从存储真值重建遗留锚点(#2644 之前铸的锚点无 turn key;老 id 在翻转后第一条请求即离开 order backbone,wire backfill 永远不会触发):

  • ReconcileOptions.storedMessages + reconcileFoldCoverage pre-plan 锚点升级(src/fold-reconcile.ts):规划前为符合条件的锚点(bare assistant、无 toolCallId、不在当前 wire 上)从存储分解重建 p/p2/x/c/sh/wh;
  • 新增 src/fold-decomposition-lookup.ts:选取目标锚点(每轮上限 256)、读统一索引行、latest-seq-per-id 去重、返回 CoreMessage[];索引不可用时不消耗尝试次数、下轮重试;
  • UnifiedStore.messagesForIds(只读,分块 IN-list + seq±1 邻接)/ shadow 透传 / SessionStore.unifiedMessageRows(readsUnified 门禁 + try/catch→null);
  • 四个 wire 站点接线(prepare-openai/responses/google/anthropic):reconcile 关闭时完全跳过查询。

Part C — 外部导入入口(外部导入账本在索引库无行——#3301 待确认点):

  • 可选输入字段 decompositionLog(session record / LegacySessionLike):导入时恰好消费一次、优先 intern 进现有 messages 表(最低 seqs);不写回磁盘记录;存在期间 delta planner 走全量路径。

相关(同一家族,按包边界拆分)

行为变更披露

项 旧 新 原因
ReconcileOptions.storedMessages 无 可选字段,undefined = 现状行为 确定性恢复源
session record decompositionLog 无 可选瞬态输入字段,不落盘 外部导入器递原始分解
foldAnchors 元数据 p/p2/x 可能缺失(legacy) 从存储行回填(字段本身未变) 遗留锚点修复
索引库 — 只读新方法,零 DDL 复用已有行
配置面 — 无新增 env/config/CLI —
kernel/ — 未触碰 —

稳态成本为零:各门禁均要求「存在遗留锚点 ∧ 索引可用 ∧ reconcile 开启」三者齐备才工作,健康锚点的会话什么都不做。

验证

  • npm run typecheck clean(rebased head)
  • 定向测试 88/88 pass:tests/issue3301-shape-flip-reanchor.test.ts(resolveStoredDecompositions DI 套件、decompositionLog ingest 套件、untagged-merge heal e2e、honest-blind test、store-level messagesForIds 块[reviewer 补])、tests/fold-reconcile.test.ts、tests/issue2636-model-switch-reconcile.test.ts、storage ingest/unified 套件
  • 全量判定:远程 CI test lanes

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。 本 PR 即 #3301 的修复 PR(Closes #3301),#3301 侧已做过家族查重(与 #2636/#2915 同属「宿主换形态重发、内容哈希身份失效」机制家族但触发面新:opencode lane + 元数据表刷新驱动的 thinking 形态翻转)。出站查重:无其他在途 PR 触碰 fold re-anchor / turn-key 通道。

当前状态:PR 分支基于 b2868ca68,master 已前进到 6ee4a2ac9(#3289/#3053/#3268/#2987/#2492/#3080/#3295 等多个合入),GitHub 标记 mergeable: false / dirty(真实文本冲突,不只是 behind)。正在做:rebase 到最新 master → 按意图并集解冲突 → 本地定向验证 → push。完成后按八问给完整审核结论。

@ranxianglei
ranxianglei force-pushed the 2026-10-16_shape-flip-reanchor branch from 8e302a5 to 3dd9263 Compare October 15, 2026 18:14
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-16_shape-flip-reanchor (a233c6c)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3919-pr.3316.73645f9

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

本 PR 带 ework-agent-pr 标记(前序会话的产出),按规则未重做:拉取分支、独立审了全部 diff、核对 CI,补了两个小修后给出结论。查重结论此前已回帖:不重复(#3301 同家族但触发机制不同)。

审核与处置摘要

Rebase:PR 切出时 base b2868ca68,现在 master 已到 6ee4a2ac9(期间合入 #3050/#3194/#3250/#3266 等)。cherry-pick 到 master 只有 src/persist.ts 一处冲突——#3194 的 folded-tail 保留逻辑与本 PR 的一次性 payload 包装改了同一行,按意图并集解决(两者都保留),其余 hunk 全部自动合并。分支已 force-push,PR head 现为 feb71403b。

独立审核结论(逐文件读了 diff,不是复述 PR 描述):

  • kernel 镜像逐字节核验通过:src/fold-reconcile.ts 的 THINKING_MERGE_FORMS/extractThinkingMerge 与 kernel/src/wire/demoted-thinking.ts FORMS+split 循环算法一致(offset-0 纪律、glue 消费、parts.join("\n"))。漂移只会导致诚实缺失,不会误认领。
  • 唯一解门、长度护栏(single +64 / pair max(256, b>>2))、x-sibling 收拢、backbone/MAX_ANCHORS 语义均未被改动;claim 应用仍只在 repair 模式落盘,warn 只算不算。
  • 存储链全链路核验:decompositionLog payload 经 guardedBuild→shadow.record→legacyLoad→toLegacyLike→planIngest 一次性 intern(seq 最低)进索引,session 内存值随即清空,稳态 save 不带该字段,影子存储(默认开启)每次落盘把整个会话重新序列化+哈希,大会话明显变卡;jsonWriter=off 时连防抖合并都没了 #3133 delta 快速路径不受影响;messagesForIds 只读、分块 IN-list(500+1 < SQLite 999 上限)、CAS 解析 content hash,无 schema 变更。
  • reconcile off 四个 wire 站点零开销(lookup 函数根本不被调用);kernel/ 未触碰。

审核中补的两个小修(独立 commit,已在 head 上):

  1. feb71403b:去掉 DecompositionSource 的多余 export——unused-exports 门禁在 CI 红了,本地复现同签名,一行修复;
  2. 324d4fa52:给 UnifiedStore.messagesForIds 补一条基于真实 index.db 的行为钉住测试(原 22 测全是注入式假源,真实存储方法无覆盖)→ 现 23 测。

一处微行为变更披露(审核发现的唯一语义面变化):两个逐字重复的思考回合若仅标记风格不同(\``thinkingvsthink` 标签),过去靠各自不同的裸 key 都能认领,现在共享同一 pair key → 歧义诚实跳过。方向安全(诚实缺失 << 误认领),实际概率≈0,列出供知情。

结构化八问

  1. 是什么问题:宿主(opencode lane 实锤)元数据刷新后,同一会话所有历史思考消息换 wire 形态重发(思考放 reasoning_content 字段 ↔ 拼进 content 正文);内容没变但 id 是内容哈希所以全变,fold re-anchor 认不回来,每轮请求报 covered id missing,已折叠原文重新上线、上下文膨胀再压一遍。
  2. 什么原因导致的:两层——① turn-key 桥接(fix: fold-reconcile survives cross-model re-serialization churn (pi model switch) — assistant-turn key + image-capability variant passes #2644 Pass 3)候选侧只登记「裸正文」和「相邻 reasoning+text 对」两种形态,宿主把思考带标记拼进正文时,合并 core 派生的 key 与拆分锚点的 key 对不上,唯一解门跳过;② pre-fix: fold-reconcile survives cross-model re-serialization churn (pi model switch) — assistant-turn key + image-capability variant passes #2644 老锚点没有 p/x 字段,回补窗口只在旧 id 还在 wire 上时存在,而翻转那一轮恰好把旧 id 踢出 wire 且 backbone 向前滚,回补永远等不到。
  3. 影响范围与严重程度:触发条件明确(宿主刷新模型元数据致思考形态翻转的长会话;报告者实测 bili 0.1.196/0.1.197、opencode 1.19.0/2.0.24,drift 一度 986)。体验退化级:上下文增长、重复压缩、token 浪费——非数据丢失、非不可用。纯 legacy-only(未开统一存储)且锚点无 p/x 的会话保持现状(诚实失明),开统一存储或提供 decompositionLog 即被覆盖。
  4. 怎么修复的:疏不堵,让既有机制覆盖这种 churn——① extractThinkingMerge 从合并形态解包出成对 turn-key(kernel FORMS 的字节镜像,只用于 key 派生不参与 identity minting),rc↔merged 双向都能过唯一解门(N→1 / 1→N 走既有 claim 路径);② 对无 p/x 的老 assistant 锚点,在 planReconciliation 之前从统一索引库读最新 seq 原始行重建锚点(每轮上限 256,tried 簿记防反复查,索引不可用≠无行可重试),翻转那一轮就能直接认领;③ 外部导入入口 decompositionLog:外部转换器的原始分解 ingest 时最先 intern、save 时一次性消费。
  5. 是否有回归问题:逐项清点过——exact-id pass、toolCallId/twin/simhash/order-bracket 各通道、唯一解门、长度护栏、MAX_ANCHORS、backbone 语义、影子存储(默认开启)每次落盘把整个会话重新序列化+哈希,大会话明显变卡;jsonWriter=off 时连防抖合并都没了 #3133 delta 快速路径(guardedBuild 仅在 payload 存在时介入)、[Bug] pi lane: switching models mid-session replays the full history and drops fold state — cross-model re-serialization churn defeats fold-reconcile anchors #2636 p 回补分支(与 master 逐字节一致)、Boot warm set off by default: sessions hydrate on first touch (#3050 R3 step 1) #3194 folded-tail 保留(rebase 冲突处并集保留)——均未改变;reconcile off 零成本;kernel 未触碰。唯一微变更见上(重复思考回合标签风格碰撞 → 诚实跳过,方向安全)。
  6. 是否破坏缓存:不涉及。prefix cache/重试/增量游标策略未动;payload 只搭一次车进索引,磁盘记录永不携带字段,持久化格式无 schema 变更。
  7. 是否改了设计方向:不涉及。仍在 order-centric reconciliation(公告:release v0.1.193 修复dsh 切模型导致上下文暴涨问题,修复fork问题,修复claude codex dsh等自动压缩导致会话破坏问题 . 另外修复几十个bug. 我本地场景有限,未必都测全,麻烦大家小场景先测试下是否有问题.任何问题及时反馈. #2821/fix(dsh): model switch drops all folds — fold-reconcile #2396 detect-only cannot re-anchor rewritten tool-call ids → doom-probe 502 session death #2915)框架内加证据通道与 pre-plan 锚点重建;存储层纯只读扩展;资格判定仍共用单一投影([Bug] recommend/apply 对同一区间的 turn-integrity 判定永久不一致:acp_status 反复推荐的区间被 apply 侧整段拒绝(0.1.196,Range would split N turn(s) at the protected-zone boundary) #3236 纪律未破)。
  8. 是否引入了新的配置:无。config surface 零新增;ReconcileOptions.storedMessages? / decompositionLog? / foldStoredTried 均为内部 API/簿记键,additive optional。

CI 状态与收工判定

本地定向:typecheck 干净;fold-reconcile 系 / issue3301(23)/ storage 系 / issue2636+2915 / compaction-archive 等定向合跑 242 pass / 0 fail(1 pre-existing skip)。

CI(head feb71403b,run 38785818953):guard/e2e/static-gates 全绿;12 条 test lane 红 6 条,全部判定与本 PR 无关:

收工判定:代码就绪可合。 当前 CI 红全部来自 master 存量问题,不是本 PR 的回归。下一步建议:你合并 #3314+#3317 后告诉我,我把本 PR rebase 到新 master 推上去,CI 应能全绿,届时即可合并本 PR。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

冲突唤醒核查结论:本次为陈旧通知,分支已是干净状态,未做任何 rebase/push。

核查过程(证据):

  1. git fetch origin master → master 仍在 6ee4a2ac9(上一轮 rebase 的落点,此后 master 未再前进)。
  2. git fetch origin refs/pull/3316/head → PR head feb71403b,本地测试合并:git merge origin/master 返回 Already up to date(master 是 head 的直系祖先,零冲突、零 diff)。
  3. GitHub API 实时状态:mergeable: true,mergeable_state: blocked(blocked 来自 CI 检查,不是冲突),base sha = 6ee4a2ac9 = 当前 master。

即:dirty 状态是 force-push 落地前算出的旧值(或重复转发),现在 GitHub 自己已经判干净了。按「不要重复 rebase」纪律,不硬造动作。

结构化八问

  1. 是什么问题:系统转发称本 PR 与目标分支冲突(dirty),需要 rebase 解冲突。
  2. 什么原因导致的:通知基于 force-push 之前的旧 mergeable 快照;上一轮会话已完成 rebase(b2868ca68 → 6ee4a2ac9,head feb71403b)并回帖。master 自那以后没有新提交,不存在新的冲突面。
  3. 影响范围与严重程度:无——代码零变更,纯状态误报。
  4. 怎么修复的:无动作可修。做的是三方核验(本地 fetch + 测试合并 + GitHub API 实时查询),确认分支已包含最新 master 且可合并,而不是盲目再 rebase 一次制造无意义的新 commit。
  5. 是否有回归问题:不涉及——没有任何提交/推送,diff 为零。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:无。

CI 现状(head feb71403b,与上轮一致)

30 项 check-run:24 绿 / 6 红,红的全是 master 存量问题,非本 PR 回归:

收工判定

分支就绪、无冲突、可合并性已由 GitHub 确认。维持上轮建议:等 #3314 + #3317 合入 master 后叫我一声,我 rebase 到新 master 推上去,CI 应能全绿,届时本 PR 即可合并。在此之前本 PR 无需任何操作。

awork added 4 commits October 16, 2026 09:56
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
…view supplement)

The new DB method carried chunked IN-lists, seq±1 neighbor expansion and
CAS content resolution but no direct store-level test — every other facet
of #3301 was pinned, this one only exercised through injected fakes.
…guessing (#3301)

Owner review: runtime form extraction in the reconciler chases symptoms —
the flip producer is the host serializer choosing the reasoning field from
the current metadata table. The root fix pins the wire shape at the plugin
transform boundary (separate PRs: opencode-acp for the 1.x lane,
opencode-native here for the 2.x lane), after which the wire re-mints the
original ids and existing exact-id + backfill mechanisms self-heal.

This commit removes that speculative half (THINKING_MERGE_FORMS,
extractThinkingMerge, its turnContexts/Pass-3 registrations and their
tests) and keeps the deterministic half: pre-plan anchor rebuild from
stored decompositions (unified index rows) + the decompositionLog import
entry.
@ranxianglei
ranxianglei force-pushed the 2026-10-16_shape-flip-reanchor branch from 8a00b3d to a233c6c Compare October 16, 2026 02:00
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

冲突已解决,rebase 完成并推回分支。 这次是真实冲突(与上次不同):master 已从 6ee4a2ac9 前进到 a046d4ecd(合入 #3196、#3298、#3202、#3275、#3286/#3287、#3292、#3309 及 #3312–#3320 批次等),且本 PR 分支期间也新增了一个评审跟进提交(8a00b3d17「收窄到确定性恢复、去掉形态猜测」)。已把 4 个提交整体 rebase 到 a046d4ecd,新 head a233c6c81,API 确认 mergeable: true(当前 blocked 仅为 CI 在跑 + 等待人工合并)。

按八问汇报:

  1. 是什么问题:系统转发上游冲突(PR 分支与目标分支不可干净合并),需要 rebase 解冲突。
  2. 什么原因导致的:master 侧新合入的 [perf] large active sessions (50-60MB payloads, 23k msgs) serialize the main thread: 1276ms avg local processing per turn + full 57MB snapshot rewrite for +270B deltas #3049(stale-guard 所有权快路径,persist.ts 的 noteOwnCommit)与本 PR 恰好改在同一行——本 PR 把 shadow.record(record, …) 的载荷包成一次性携带 decompositionLog 的对象,而 master 在同位置追加了 this.noteOwnCommit(session.id, record)。这是全 rebase 唯一一处文本冲突(4 个提交中其余全部干净应用,fix(server): redacted_thinking arms the #651 reasoning-drop gate #3196 只动 src/server.ts,与本 PR 文件零重叠)。
  3. 影响范围与严重程度:仅 src/persist.ts 一处保存闭包;若不按并集解,会丢一侧行为——丢 PR 侧则外部转换导入的一次性索引注入失效(After an interleaved metadata refresh, the entire history of the same session is resent in a different form, and already-collapsed content fails to re-anchor. | interleaved 元数据刷新后,同一会话整段历史换形态重发,已折叠内容 re-anchor 认不回来 #3301 核心机制),丢 master 侧则 [perf] large active sessions (50-60MB payloads, 23k msgs) serialize the main thread: 1276ms avg local processing per turn + full 57MB snapshot rewrite for +270B deltas #3049 快路径的所有权令牌缺失。已按两侧意图并集保留,无外部可见行为变化。
  4. 怎么修复的:并集解法——shadow.record 仍接收包装后的对象(带一次性 decompositionLog),其后保留 master 的 noteOwnCommit(session.id, record);令牌从裸 record 取计数器,与包装对象完全相同(包装只加字段不改计数),[perf] large active sessions (50-60MB payloads, 23k msgs) serialize the main thread: 1276ms avg local processing per turn + full 57MB snapshot rewrite for +270B deltas #3049「令牌计数 === 索引行计数」不变量成立。无其他语义改动。
  5. 是否有回归问题:rebase 后本地验证:typecheck 通过;定向测试 25/25 全绿(tests/issue3301-shape-flip-reanchor.test.ts 全套 + tests/persist-guard-ownership.test.ts [perf] large active sessions (50-60MB payloads, 23k msgs) serialize the main thread: 1276ms avg local processing per turn + full 57MB snapshot rewrite for +270B deltas #3049 快路径 + tests/persist-tail.test.ts 同区域尾段逻辑 + tests/multi-instance-persist.test.ts stale-guard);无残留冲突标记;评审跟进提交的收窄状态完整保留(extractThinkingMerge 等猜测半边确认不在树中)。高危模式逐项过:未改默认值/阈值/时序/输出格式,fail-fast 语义未动。全量回归以 push 后 CI 为准。
  6. 是否破坏缓存:不涉及——本次仅冲突解决,不触碰压缩/缓存路径;[perf] large active sessions (50-60MB payloads, 23k msgs) serialize the main thread: 1276ms avg local processing per turn + full 57MB snapshot rewrite for +270B deltas #3049 快路径行为按其原设计保持。
  7. 是否改了设计方向:不涉及,维持 PR 原有范围(确定性恢复半边:统一索引锚点重建 + 导入入口 + messagesForIds 只读扩展)。
  8. 是否引入了新的配置:不涉及。

已知背景(非本次引入):CI 上 shard 2 的红是 master 既有问题,待 #3314 + #3317 合入后转绿;Windows shard 3 为运行时时序抖动家族(#3279 同族)。收工判定:rebase 完成、冲突已解、验证通过,PR 可合并性已恢复,等 CI 绿 + owner 合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

已并入合并列车 #4572(master 合并,merge commit 保留原作者署名)。本 PR 关单收尾;回滚点为 #4572 单提交 revert。

@ranxianglei ranxianglei changed the title fix: re-anchor folded history across host wire-shape flips (#3301) [PR] fix: re-anchor folded history across host wire-shape flips (#3301) Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant