Repository navigation
fix: parse OpenCode Zen /zen/v1/chat/completions as OpenAI inference - #1225
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe inference parser recognizes OpenCode Zen’s chat-completions endpoint and processes its requests with the existing OpenAI request parser. A test checks the parsed model, user message, and action classification. ChangesOpenCode Zen chat completions
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The new Zen endpoint reuses existing OpenAI parsing, and the added test checks the expected inference details. No concrete merge-blocking risk is evident. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change is narrow and reuses established processing. No new permission or isolation failure was established, but previously unclassified requests can now influence existing security-policy selection. Behavior under deployed policies remains unverified. Retained concerns Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
OpenCode Zen mounts an OpenAI-dialect chat completions API under /zen, so opencode traffic to opencode.ai/zen/v1/chat/completions fell to the inference-parser default arm: no model/message telemetry, no cost. Add /zen/v1/chat/completions alongside bobPath, mirroring the existing Bob special-case, with a matching test. Signed-off-by: Hai Huang <[email protected]>
b768a83 to
19aba13
Compare
pdettori
left a comment
There was a problem hiding this comment.
Clean, well-scoped fix. Adding zenPath to the OpenAI arm of the dispatch switch follows the established bobPath pattern exactly, and the regression test mirrors TestInferenceParser_BobPath_ChatCompletions with good assertions (Continue action, non-nil Inference extension, model, messages, IsAction).
Verified that the dispatch switch is the only site needing the new constant — all other endpointPath uses in the parser are Anthropic-dialect checks, and upstream code search shows no other bobPath dispatch sites. Scope is right: deferring /zen/v1/messages (Anthropic dialect via Zen) until observed in traffic is the correct call.
Areas reviewed: Go (inferenceparser), tests
Agent/IDE config (.claude/.vscode): none
Commits: 1, signed-off: yes
CI status: passing
Problem
OpenCode routes inference to OpenCode Zen at
opencode.ai/zen/v1/chat/completions. That path is an OpenAI-dialect chat-completions endpoint, but the inference-parser's dispatch switch only exact-matches/v1/chat/completions,/v1/completions,/chat/completions,/completions, and Bob's/inference/v1/chat/completions. Zen traffic therefore fell to the default arm:Extensions.Inference(no model, no messages, no agent attribution)"plugin": "tool-prune", "reason": "no_inference_extension"Observed live: an opencode session's POST /zen/v1/chat/completions events present but unparsed in the session API.
Fix
Add
/zen/v1/chat/completionsto the OpenAI arm of the dispatch switch, as a namedzenPathconst alongsidebobPath, with a regression test mirroringTestInferenceParser_BobPath_ChatCompletions.Note: /zen/v1/messages (Anthropic dialect via Zen) is intentionally out of scope; observed traffic from opencode 2.0.21 uses /zen/v1/chat/completions.
Test plan
go test ./core/plugins/inferenceparser/— new Zen test plus full package passesgo vet ./core/plugins/inferenceparser/cleanDeferred from review
TestInferenceParser_ZenPath_ChatCompletionsusesclaude-sonnet-5, but Zen serves Claude on/zen/v1/messages(opencode.ai/docs/zen). A model Zen routes to chat/completions, such askimi-k2.6orbig-pickle, would match the path under test./zen/v1/messages(Claude, most Qwen),/zen/v1/responses(GPT, Grok) and/zen/v1/models/<id>(Gemini) still fall to the default arm. Adding/zen/v1/messagestakes more than a case label: the response-side== anthropicMessagesPathchecks inplugin.gohave to share one dialect helper with the request switch./v1/chat/completionssuffix, astool-pruneandcontext-gurualready do, instead of adding a const per gateway.Summary by CodeRabbit