fix: send x-opencode-session header to OpenCode providers - #4190
Open
IsmaelMartinez wants to merge 1 commit into
Open
fix: send x-opencode-session header to OpenCode providers#4190IsmaelMartinez wants to merge 1 commit into
IsmaelMartinez wants to merge 1 commit into
Conversation
IsmaelMartinez
force-pushed
the
fix/opencode-session-header
branch
from
September 7, 2026 18:52
9e1feea to
733ec47
Compare
5 tasks
IsmaelMartinez
marked this pull request as ready for review
September 7, 2026 19:03
IsmaelMartinez
force-pushed
the
fix/opencode-session-header
branch
from
September 7, 2026 19:07
733ec47 to
7a0b20e
Compare
IsmaelMartinez
marked this pull request as draft
September 7, 2026 19:08
IsmaelMartinez
marked this pull request as ready for review
September 7, 2026 20:55
IsmaelMartinez
force-pushed
the
fix/opencode-session-header
branch
from
September 8, 2026 07:03
7a0b20e to
c45be64
Compare
This was referenced Sep 8, 2026
OpenCode asks clients to send a stable session ID per conversation, which it uses to optimise routing and prompt caching. A middleware derives the value from the session already on the request context, so multiplexed deployments get one ID per conversation rather than one per client. Fixes docker#4164 Co-Authored-By: Md Yunus <admin@yunuscollege.eu.org> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qyjba1txhq3QsrpcGUt3FM
IsmaelMartinez
force-pushed
the
fix/opencode-session-header
branch
2 times, most recently
from
September 8, 2026 07:21
c45be64 to
d4fa155
Compare
Contributor
|
Thanks @IsmaelMartinez, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenCode's docs ask clients to send a stable ID per conversation in
x-opencode-session, which they use to optimise routing and prompt caching. The reporter of #4164 additionally quotes an OpenCode email saying requests missing the header may error from 2026-09-06; the docs themselves state no date, so treat the deadline as their account rather than a documented one.A middleware on the OpenAI client, the same shape as the existing
chatgptAuthMiddleware, sets the header on every request toopencode.ai, covering both built-in aliases and custom providers. The value is a UUIDv5 derived from the session ID already on the request context, salted so it cannot be correlated with the local session store or the gateway'sX-Cagent-Session-Id. Requests with no session on the context fall back to a per-client UUID, and a value pinned throughprovider_opts.http_headersalways wins.This supersedes an earlier version of this PR that set the header once at client construction. @yunus25jmi1 pointed out in #4191 that the client is built once per process in
serve a2a,serve mcpand the TUI, so a construction-time value collapses to one ID per deployment in exactly the multiplexed cases the issue is about. The implementation here is theirs, carried over with the commit co-authored; my part is the docs wording and the accuracy corrections against OpenCode's published text.Custom Anthropic or Google providers pointed at OpenCode are still not covered, since those clients have no custom-header support today.
Fixes #4164
🤖 Generated with Claude Code
https://claude.ai/code/session_01Qyjba1txhq3QsrpcGUt3FM