Repository navigation
fix: OpenCode Go/Zen requests are missing the required x-opencode-session header - #137464
Conversation
OpenCode Go/Zen (opencode.ai) enforces an x-opencode-session header from 2026-09-06 and uses it for prompt-cache routing. Add an "opencode" session-affinity mode detected by baseUrl host (covers zen/go/v1 and zen/v1, OpenAI-completions and Anthropic transports). For opencode hosts the header is sent whenever a stable session id is available, without requiring the sendSessionAffinityHeaders opt-in; the flag-gated generic modes are unchanged. Fixes openclaw#137165
…e endpoints Review follow-up: extract isOpencodeEndpoint (trailing-dot safe, parse guarded) shared by both transports; the compliance header now survives cacheRetention none; add Anthropic zen/go and OpenAI zen/v1 regression coverage.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 11:58 AM ET / 15:58 UTC. ClawSweeper reviewWhat this changesAdds stable OpenCode conversation headers across four model transports while preserving explicit headers and working independently of prompt caching. Merge readiness✅ Ready for maintainer review This PR remains necessary and has no actionable correctness findings. The earlier coverage and header-precedence defects are resolved, and the supplied live transport evidence satisfies the proof requirement. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw’s model transports turn agent conversations into requests to hosted model providers. This change carries the existing conversation identifier through SDK and managed transport paths to OpenCode. flowchart LR
A[Agent conversation] --> B[Model transport selection]
B --> C[OpenCode endpoint check]
C --> D[Preserve explicit header or use conversation ID]
D --> E[SDK or managed transport]
E --> F[OpenCode model response]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +64, Tests +230, Docs +5. Total +299 across 16 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Use the existing conversation ID consistently at request construction, preserving configured header precedence and optional cache behavior. Do we have a high-confidence way to reproduce the issue? Yes: inspected current-main request construction omits the required header, matching the supplied capture-only baseline. This review did not execute a failing live request. Is this the best way to solve the issue? Yes: the shared resolver repairs existing request paths without new configuration or storage, and the supplied real completions validate the central Go workflow. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b3f87ed37006. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
* origin/main: (25 commits) docs(releases): keep the release-notes nav group to version routes (#140353) fix(ui): hide trust wrappers in imported chat history fix(subagents): subagent list building decodes unrelated saved prompts in large session stores (#139540) test(process): share relay startup fixtures (#140345) refactor(doctor): inline GitHub skill discovery inputs (#140343) refactor(ui): share channel status type definitions (#140331) refactor: simplify queue state and infrastructure dispatch (#140311) fix: require saved agent turns before update verification succeeds (#140274) fix(update): keep the service profile when switching to Git (#140263) fix(ui): prevent image avatars overlapping mobile chat (#140341) fix(test): accept release subpages in docs route shape (#140337) refactor(plugins): share uninstall mutation ownership (#140322) refactor(agents): use canonical tool execution arguments (#140280) perf(cli): keep inference metadata and domain help lazy (#140327) refactor(plugins): simplify self-hosted setup results (#140332) refactor(config): reuse parent lookup for unset operations (#140326) fix(plugins): preserve exact installed-index mutation receipts (#140328) test(agents): simplify MCP and LSP boundary fixtures (#140312) fix(ui): preserve literal source previews and copied whitespace (#140306) fix: OpenCode Go/Zen requests are missing the required x-opencode-session header (#137464) ...
…sion header (openclaw#137464) * fix: send x-opencode-session header on OpenCode endpoints OpenCode Go/Zen (opencode.ai) enforces an x-opencode-session header from 2026-09-06 and uses it for prompt-cache routing. Add an "opencode" session-affinity mode detected by baseUrl host (covers zen/go/v1 and zen/v1, OpenAI-completions and Anthropic transports). For opencode hosts the header is sent whenever a stable session id is available, without requiring the sendSessionAffinityHeaders opt-in; the flag-gated generic modes are unchanged. Fixes openclaw#137165 * fix: emit x-opencode-session regardless of cache retention on OpenCode endpoints Review follow-up: extract isOpencodeEndpoint (trailing-dot safe, parse guarded) shared by both transports; the compliance header now survives cacheRetention none; add Anthropic zen/go and OpenAI zen/v1 regression coverage. * fix(opencode): identify conversations across all model transports * fix(opencode): cover managed transports and preserve configured identity * fix(google): merge model and stream headers case-insensitively * test(opencode): use transport-specific model fixtures --------- Co-authored-by: Ghilteras <[email protected]> Co-authored-by: VACInc <[email protected]>
Closes #137165. Related: #135588.
Summary
High Level TLDR
OpenCode requires a stable conversation header in addition to the User-Agent added by #135588. This PR sends
x-opencode-sessionthrough all four bundled OpenCode model transports, including when prompt caching is disabled.What Problem This Solves
Fixes an issue where OpenCode Go and Zen model requests omit the conversation identity required by the provider. The vendor notice warns that requests without it may fail starting September 6, 2026. The requirement is documented at https://opencode.ai/docs/go/.
Why This Change Was Made
One shared header resolver covers both standalone SDK adapters and the managed transports selected by normal Gateway turns: Anthropic, Gemini, OpenAI Chat Completions, and OpenAI Responses. Managed Google receives the header at its provider-plugin boundary; managed Responses shares the HTTP/WebSocket header builder. It uses the existing stream
sessionIdindependently of optional cache-affinity headers, avoiding four separate compatibility policies. It applies only to HTTPS requests toopencode.ai, accepts the DNS trailing-dot spelling, preserves explicit model and stream headers case-insensitively, and leaves unrelated endpoints unchanged. The Google SDK header merge now uses the existing case-insensitive transport helper, preventing model and stream spellings of the same header from becoming a comma-joined value. Sessionless SDK calls do not invent a shared ID; direct callers must supply their conversation'ssessionId.Root Cause
#135588 implemented
User-Agentidentification only. The original patch in this PR added the session header to Chat Completions and Anthropic but left bundled Responses and Gemini routes uncovered. It also coupled the required identity to cache-session selection. The revised implementation supplies the required header before each SDK receives its request headers, keeping optional cache behavior unchanged. Follow-up review also identified the separate managed transport implementations; those now use the same policy, with regression coverage through the runtime transport selector and fetch egress.User Impact
OpenCode conversations carry the required identity across all four API families and retain it with
cacheRetention: "none". No configuration, dependency, storage, or protocol changes are needed. The original contributor's commits are preserved; the maintainer follow-up resolves the merge conflict and completes the missing transport coverage.Verification
Evidence
eslint(curly)in the new helper).git diff --check: passed.model-session, stream-sessioninstead ofstream-session). The Google adapter now uses the existing canonical merge helper. Evidence: https://github.com/openclaw/openclaw/actions/runs/34039644850/job/101504061040.88f3d1bda27ec49f442ce22076c968ae1bf573ce: production types, test types, and lint passed. The request-egress regressions passed for all four transports, including the repaired Google precedence case; the containing shard passed 4,100 tests across 234 files (one additional test skipped). Evidence: https://github.com/openclaw/openclaw/actions/runs/34040446299/job/101506232135. The full CI run passed all 108 jobs: https://github.com/openclaw/openclaw/actions/runs/34040446299.Real behavior proof
Passed on September 6, 2026 against real OpenCode Go, using the reviewed source at
88f3d1bda27ec49f442ce22076c968ae1bf573cein a separate process. The probe calledcreateBoundaryAwareStreamFnForModelwithopencode-go/minimax-m2.5, the normal Go Chat Completions endpoint, and the existing configured API-key credential loaded read-only. It supplied synthetic conversation IDs and no explicitx-opencode-sessionheader. The fetch observer asserted the automatically generated header immediately before forwarding the original request to OpenCode; it did not add or replace headers or responses.Procedure:
cacheRetention: "none"and synthetic conversation A. Require HTTP 200 and the exact textOPENCODE_SESSION_OK.cacheRetention: "short", and require the same conversation header and successful reply.cacheRetention: "none"; require its distinct header and the same successful reply.Command shape (checkout paths redacted):
Observed output, reduced to the synthetic test fields:
Environment: Linux, Node 25.9.0, tsx 4.23.12, existing installed OpenAI SDK 7.5.0. CI separately tested the PR's locked dependencies. Only synthetic prompts were sent; credentials, actual generated conversation IDs, account data, and private endpoints are omitted from this evidence.
Deployed compiled transport follow-up
Repeated the same three live requests using the deployed
packages/ai/dist/index.mjsandpackages/ai/dist/transports.mjs, built from base9d20f0b07accf2566251380ff2204e710653d363plus this PR at88f3d1bda27ec49f442ce22076c968ae1bf573ce. This run used the pinned OpenAI SDK 7.8.0. The observer again only asserted headers and forwarded the original requests.The deployment owner verified build/source transfer before restarting the Gateway. Its finalization command nevertheless exited nonzero because an existing legacy config-audit archive failed migration; the preserved archive was not altered to bypass that refusal. The recovery path started the verified new runtime, and separate RPC and health checks then passed. Thus the deployed transport proof passed, but the broader update finalization is not claimed as successful.
What was not tested
Live completion proof covers OpenCode Go Chat Completions. Anthropic, Responses, and Gemini are covered by passing request-egress regressions, not successful live completions in these runs. The probes used isolated processes executing the actual managed transport, including the deployed compiled package in the follow-up; they were not full Gateway agent/channel turns. Timings are observations, not a statistically meaningful before/after performance benchmark; no baseline live completion benchmark was run.