Skip to content

fix: parse OpenCode Zen /zen/v1/chat/completions as OpenAI inference - #1225

Merged
huang195 merged 1 commit into
mainfrom
fix/zen-chat-completions-path
Oct 1, 2026
Merged

huang195 merged 1 commit into
mainfrom
fix/zen-chat-completions-path

Conversation

@huang195

@huang195 huang195 commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

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:

  • no Extensions.Inference (no model, no messages, no agent attribution)
  • events recorded with "plugin": "tool-prune", "reason": "no_inference_extension"
  • nothing for opencode in parsed inference views / cost aggregates

Observed live: an opencode session's POST /zen/v1/chat/completions events present but unparsed in the session API.

Fix

Add /zen/v1/chat/completions to the OpenAI arm of the dispatch switch, as a named zenPath const alongside bobPath, with a regression test mirroring TestInferenceParser_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 passes
  • go vet ./core/plugins/inferenceparser/ clean

Deferred from review

  • Test fixture model (suggestion): TestInferenceParser_ZenPath_ChatCompletions uses claude-sonnet-5, but Zen serves Claude on /zen/v1/messages (opencode.ai/docs/zen). A model Zen routes to chat/completions, such as kimi-k2.6 or big-pickle, would match the path under test.
  • Rest of Zen (suggestion): /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/messages takes more than a case label: the response-side == anthropicMessagesPath checks in plugin.go have to share one dialect helper with the request switch.
  • Suffix match (nit): match the /v1/chat/completions suffix, as tool-prune and context-guru already do, instead of adding a const per gateway.

Summary by CodeRabbit

  • New Features
    • Added support for OpenCode Zen chat-completions requests using the OpenAI-compatible request format.
  • Tests
    • Added coverage verifying that Zen requests capture the model and message and continue processing.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 91f64650-01a8-47e4-8b1b-dc1e554e00a5

📥 Commits

Reviewing files that changed from the base of the PR and between 61a382e and 19aba13.

📒 Files selected for processing (2)
  • core/plugins/inferenceparser/plugin.go
  • core/plugins/inferenceparser/plugin_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The 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.

Changes

OpenCode Zen chat completions

Layer / File(s) Summary
Register and validate the Zen route
core/plugins/inferenceparser/plugin.go, core/plugins/inferenceparser/plugin_test.go
The parser adds the Zen endpoint to its OpenAI request routes. The test checks that a request continues and captures the expected model, user message, and action classification.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: abigailgold

Merge Risk: ⚪ Minimal · up to 19aba

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 Review

Security architecture risk: 🔵 Low · up to 19aba

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
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The directly affected population is traffic reaching a configured inference parser with the Zen path, including query-string variants. Dispatch checks the path rather than the destination host. Downstream effects depend on configured consumers; deployment-wide tenant, service, and environment exposure is not established.

Security Findings and Attack Paths

  • inferred — The security-relevant path is client-supplied model data to inference metadata to per-model policy selection. The local mapping is established, but external matching, unknown-model handling, and authorization constraints remain unresolved. This is an exposure question, not a verified policy bypass.

Trust Boundaries and Controls

  • observed — The parser writes inference metadata and returns Continue; it does not change forwarding destinations or authenticated identity. The CPEX adapter separately obtains the subject from pipeline identity, workload identity from pipeline agent data, and configured identity resolution through its existing invocation path.

Resilience and Maintainability Implications

  • observed — Zen uses existing request-scoped response state and terminal finalization. State access assumes single-threaded processing per request; cost publication has a per-request latch. ExtProc supplies terminal delivery and teardown recovery. Arbitrary duplicate terminal callbacks and final state disposal are not fully proven, but neither mechanism was changed by this PR.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: parsing OpenCode Zen chat-completions requests as OpenAI inference.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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]>
@huang195
huang195 force-pushed the fix/zen-chat-completions-path branch from b768a83 to 19aba13 Compare October 1, 2026 18:39

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@huang195
huang195 merged commit 39cb3de into main Oct 1, 2026
28 checks passed
@huang195
huang195 deleted the fix/zen-chat-completions-path branch October 1, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants