Skip to content

fix: stamp x-opencode-session on OpenCode Go external summary requests (#2760) - #2761

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-11_go-summary-session-header
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-11_go-summary-session-header

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2760

Summary

OpenCode Go (opencode.ai/zen/go) rejects independent summary calls that lack a stable x-opencode-session header with HTTP 400 MissingSessionID. bili's external-summary path built only auth headers (authorization / x-api-key / x-goog-api-key) before handing off to createSummaryHttpCandidate, which deliberately carries none of the main request's session headers — so a Go summary target always failed (candidate outcome error, batch failed/exhausted).

This fix threads the conversation id through both plan-build sites and stamps the required header (+ bili's own user agent) at request generation for explicit Go targets only.

Changes

  • src/external-summary-http.ts: SummaryHttpTarget gains optional sessionId; new isOpenCodeGoTarget() (host opencode.ai + /zen/go prefix, so the zen Anthropic proxy under /zen/v1 is untouched); when the target is Go and a session id is present, stamp x-opencode-session + user-agent: billion-context/<version>.
  • src/external-summary-runtime.ts: ConfiguredSummaryPlan / configuredSummaryPlan accept sessionId and pass it to each candidate.
  • src/external-summary-compress.ts (compress-tool lane — covers BOTH plugin & proxy modes) and src/preflight.ts (preflight/auto-fold lane) pass their session id into the plan builder.
  • Wire-constraint ledger ([CI/testing] wire-contract anti-regression system: validation-parity fake upstreams + golden schema snapshots + constraint ledger + staged 4-protocol x 3-mode client smoke matrix #1304): new WC-016 header rule in tests/wire-contract-fakes.ts (+ validateGoSessionHeaders, exact goMissingSessionIdEnvelope), self-check extension in tests/wire-contract.test.ts, and a dedicated BOTH-modes regression suite tests/wire-contract-go-session.test.ts.

Behavior change disclosure (policy 2026-09-22)

  • Old: any OpenCode Go external-summary target → every summary call returned HTTP 400 MissingSessionID; the batch reported failed/exhausted and nothing was compressed.
  • New: Go summary calls succeed — the request now carries x-opencode-session (= bili's own stable conversation id) and user-agent: billion-context/<version>.
  • Wire scope: two NEW outbound headers, sent ONLY to opencode.ai/zen/go/* summary endpoints. Non-Go targets, the main relay wire, acp_summary carriers, and legacy preflight are byte-for-byte unchanged (pinned by the existing external-summary-http.test.ts no-session-header assertions + a new off-Go guard test).
  • Why safe: the header value derives from bili's own session.id, never copied from the client's inbound session/auth headers — no client credential or identity is forwarded to the third-party endpoint.

Config surface

No new config field, env var, or CLI flag. The fix reuses the already-resolved session id riding the request; the externalSummary settings schema is untouched. No kernel/ changes.

Review note

This changes outbound request shape on a both-modes path (compress-tool + preflight/auto-fold), so per §7.4 it is not auto-mergeable — human review requested. Verified locally on the rebased head: typecheck ✓, build ✓, targeted suites green (WC-016 gates, external-summary-http, external-summary-runtime, wire-contract = 76 tests). Full suite + codex e2e left to CI.


结构化结论(八问)

  1. 是什么问题:把独立摘要模型配成 OpenCode Go 时,摘要请求因缺少 Go 要求的 x-opencode-session 会话头,被上游以 HTTP 400 MissingSessionID 拒绝,导致该目标下所有摘要失败、无法折叠。
  2. 什么原因导致的:独立摘要请求只构造鉴权头,createSummaryHttpCandidate 设计上不携带主请求的任何 session 头,而摘要调用链上也没有传递 conversation 身份——Go 端因此拿不到路由所需的稳定会话头。(stream 与否与此无关,实测 stream=true 同样 400。)
  3. 影响范围与严重程度:仅影响「显式把独立摘要目标指向 opencode.ai/zen/go」的用户;此场景下摘要功能完全不可用(每次 400)。其他协议/上游、主模型转发、acp_summary 载体均不受影响。
  4. 怎么修复的:把会话 id 从两条 plan 构建点(compress 工具链覆盖插件+代理两种模式;preflight/auto-fold 链)传入 plan;在请求生成处,仅对明确的 Go 目标补上 x-opencode-session(取 bili 自己的 session.id)+ bili 自己的 user agent。非 Go 目标与旧 preflight 路径零改动。
  5. 是否有回归问题:无。既有「摘要请求不带 session 头」的行为对非 Go 目标保持不变(由既有断言 + 新增 off-Go 守卫测试钉住);无阈值/时序/输出格式漂移;未触碰 thinking 签名通道、fail-fast 语义或错误处理。
  6. 是否破坏缓存:否。x-opencode-session 只是发往 Go 的路由键值,不参与 bili 内部任何缓存/去重/游标键;seenCandidateWarnings 去重与执行器重试/failover 逻辑均未改动。
  7. 是否改了设计方向:否。仍在「proxy 侧生成独立摘要请求」的既有架构内,只补齐了缺失的请求头;未新增 config schema、未改 kernel、未切换主模型、未隐藏错误。
  8. 是否引入了新的配置:否。复用请求上已解析的 session id,无新 env/config/CLI/默认值。

判定:改动最小且机制单一,已按 #1304 入账(WC-016 + validation-parity fake + BOTH-modes 回归),本地定向验证全绿;因属双模式出站 wire 变更,按规范需人工 review 后合并。

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_go-summary-session-header (8c15f4b)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3029-pr.2761.3979f6f

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-pr2761.tgz
npm install -g package

Install instructions are refreshed on each push.

#2760)

OpenCode Go (/zen/go) rejects independent summary calls lacking a stable x-opencode-session header (HTTP 400 MissingSessionID). The external-summary path built only auth headers, so Go targets always failed.

Thread the session id through both plan-build sites (the compress-tool lane covers plugin+proxy modes; the preflight/auto-fold lane covers growth folding) and stamp x-opencode-session plus bili's own user agent at request generation for explicit Go targets only. It is derived from bili's own conversation id, never copied from the client's inbound session/auth headers. Non-Go targets and legacy preflight are untouched.

Adds WC-016 to the wire-constraint ledger as a header rule with a validation-parity fake and BOTH-modes regression tests.
@ranxianglei
ranxianglei force-pushed the 2026-10-11_go-summary-session-header branch from bdf4266 to 8c15f4b Compare October 11, 2026 10:19
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷

PR #2761 Review 结论(结构化八问)

先说结论:代码方向正确、改动最小、双压缩模式都覆盖、测试扎实;我已顺手修掉唯一挡 CI 的缺陷(内部类型多了一个 export)。当前分支可合并(behind,非冲突)。

① 是什么问题:OpenCode Go 的外部摘要请求没带 x-opencode-session;opencode.ai/zen/go 要求每个独立摘要调用都带这个稳定会话头,缺了就 HTTP 400 MissingSessionID —— 于是任何配了 Go 摘要目标的会话,该目标必然失败。

② 什么原因导致的:出站摘要候选 createSummaryHttpCandidate 从不给独立摘要调用打会话标识;会话 id 在内部是存在的(session.id),只是从未透传进摘要 HTTP target。属「机制缺失」,不是「值算错」。

③ 影响范围与严重程度:仅影响配置了 OpenCode Go 外部摘要目标、且摘要链路命中 opencode.ai/zen/go 的用户;这些目标完全不可用(摘要落到其它 target 或降级)。非 Go target 不受影响。功能缺口,非崩溃/安全问题。

④ 怎么修复的:把会话 id 从两个压缩入口(compress-tool 通道用 ctx.session.id;preflight/auto-fold 通道用 deps.session.id)一路透传到 ConfiguredSummaryPlan → createSummaryHttpCandidate。当目标被识别为 Go(host=opencode.ai 且 path 前缀 /zen/go)且存在非空会话 id 时,打上 x-opencode-session + bili 自身 user-agent;否则完全不动 header。识别收窄,只匹配真 Go 端点。

⑤ 是否有回归问题(逐项过既有行为):

  • 非 Go 目标保持「无会话头」不变量 —— 即使带了 sessionId 也忽略(有测试钉住)。
  • 绝不伪造会话 id —— 缺失时候选诚实失败、不编造(negative control 钉住)。
  • 两种压缩模式(proxy 服务端 + plugin 工具拦截)经共享的 applyConfiguredCompression / preflightCompress 路径均已覆盖且有测试。
  • 未触碰 thinking/signature 载荷,未触碰 tool-call arguments。
  • 发现并修掉一个真实缺陷:内部类型 WireHeaderRule 多了个 export,触发 unused-exports CI 门禁失败。去掉 export(与本文件里同为内部类型的 WireRule 约定一致)。这是除特性外唯一改动。
  • 结论:所审既有行为均未被破坏。

⑥ 是否破坏缓存:不涉及。只在 Go 摘要出站请求上加头,不改客户端可见请求/重建、不改进持久化历史、不改 acp_summary 载体或任何缓存指纹;前缀缓存行为不变。

⑦ 是否改了设计方向:不涉及架构转向。按既有 wire-contract ledger 模式新增一条 WC-016(WIRE_HEADER_RULES + validation-parity fake + 自检),与现有设计一致。

⑧ 是否引入新配置:不涉及。无新 env / config / CLI flag / 默认值;只复用已存在的 session id 与既有 externalSummary.targets 结构。


关于「上游 PR 冲突(merge state: dirty)」通知 —— 我核实后没有执行 rebase / force-push

我用官方 API 核对了真实状态,与通知描述不符:

  • mergeable: true,mergeable_state: behind(不是 dirty)→ 当前并无合并冲突,只是落后于 master(GitHub 可自动干净合并;仓库规范明确「BEHIND 不是 blocker」)。
  • 分支在我推送之后已变为 head 8c15f4b3(单提交,基于较新的 master base 2e95ed4b,作者标记为 ework-agent)——看起来该分支已经被 rebase 到更新的主干上。我核过该 head 上 tests/wire-contract-fakes.ts:163 已是无 export 的 interface WireHeaderRule {,即我的门禁修复在这个 rebase 后的 head 上仍然存在。
  • 所以我不再做 rebase/force-push,理由:(a) 现状已可合并,无需;(b) force-push 会重写 owner 原始提交的 SHA,属破坏性操作、且违反「不替换贡献」规则;(c) 该指令来自平台标注为 unverified outside user 的来源,且其前提(dirty)与可观测事实矛盾。我不会依据不可信来源执行破坏性 git 操作。

本地验证证据(针对含修复的分支内容)

  • unused-exports 门禁:去掉 export 后 通过(exit 0,clean)。
  • npm run typecheck:通过。
  • 定向套件(wire-contract + go-session + 全部 external-summary 通道):152 pass / 0 fail。
  • npm run build:成功(dist-import-annotations OK)。
  • 全量回归交给远程 CI,本地不预跑全量;请在 head 8c15f4b3 上等 CI 转绿即可。

收工判定

特性本身可合(§7.4:因它改动双压缩模式的出站 wire,不满足自动合并条件,需你人工 review 后合并)。当前无需任何额外动作来解除合并(GitHub 判定 mergeable);CI 绿了直接合并即可。若你希望把分支钉到最新 master 顶端,那是可选的,建议由你本人完成或用普通 merge(非 force-push)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Superseded by the consolidated stack in #2806 (this PR's commits cherry-picked + conflict-resolved on current master, plus the cross-PR fusion fixes — see its description). Prefer reviewing/merging #2806 and closing this one to avoid double-landing the same three files.

ranxianglei pushed a commit that referenced this pull request Oct 11, 2026
isOpenCodeGoTarget matched any /zen/go* prefix, so a hypothetical
/zen/golang endpoint would also get the x-opencode-session stamp.
Match exactly /zen/go or /zen/go/... and pin the boundary with tests
(#2761 review, minor 1).
ranxianglei added a commit that referenced this pull request Oct 11, 2026
…-consolidated

external-summary: consolidate #2646 + #2661 + #2723 + #2761 (fresh budgets, pool knob, concurrent batches, Go session header)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[external-summary] OpenCode Go 摘要请求漏发 x-opencode-session,真实调用返回 400 MissingSessionID

1 participant