Skip to content

[PR] fix: fork 会话从父会话继承完整账本位置,克隆不再被跳过(#5043) - #5045

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-28_fix-fork-ledger-publication
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-28_fix-fork-ledger-publication

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

(ai: anthropic/claude-opus-4-8)

贡献署名:本 PR 的修复提交为 @kuviki 原创(见其 issue #5043 与 PR #5044),此处原样 cherry-pick(commit message 含 Co-authored-by 与来源引用)。#5044 面向 #4982 release 分支,受 CI 触发规则限制(该 base 上 test-matrix 全部跳过、version-guard 结构性红);经 maintainer 决定,以本 PR 承载同一补丁在 master 上获得完整的远端全量矩阵裁决。两者内容逐字节相同:谁先合入,另一个即失去意义可关闭。

现象与后果

plugin fork(分叉会话)功能下,fork 出的子会话的"消息账本位置"来自父会话,但统一存储里子会话的行却被从第 0 位重新排起——只要父会话存在已退役的历史位(tombstone,本次发版引入的功能),两边的位置就会错位:存储把子会话误判成"已经有自己的行",直接跳过从父会话克隆原始行,导致子会话继承错误的位置映射,最坏情况覆盖压制仍在生效的消息。发布前回归审查判定 🔴 MAJOR:#4982 审查评论。

根本原因

fork 处理器先把子的快照落库(publishForkSession → 同步 flush,子的行按 0..N 排好),之后才执行"保持父位置的行克隆";而克隆的幂等守卫看到子已有行就整体跳过。克隆排在写入之后 = 生产路径上永远克隆不到东西(测试恰好锁的是"先克隆后写入"的非生产顺序,所以此前一直绿)。次生隐患:血缘字段(parent_session_id/fork_point_seq)的 upsert 无条件覆盖,重放/崩溃补写会改写已确立的分叉对。

修法(与 #5044 相同)

  1. 克隆父会话行 + 子会话首次写入合并进同一后端事务(sqlite/mysql 双后端),在任何其他持久化步骤之前完成;
  2. 血缘列改为"首个确立的分叉对不可变"(COALESCE/CASE 语义,两后端一致),冲突配对与既有行的子会话严格报错;
  3. 崩溃恢复路径:fork 响应已发出但 envelope 未落盘时,重试从已提交的 DB receipt 修复并返回原回执,不产生孤儿子会话;
  4. 回归测试覆盖:HTTP 端到端(稀疏账本 [0,3,4] 完整传入子会话)、崩溃重启同 key 重放、事务失败绝不发布、mysql 连接契约、媒体引用计数不变量。

验证证据

  • 基线 RED:本 PR 的 HTTP 回归测试放到未改动的 master(b0b0e66f)上失败,失败形态正是上述 MAJOR(父 [0,3,4] → 子密排 [0,1,2]);
  • 本头 GREEN:plugin-fork 54、fork-lineage-conflict 18、issue4910 1、seq-ledger-pr3 4、issue4730-fork-live-seq 2、storage-backend-contract 7+1skip(真实 MySQL 门)、bounded-storage 11、storage-json-writer-off 3、fork-clone-media-refcount 3、proxy-persist 23 —— 全过;typecheck 干净,build 通过;
  • 已知环境噪音:tests/issue3157-persist-durability.test.ts(隔离测试)在未改动的 master 上同样失败,与本补丁无关(Node 版本差异),单独跟进,不作为本 PR 证据。

不涉及版本号、配置面、wire 协议改动;纯 fix: + 回归测试。

Fixes #5043

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-28_fix-fork-ledger-publication (43c0a61)

Latest build — install this exact version

npm install -g billion-context@0.0.6650-pr.5045.af4b4af

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

Recent builds (commit → version)

commit version build
43c0a61 billion-context@0.0.6650-pr.5045.af4b4af build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: anthropic/claude-opus-4-8)

Closed as superseded: per the owner, the canonical vehicle for this fix is #5044 - kuviki's original patch (authorship and commit preserved, with a Co-Authored-By credit added), now rebased onto current master (head 4bf931c, base retargeted to master) so the full CI matrix runs directly on his PR.

The patch in this mirror was byte-for-byte identical to that work (clean cherry-pick, zero diff). No content is lost by closing it - the verification evidence (baseline RED repro + full storage-lane suite results) stands via the comment on #5044.

@ranxianglei ranxianglei changed the title fix: fork 会话从父会话继承完整账本位置,克隆不再被跳过(#5043) [PR] fix: fork 会话从父会话继承完整账本位置,克隆不再被跳过(#5043) Oct 28, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

状态汇报(进程因 35 分钟无输出被强制重启,现已恢复):

无待办。 本线程自关闭后没有任何新的人类评论或新的 CI 状态——floor 3 起全部是系统级进程状态消息,不是新工作项。

状态核实(git 实测,非转述):

此前本线程的连续重启均为进程层面挂起(线程内无新输入触发任何实际工作),不是修复本身出现了新问题。无需进一步动作,此条仅作恢复后的收尾确认。

@ranxianglei ranxianglei added bug Something isn't working p1 scope/storage labels Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p1 scope/storage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] plugin fork 发布顺序导致 ledger 克隆被跳过,稀疏 seq 与持久化血缘不一致

2 participants