Skip to content

[PR] opencode V2: core-align the msgId header — skip the hoisted leading system run (#6525/#6539) - #6553

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-11-13_opencode-v2-lead-run-skip
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-11-13_opencode-v2-lead-run-skip

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

这是啥

opencode V2 一直在发 x-bili-msg-ids 头,但在 openai 协议上从来没真正 pin 住过宿主号——服务端每次都把 pin 拒了(安全降级成按内容摘要)。后果:opencode V2 的会话拿不到稳定宿主身份,fork/继承那条线(opencode V2)一直走不了 msgid 轨。

根本原因

  • 服务端 pin 校验的是 post-hoist core count:prepare-openai.ts 用 validateMsgIds(ids, msgs.length),其中 msgs = openaiToCore(parsed)——内核会把开头的连续 system/developer 段 hoist 出折叠空间。所以 openai 线上 msgs.length = 线消息数 − 开头 system 段长度。
  • 但 opencode V2 的 x-bili-msg-ids 头是按每一条 wire message 发的(opencodeV2MsgIdList 遍历全部,含开头 system)。于是头里的号数永远 = 线消息数 > post-hoist core 数 → validateMsgIds 计数不等 → pin 被拒。
  • anthropic 线没这问题:system 是单独字段、从不进 messages,所以头数本来就等于 core 数(anthropic 线一直是好的)。

一句话:客户端发的号是按「线消息」算的,服务端校验是按「hoist 后 core」算的,openai 线两者差一个开头 system 段,永远对不齐。

怎么修的

src/agent/opencode-v2-msgids.ts 的 opencodeV2MsgIdList 加一处 core-align:收集号之前,先跳过开头的连续 system/developer 段(和内核 openaiToCore 的 hoist 规则对齐)。这样头数 = post-hoist core 数,pin 就能通过。

  • openai 线:跳过开头 system 段 → 对齐 → pin 点亮。
  • anthropic 线:system 不在 messages 里 → 跳过是 no-op → 行为不变(本来就是对的)。
  • 会话中途的 system 消息不是开头段 → 保留它的号(它是一条真 core)。
  • 纯开头 system 段(没有别的内容)→ 无号可 pin,返回 undefined,不发空头。
  • poison(某条缺号/外形不对)整轮降级契约不变。

验证

  • typecheck 干净。
  • tests/opencode-v2-msgids.test.ts 10/10(原 5 + 新 5 条 core-align 回归:开头段跳过 / anthropic no-op / 中途 system 保留 / 纯开头段→不发 / 开头段后 poison 仍杀)。
  • tests/msgid-pin.test.ts 9/9、tests/opencode-fork-adopt.test.ts 2/2。
  • tests/opencode-v2.test.ts 31/34,3 个失败在 baseline(不含本改动)上同样失败 = 既有环境问题,非本 PR 引入。

范围

…6525/#6539)

The server pins host ids against the POST-HOIST core count (prepare-openai
validates ids.length against openaiToCore(parsed).length, which hoists the
contiguous leading system/developer run out of the fold space). opencode V2's
x-bili-msg-ids header was stamped per WIRE message, INCLUDING the leading
system, so its count always exceeded the core count on the openai wire and the
pin was rejected (a safe content-derived degrade — but opencode V2 never
actually pinned on the openai wire).

Core-align the V2 extractor: skip the contiguous leading system/developer run
before collecting ids so the header count equals the post-hoist core count.
No-op on the anthropic wire (system is a separate field, never in messages);
mid-conversation system messages keep their ids; a leading-system-only turn
degrades (no empty header). Whole-turn poison contract unchanged.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-13_opencode-v2-lead-run-skip (a423fb6)

Latest build — install this exact version

npm install -g billion-context@0.0.9596-pr.6553.79a515f

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
a423fb6 billion-context@0.0.9596-pr.6553.79a515f build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

已收编进统一 PR #6564(提案 #6539 一个 PR 落地,用户要求不拆分)。本 PR 关闭;合并留 owner。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant