Skip to content

fix(#1853): fork-adoption 收养管线补齐 responses/google 两线(resume 继承 refs/blocks) - #1855

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-01_issue1853-adoption-wires
Oct 1, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-01_issue1853-adoption-wires

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #1853(继 #1834 / PR #1850 之后的残留项)。

问题

src/fork-adoption.ts 的 id 解析管线 incomingCoreMessages 只支持 SUPPORTED={openai, anthropic}:responses(codex /v1/responses)和 google(gemini native)直接返回 null → 整条收养/继承管线被跳过(包括 #1850 已默认化的 resume 块收养)。这两类客户端换 id resume 时只记 lineage,refs 和 blocks 都不继承 —— 折叠原文全部回到线上、请求膨胀、重新折叠一遍。

链路追踪(findResumeParent)、identified 链记录、#1850 的默认块收养本来就都是协议无关的;这是唯一的缺口。

修复

SUPPORTED 扩到四线,新分支 按 prepare 的顺序*镜像各线的投影前变换,再用 prepare 用的同一个转换器收尾:

  • responses:replaceBiliCompactionItems → normalizeResponsesMessageItems → sanitizeResponsesInputIds → dropWhitespaceResponsesMessages → stripAcpPanelResponsesInput → stripAcpStatusMarkers → stripEmbeddedChainCarriers → responsesToCoreWithToolImages
  • google:stripEmbeddedChainCarriers → googleToCore

与 processTurn 输入的 id 对齐是全部意义所在:本 pass 漏掉的 id 会让父会话少一个 ref;多算出的 id 匹配不到任何东西(无害超集)。插件模式 mid-history sys/developer 原位标记(__bili_inplace_sysdev)刻意不复刻 —— 标记与否,这些项都不产生 core 消息,id 集合相同。

测试

tests/resume-adoption-wires.test.ts(新):

  1. responses 线(经 responses⇄chat bridge,与 e2e-grow-compress 同路):父会话 8 轮触发折叠后换新 id resume 全量历史 → 断言完整 Claude 上 resume 导致消息错乱 #1486 契约:父 refs 全保留(含折叠块外)+ blocks 收养 + lineage + 父会话不动 + 新消息编号高于父空间
  2. responses 线 + resumeInheritance 关闭:无 lineage、无收养(旧行为不变)
  3. google 线(gemini native 直连 mock):同 1 的完整契约

牙型验证:把 SUPPORTED 临时改回 {openai, anthropic},两条继承测试变红、关闭变体保持绿。

验证

  • npm run typecheck ✓
  • 定向:resume-ref-inheritance + fork-adoption + prefix-affinity + e2e-grow-compress 32/32 ✓
  • 新文件 3/3 ✓
  • 全量(clean env):3539 tests / 3520 pass / 0 fail / 19 skipped

影响

fork-adoption's id pass (incomingCoreMessages) only supported
{openai, anthropic}: responses (codex /v1/responses) and google
(gemini native) returned null, so identified resume-forks on those
wires inherited nothing but lineage — every folded original came
back on the wire and had to re-fold (#1834's residual population).

Extend SUPPORTED to all four wires. The new branches mirror each
wire's prepare* pre-projection mutations IN ORDER before converting
with the same converters prepare uses:

- responses: replaceBiliCompactionItems → normalizeResponsesMessageItems
  → sanitizeResponsesInputIds → dropWhitespaceResponsesMessages →
  stripAcpPanelResponsesInput → stripAcpStatusMarkers →
  stripEmbeddedChainCarriers → responsesToCoreWithToolImages
- google: stripEmbeddedChainCarriers → googleToCore

Id parity with processTurn's input is the whole point: an id this
pass misses drops a parent ref from the inheritance; an id it
invents matches nothing (harmless superset). The plugin-mode
mid-history sys/developer in-place marking (__bili_inplace_sysdev)
is deliberately not replicated — marked or hoisted, those items
contribute no core message either way.

Chain tracking, findResumeParent and the #1850 default block
adoption were already protocol-agnostic; this was the only gap.

tests/resume-adoption-wires.test.ts: responses resume through the
responses⇄chat bridge and a direct gemini-native scenario, both
asserting the full #1486 contract (refs preserved incl outside the
folded block, blocks adopted, lineage, parent untouched, fresh refs
above the parent's space) + the disabled-gate variant. Both
inheritance tests fail on the old SUPPORTED set (teeth verified).
@ranxianglei

Copy link
Copy Markdown
Owner Author

链接到跟踪 issue:#1853(PR 关闭时自动关联 via Fixes)。

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-01_issue1853-adoption-wires (da36cfb)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1840-pr.1855.eaa3e55

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-pr1855.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

[bot] 🏷 收到。这是 [PR] 类唤醒——先按 review 流程走:核对原 issue #1853 的方向、拉取分支核对代码与 CI 状态,再给结构化结论。稍等。

@ranxianglei ranxianglei added the p1 label Oct 1, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成(#1853 残留项,继 #1834/#1850)。结论:可合并。

结构化七问

1. 是什么问题:fork-adoption.ts 的 id 解析管线只对 openai/anthropic 两线工作,responses(codex /v1/responses)和 google(gemini native)直接返回 null → 换 id resume 时整条继承管线被跳过,#1850 默认化的块收养在这两线也不生效。

2. 什么原因导致的:根因在 v1 实现时的协议覆盖缺口——SUPPORTED 集合只装了两线。链路其余部分(findResumeParent 字节匹配、identified 链记录、#1850 的默认块收养)本来就协议无关,唯一断点就是这个 id pass:没有它,父会话的 raw-id 集合算不出来,refs/blocks 无从继承,只剩 lineage。

3. 怎么修复的:扩 SUPPORTED 到四线,新分支按 prepare* 的顺序镜像投影前变换、用同一个转换器收尾——疏(补上缺失的管线镜像),不是堵。我逐行核对了管线一致性:

  • responses 分支顺序与 prepareResponses(src/server.ts:4061→4088→4092→4094→4099→4103→4107)完全一致;收尾转换器也是同一个——server.ts:50 把 responsesToCoreWithToolImages 以别名 responsesToCore 导入,:4157 的「responsesToCore」实际就是 WithToolImages 版,与收养分支用的函数是同一物。
  • google 分支与 prepareGoogle(src/server.ts:3868 stripEmbeddedChainCarriers → :3874 googleToCore)一致。
  • __bili_inplace_sysdev 刻意不复刻是对的:标记与否,mid-history sys/dev 项都不产生 core 消息(标记→coreId-less slot,不标记→hoist 进 systemParts),id 集合相同,不影响继承正确性。
  • 调用侧核对:WireProtocol 恰为四线(src/util.ts:59);affinityMessageList()(src/server.ts:2015-2024)对 responses input / google contents / 其他 messages 三种形状都取原始数组,findResumeParent 协议无关的前提成立。
  • 所有变换先 structuredClone 再改原,请求体本身不被这个只读 id pass 触碰。

4. 是否有回归问题:无。openai/anthropic 分支逐行未动(diff 核实);新代码只在原本返回 null 的路径上产生值。高危模式逐项过:无语义漂移、无 fail-fast 变吞错、无阈值/时序/输出格式变化、无缓存键变化。行为变更仅 PR 披露的两处:①responses/google 换 id resume 从「只记 lineage」→「完整继承 refs/blocks/lineage」(本 PR 目的);②匿名 fork(forkAdoption 门)在四线同样可被测量/收养(仍受既有配置门控,默认不变)。

5. 是否破坏缓存:不涉及。本模块只读会话状态做种子复制,不改任何外发字节、前缀锚点或重试策略;种子发生在 processTurn 分配 ref 之前,符合 #1486 既有契约(ref 编号高于父空间,id 永不复用)。

6. 是否改了设计方向:不涉及。沿用 #629/#1486/#1834 的 copy-on-fork/copy-on-resume 机制,只是把 id pass 的协议覆盖补齐到声明的四线全量。

7. 是否引入了新的配置:不涉及。无新 env/config/flag;resumeInheritance 与 forkAdoption 门控语义不变。

本地定向验证(PR head da36cfb,另在与当前 master bcef839 的本地合并分支上复跑)

  • npm run typecheck ✓(两处均干净)
  • 定向套件:resume-adoption-wires(新,3)+ resume-ref-inheritance + fork-adoption + prefix-affinity = 34/34;加 e2e-grow-compress 后 35/35(head 与 master 合并分支均过)
  • 牙型复核:把 SUPPORTED 临时改回 {openai, anthropic} 重跑新文件 → 两条继承测试变红、关闭变体保持绿,与 PR 声称完全一致(已还原)
  • CI(head sha):test ubuntu/windows ×22/×24、version-guard、build-artifact、hermetic registry e2e、四条 real-client lane 全绿
  • master 漂移:base 3b2fa2c → 当前 bcef839 之间只有 AGENTS.md(docs(AGENTS): minor problems are fixed directly (owner rule) #1860),无代码竞争,实际已对齐

一个范围说明(google 线,#866 核查结论)

google 线的 clientProvided ⟺ 客户端发了会话头(src/server.ts:1928-1937:gemini native 无 prompt_cache_key 可提升,身份靠 convHeader 或内容指纹)。所以本 PR 的 google 收益落在「带头换 id resume」的 gemini 系客户端上;裸 Gemini CLI(不发任何会话头)仍走匿名内容亲和,不受本 PR 影响——这是身份设计的既有边界(#286),不是本 PR 的缺口。PR 描述里「gemini 客户端带头换 id resume」的措辞与此一致,无需改动。

判定

方向对(根因级修复)、管线一致性逐行核实通过、测试有牙且钉住旧行为、CI 全绿、diff 收敛(2 文件 +504/-10 全部相关)。建议合并。注:此变更扩展了 ref 继承语义到两条新线,按 §7.4 属人工合并范畴,合并操作留给你。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到。已核对:PR 正文首行即 Fixes #1853,合并后会自动关联关闭跟踪 issue。Review 结论见上条(可合并),无其他待办。

@ranxianglei
ranxianglei merged commit c411b5e into master Oct 1, 2026
12 checks passed
@ranxianglei
ranxianglei deleted the 2026-10-01_issue1853-adoption-wires branch October 15, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fork-adoption SUPPORTED 只有 {openai, anthropic}:responses(codex)/google 线换 id resume 仍不继承 refs/blocks(#1834 残留)

1 participant