Skip to content

[PR] Prefer native OpenCode session IDs over shared parent cache affinity - #2796

Closed
mariopasquali wants to merge 1 commit into
ranxianglei:masterfrom
mariopasquali:2026-10-11_native-session-identity
Closed

mariopasquali wants to merge 1 commit into
ranxianglei:masterfrom
mariopasquali:2026-10-11_native-session-identity

Conversation

@mariopasquali

@mariopasquali mariopasquali commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

OpenCode child requests can carry their own x-opencode-session-id alongside the parent's cache-affinity headers. Ignoring the native header makes the parent and siblings share mutable ACP state, even though they are separate conversations.

Prefer the native session header before the shared affinity headers. A marked plugin conversation retains precedence, blank native IDs fall back to existing signals, and the parent header alone remains insufficient to identify a child. Upstream cache headers and body cache keys are preserved.

Fixes #2779.

Real native OpenCode end-to-end validation: 4/4 passed, including intercepted traffic, tool registration, status execution and actual compression. The external Windows runner allows the existing persistence debounce to flush before process termination; tracked assertions are unchanged.

Validation: nine added regressions failed on the pristine source and pass with the change. All 42 identity tests pass, including concurrent siblings across Responses, Anthropic and Chat Completions in proxy and plugin modes. Typecheck and build pass. The patched full Windows suite has 6,293 passes, 24 skips and five failures also present in the pristine baseline: four SQLite cleanup EPERM failures and session-name clearing. The baseline's separate timing failure did not recur. No kernel, configuration, version or tool-argument changes. This remains a draft for human review of the identity boundary.

@ranxianglei

Copy link
Copy Markdown
Owner

(ai: zhipuai-lb/glm-5.3)

陈旧票清理(第三批动作①):目标 issue #2779 已关。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。

感谢 @mariopasquali 的贡献与排查——这条修复路径已被其他方式覆盖;欢迎认领其他 open issue。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重结论:重复 —— 与已合并的 PR #2792 重复(同症状、同机制、同根因)。独立复核完毕,清理判断成立,无需 reopen。

验证证据(全部对照 master 源码与测试套件核过):

  1. Native OpenCode children share mutable ACP state when parent affinity wins over x-opencode-session-id #2779 的修复已经由 PR fix: key OpenCode 2.x child sessions by their own x-opencode-session-id (#2779) #2792 合入 master(2026-10-13 合并,commit 5f70fc7c8,「key OpenCode 2.x child sessions by their own x-opencode-session-id」)。
  2. 本 PR 与 fix: key OpenCode 2.x child sessions by their own x-opencode-session-id (#2779) #2792 修法完全一致:把原生头 x-opencode-session-id 插入身份优先级表(位于亲和头之前),不改写任何上游头部或 cache key。
  3. 本 PR 的 9 个回归用例逐一比对,均已在 master 套件中覆盖,且部分断言更强(e2e 额外断言上游四个缓存亲和头逐字节原样透传):
    • 原生头优先于父亲和键 → master 单测断言 + e2e 三协议(chat/responses/anthropic)父+双兄弟交错隔离测试;
    • 空原生头回落亲和键 → master「blank x-opencode-session-id falls back」e2e;
    • plugin 会话保持最高优先 → master「plugin-stamped identity still outranks」e2e + claude/mavis 更高优先级头的单测。
      没有值得 cherry-pick 的独特场景。
  4. 本 PR 在 GitHub 上已是 closed(unmerged)状态(2026-10-24T13:35Z),与上面的清理动作一致。

结构化八问

  1. 是什么问题:Native OpenCode 2.x 的 subagent/fork 子请求自带自己的会话 id,但 bili 只认继承自父的亲和头,父与兄弟被当成同一会话、共享可变压缩状态。
  2. 什么原因导致的:OpenCode 2.x 把原生 id 移进新头 x-opencode-session-id,旧三头改承载缓存路由亲和键(子请求有意共享父的上游缓存);bili 的身份优先级表早于 2.x、未收录新头,于是回落到读亲和键。
  3. 影响范围与严重程度:仅 proxy 模式 + OpenCode 2.x + 含 subagent/fork 的会话;父与兄弟压缩状态互相污染(baseline/snapshot 归属错乱),特定条件下的数据级污染。已由 fix: key OpenCode 2.x child sessions by their own x-opencode-session-id (#2779) #2792 修复合入 master。
  4. 怎么修复的:把原生头插入身份链既有信任级(x-mavis-session-id 与 x-session-affinity 之间),空值沿用既有 fall-through;不动上游头与 cache key。已在 master。
  5. 是否有回归问题:不涉及——本 PR 不合并;回归审查在 fix: key OpenCode 2.x child sessions by their own x-opencode-session-id (#2779) #2792 侧已完成(见该线程八问)。
  6. 是否破坏缓存:否——本线程未做任何代码改动;已合并的修复也保持上游缓存亲和输入逐字节不变(有 e2e 断言钉住)。
  7. 是否改了设计方向:无。
  8. 是否引入新配置:无。

标签:duplicate(记录本票与已合并 #2792 重复;保留 pr)。

结论:第三批清理动作①判断成立,关闭正确。感谢 @mariopasquali 的贡献——排查方向与合并修复完全一致,测试思路已被 master 套件覆盖。

@ranxianglei ranxianglei added the duplicate This issue or pull request already exists label Oct 24, 2026
@ranxianglei ranxianglei changed the title Prefer native OpenCode session IDs over shared parent cache affinity [PR] Prefer native OpenCode session IDs over shared parent cache affinity Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native OpenCode children share mutable ACP state when parent affinity wins over x-opencode-session-id

2 participants