Skip to content

fix(opencode): select the Connect protocol per model - #8856

Merged
lidge-jun merged 4 commits into
lidge-jun:devfrom
colthreepv:codex/opencode-protocol-per-model
Nov 18, 2026
Merged

lidge-jun merged 4 commits into
lidge-jun:devfrom
colthreepv:codex/opencode-protocol-per-model

Conversation

@colthreepv

@colthreepv colthreepv commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Human Summary

I started out thinking we should move all OpenCode requests to Responses. #8829
Then I realized OpenCode already does the part we need for OpenCode Go: it can choose an API adapter per model.
"Connect" can use that same mechanism. If a model already has a direct Chat route, OpenCode can send Chat and the proxy can keep that path. Everything else uses Responses. From the user’s point of view, nothing changes: they still just pick a model.

Summary

OpenCode Connect currently generates Chat Completions for every model. This draft is a per-model alternative to #8829: both config generations default to Responses and opt a concrete model into Chat only when the existing router resolves it to a native-eligible Chat route from both ingress protocols. Native Responses models and dynamic routes keep the Responses default. Model selectors, managed ownership, and upstream routing are unchanged.

This reuses OpenCode's model-level adapter selection, so a user picks a model without selecting an API. It reuses the proxy's existing native paths; the regular per-request eligibility and admission checks still apply. Remote admission uses the same dedicated header, in the location each OpenCode generation reads.

Verification

  • Focused Windows tests: 288 passed, 17 opt-in Kilo/combined cases skipped, 0 failed across client export, live wire, managed refresh, launcher, CLI export, admission, and the core/Lab import boundary.
  • The live tests ran OpenCode 1.19.5 and 2.2.6 with a single generated config through a real OpenCodex server and mock Chat and Responses upstreams. They verify matching ingress/egress and separate upstream authorization. Local follow-up probes verified byte-identical WAV forwarding on V1 native Chat and encrypted reasoning/tool continuation on both Responses clients. V2 audio attachment parity is outside this draft.
  • bun run typecheck, bun run structure:check, bun run docs:clients:check, bun run privacy:scan, and the docs-site frozen install/build passed.
  • Full suite and upstream CI are not claimed as passing. This draft is for scope review before readiness.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • New Features

    • OpenCode exports now select Chat Completions or Responses for each model based on its provider route. Models with unsupported or unresolved routes continue to use Responses.
    • Updated connection details support both protocols, including authentication requirements. Chat-compatible models also receive the appropriate reasoning compatibility settings.
  • Documentation

    • Updated OpenCode setup guidance and client compatibility tables in multiple languages to document support for both protocols and explain model-level protocol selection.

Readiness boxes ticked by maintainer @lidge-jun at integration (2026-11-18) after the exact-head review and CI described in the PR comments.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

OpenCode V1 and V2 exports now default to Responses and select Chat Completions for eligible model routes. The changes update provider and model metadata, connection serialization, protocol tests, the support matrix, and OpenCode documentation.

Changes: OpenCode protocol-aware exports

Layer / File(s) Summary
Route-aware protocol selection and export shape
scripts/client-support-matrix/metadata.ts, src/clients/config-export/opencode-wire.ts, src/clients/config-export.ts, tests/config/client-config-export.test.ts, tests/clients/client-export-reasoning-controls.test.ts, tests/clients/opencode-kilo-refresh.test.ts, tests/server/management-client-config-route.test.ts
The exporter checks whether a concrete model route qualifies for Chat Completions. Eligible models receive generation-specific Chat package metadata and Chat-only reasoning fields; other models use Responses defaults. V2 provider headers are emitted separately from settings. When proxy admission uses a dedicated header, the connection also receives a loopback placeholder API key. Tests cover model selection, connection fields, reasoning metadata, and integration refresh.
Live proxy tests and harness
tests/clients/client-export-live-wire.test.ts, tests/helpers/client-export-live-wire.ts, tests/providers/opencode-cli.test.ts
The live proxy test runs OpenCode V1 and V2 with Chat Completions and Responses models, then checks request paths, model IDs, authorization, and inbound protocol logs. The harness sets per-model packages and local adapter configuration, controls OpenCode environment and logging, and retries cleanup.
Support matrix and protocol documentation
scripts/generate-client-support-matrix.ts, docs-site/src/content/docs/guides/opencode.md, structure/clients/integrations.md, structure/clients/client-support-matrix.md, docs-site/src/content/docs/{reference,es/reference,fr/reference,ja/reference,ko/reference,ru/reference,tr/reference,zh-cn/reference,zh-tw/reference}/client-support.md
The matrix fixture includes a direct Chat provider, and its generator allows some model-level protocol entries to be absent. The documentation describes Responses defaults, conditions for Chat overrides, and the protocol behavior of concrete, native, combo, policy, and unresolved routes. The client-support tables list both inbound protocols for OpenCode.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant OpenCode
  participant Proxy
  participant UpstreamProvider
  OpenCode->>Proxy: Send Chat Completions or Responses request
  Proxy->>UpstreamProvider: Forward request with selected path and credentials
  UpstreamProvider-->>Proxy: Return response
  Proxy-->>OpenCode: Relay response
