Repository navigation
Conversation
OpenCode 2.x sends x-session-id, x-session-affinity and x-opencode-session as the parent (or fork source) session for every child session, so subagents share prompt-cache affinity with their parent. Only x-opencode-session-id names the requesting session. Keying on the affinity ids made every subagent Run bind to its parent's Cursor conversation: it superseded the parent's held Run and left the parent resuming a checkpoint that now held the subagent's turns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused change correctly addresses the session collision and includes appropriate regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Prioritizes the requesting OpenCode session ID so subagents no longer reuse their parent’s Cursor conversation.
Changes:
- Uses
x-opencode-session-idbefore affinity fallback headers. - Adds regression coverage for parent/child session separation.
| File | Description |
|---|---|
src/language-model.ts |
Corrects session-key header precedence. |
test/conversation-id.test.ts |
Tests subagent conversation isolation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Soak test resultsI ran a local soak test with OpenCode 2.0.21 ( Build under test: this PR combined with #32 (foreign-history reseed), plus an unpublished follow-up that reseeds when a resumed checkpoint fails after missing KV blobs, plus a debug trace for raw end-stream error frames. Without this fix, a child Run arrives with the parent's key, supersedes the parent's held Run and forces a reset. I reproduced that in the same setup (see the PR description). Every round ran
Results
Observations (none of them caused a failure)
|
|
Closing in favor of a single consolidated PR. It combines this change with the related fixes found during soak testing on OpenCode 2.x (subagent session key, foreign-history reseed, system-notice continuations, missing-blob reseed) and includes the full test results. I'll link it here once it's open. |
|
Consolidated PR: #34 |
Summary
OpenCode 2.x sets
x-session-id,x-session-affinityandx-opencode-sessionto the parent session (or the fork source) on every child-session request, so that subagents share prompt-cache affinity with their parent. Onlyx-opencode-session-ididentifies the session that is actually making the request. The relevant part of OpenCode 2.0.21's request builder:opencodeSessionKeyreadx-session-idfirst, so every subagent Run running on a Cursor model was bound to its parent's Cursor conversation. Two things went wrong as a result:sessionManager.close: reason=superseded-by-new-run).code=internalafter spawning subagents.It happens for every way of starting a subagent: built-in
general, custom subagents, and a Cursor-native Task mapped tosubagent. It happens whether or not the subagent uses the same model as the parent.The fix is to read
x-opencode-session-idfirst. The existing headers stay as fallbacks, so hosts that don't send it behave as before.Test plan
bun test: 1215 pass, 0 fail.tsc --noEmitis clean.cursor/gpt-5-minispawnedgeneral(same model), a custom subagent oncursor/gemini-3-flash, and one on DeepSeek.internalerror.Related to #32: that PR detects and repairs a conversation that a foreign model has diverged, and this PR removes one major source of that divergence.
🤖 Generated with Claude Code