Repository navigation
fix(opencode-go): always send x-opencode-session via per-instance session id - #1710
Conversation
…sion id The Go gateway requires the x-opencode-session header on every request for operator-side session affinity (requests missing it may error). It was only sent when metadata.taskId existed, and completePrompt never sent it at all. Add a uuidv7 per-instance session id on the handler (mirroring the OpenAiNativeHandler fallback pattern) and send x-opencode-session: metadata.taskId ?? sessionId at every request site: chat-completions streaming, Anthropic /v1/messages streaming, Responses streaming, and all three completePrompt paths. Fixes Zoo-Code-Org#1511
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: Zoo-Code-Org/Zoo-Code/.coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📜 Recent review details🧰 Additional context used📓 Path-based instructions (5)Treat model, provider, MCP, path, command, and tool data as untrusted.⚙️ CodeRabbit configuration file Files:
Require regression coverage at the lowest valid harness with behavior-focused assertions, including relevant negative, error, false/unset, and boundary cases.⚙️ CodeRabbit configuration file Files:
Check strict typing and exhaustive behavior across normal, boundary, error, cancellation, retry, and compatibility paths.⚙️ CodeRabbit configuration file Files:
Verify extension/webview contracts, cancellation and error propagation, VS Code lifecycle correctness, and behavior under retries and partial failure.⚙️ CodeRabbit configuration file Files:
Act as an adversarial second-opinion reviewer.⚙️ CodeRabbit configuration file Files:
🔇 Additional comments (2)
📝 SummarySummary by CodeRabbit
WalkthroughChangesOpenCode Go session headers
Priority: ⬆️ High Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix · Severity of issue fixed: Medium Sequence Diagram(s)sequenceDiagram
participant Caller
participant OpencodeGoHandler
participant OpenCodeGoAPI
Caller->>OpencodeGoHandler: createMessage or completePrompt
OpencodeGoHandler->>OpencodeGoHandler: Select taskId or sessionId
OpencodeGoHandler->>OpenCodeGoAPI: Send request with x-opencode-session
OpenCodeGoAPI-->>OpencodeGoHandler: Return response
🚥 Pre-merge checks | ✅ 8✅ Passed checks (8 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Review statusThanks for contributing. This comment tracks the review sequence and the next action. Current step: Awaiting fresh human maintainer or CODEOWNER approval. Automated review is complete for the latest commit but does not replace human approval. Review-state labels are managed by this workflow; do not edit them manually. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…diff churn The codecov patch partials were not the streaming header fallbacks (those arms are all exercised by the metadata-absent createMessage tests): they were lines 720-722, pre-existing conditionals that became patch lines because the completePrompt Anthropic restructure re-indented the untouched params object. - Send the session header on the Anthropic client's defaultHeaders instead of a per-request option in completePrompt (per-request headers still override it with taskId when streaming), so the completePrompt params block stays byte-identical to main and out of the diff. The supportsTemperature false arm there is unreachable for Anthropic-format Go models by design. - Add a completePrompt test for the includeMaxTokens-on / modelMaxTokens-unset max_tokens fallback, mirroring the streaming test of the same name, and assert the defaultHeaders session header. Patch coverage of opencode-go.ts vs base is now 100% with no untaken branch arms on added lines.
Related GitHub Issue
Closes: #1511
Description
The OpenCode Go provider only sent the
x-opencode-sessionheader whenmetadata.taskIdwas set, so any request without a task context (including everycompletePromptcall from the prompt-enhancement flow) omitted the header entirely. Operators use this header for session affinity, so those requests could land on a different backend session.The handler now always sends the header:
metadata.taskIdwhen available, otherwise a stable per-instanceuuidv7()session id — the exact patternopenai-native.tsalready uses (sessionIdfield, same import;??instead of||, semantically identical sincetaskIdisstring | undefined).Coverage: chat-completions streaming, Responses streaming, Anthropic
/v1/messagesstreaming, and all threecompletePromptpaths (Anthropic, Responses, chat-completions —CompletePromptOptionshas no taskId, so the instance session id is used there). Per-requestheadersmerge over the SDK clients' existingdefaultHeaders, so theDEFAULT_HEADERS/User-Agentwiring is untouched.Test Procedure
src/api/providers/__tests__/opencode-go.spec.ts:x-opencode-session, and the value is stable across two calls on the same handlercompletePromptpathsmock.calls[0][0]property assertions (same or stricter)cd src && ./node_modules/.bin/vitest run api/providers→ 78 files / 1924 tests passed, 1 skipped.cd src && pnpm run check-types→ 0 errors.Pre-Submission Checklist
Visual Snapshots
N/A.
Videos (interaction / animation only)
N/A.
Documentation Updates
Additional Notes
No manifest changes needed —
uuidv7 was already a dependency. Follow-up idea (out of scope): other providers using conditional session headers could adopt the same per-instance fallback, but each deserves its own small PR.Get in Touch
GitHub: @myk1yt — please tag me here; I monitor notifications.