Loading

Possibly related PRs

  • lidge-jun/opencodex#8829: Both PRs define Responses as the OpenCode V1 and V2 default protocol, so their final protocol selection must agree.
Merge Risk: Minimal · up to 488b7

OpenCode exports now default to Responses and use Chat Completions only for eligible models. The change is covered by updated tests and documentation, and no actionable merge-blocking risk was found. Confirm that the exact-head CI run passes before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(opencode): select the Connect protocol per model" matches the main change. The PR makes OpenCode Connect configs default to Responses and use Chat only for specific models whose explici…
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.
Full details: Title check

Explanation

The title "fix(opencode): select the Connect protocol per model" matches the main change. The PR makes OpenCode Connect configs default to Responses and use Chat only for specific models whose explicit route resolves to a native-eligible openai-chat upstream. The summary files show per-model protocol overrides (perModel), the new opencodeModelUsesChat function, and the updated tests and docs that support this. The title is concise, specific, and follows the conventional commit style. Minor note: 'Connect' is the product name used by the PR objectives, while the changed files refer to OpenCode and Kilo, so the title uses a term that a reader of the diff may need context for.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8d625b1 and 488b7fa.

Files selected for processing: 2

  • structure/clients/client-support-matrix.md
  • tests/server/management-client-config-route.test.ts

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

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ✅ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

✅ 4/4 boxes ticked.

This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers notified: @lidge-jun @Ingwannu

Hygiene

✅ Deterministic PR hygiene checks passed.

@colthreepv
colthreepv marked this pull request as ready for review November 16, 2026 20:14
@github-actions
github-actions Bot marked this pull request as draft November 18, 2026 09:08
@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer review of #8856 at 8d625b1: the design is approved. OpenCode V1 1.19.4 and V2 2.2.6 each selected Chat and Responses correctly from one generated config against mock upstreams, and refreshing a legacy managed config works.

One CI blocker: test changed fails on tests/server/management-client-config-route.test.ts, in "GET /api/client-config > opencode envelope carries the shared builder's exact bytes". The route's config gains "provider": { "npm": "@ai-sdk/openai-compatible" } on a model, while buildClientConfig("opencode", { …, config }) built from the same test config does not. It fails on the PR head and passes on dev. That test exists so that the dashboard download and ocx export never disagree, so please find which config object opencodeModelUsesChat receives in the management route versus the CLI path, make both use the same effective config, and keep the test as written.

Non-blocking: structure/clients/client-support-matrix.md should record the new perModel protocol-field exception and that the fixture needs at least one explicit override.

@lidge-jun
lidge-jun marked this pull request as ready for review November 18, 2026 11:43
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T11:52:30.852494Z 488b7fa Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer update: this supersedes my earlier request. The CI failure was the route test's old expectation, not a parity bug. b/no-context sits on a direct openai-chat route, so it now correctly carries the per-model Chat override; the dashboard download and ocx export still agree byte for byte. I pushed 488b7fa on top of a dev merge. It updates that expectation and records the perModel exception in structure/clients/client-support-matrix.md. Locally: route test, client-support-matrix and file-size ratchet pass 64/0; typecheck and structure:check are green. I ticked the readiness boxes on your behalf at integration. This merges after exact-head CI and a final review.

@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer integration into dev by @lidge-jun (MAINTAINERS.md 2026-09-06 policy) at exact head 488b7fa:

  • Review: gpt-6.2-sol final review APPROVE on this head, including live OpenCode V1/V2 runs choosing Chat and Responses per model, and byte parity between the dashboard export and the CLI export.
  • CI: every check on this head passed.
  • Union check: I merged current dev locally and reran typecheck, structure:check, the file-size ratchet, the test-layout guards and the client-config route, OpenCode export and client-support-matrix tests (156/0).
  • Review gate: scripts/ci/assert-mergeable-review.sh --maintainer-integration 8856 returned OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants