feat(agent): use stable /api/v2 chat routes with experimental fallback - #177
Conversation
Negotiate the chat prefix per client, preserve legacy model-config lookup, and preflight WebSockets and streaming uploads without replaying bodies. Update deployment examples and validate README snippets. Signed-off-by: Thomas Kosiewski <tk@coder.com> --- _Generated with [`mux`](https://github.com/coder/mux) • Model: `coder:openai/gpt-6-astra` • Thinking: `high`_ Change-Id: I779a79dc123c2699c903b1b600168efd1fe81bc3
|
@codex review |
|
@codex security review |
Live verification evidenceHead: The attached terminal screenshot and accelerated recording show actual SDK REST and stream transport events plus the successful global-watch factory upgrade. The proof ran at 20:04:59–20:05:02 UTC, on the same production source as this head (only documentation changed afterward). All created chats were archived; the watch was closed. No pre-2.37 deployment was available for a live fallback run; fallback is source- and unit-test-verified. Transport transcriptGenerated with |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |

Summary
/api/v2/chatsfor promoted REST routes and both chat WebSockets; retain the deprecated/api/experimental/chats/model-configslookup independently.CoderChatClient, tolerating older deployments without buildinfo/semver gating.dev.coder.comreferences withdogfood.cdr.dev, document compatibility, and fix a checkpoint example mismatch exposed by typechecking all README snippets.Upstream context
/api/v2(merged August 26, 2026), shipped in v2.37.0 on September 1.codersdkto the stable prefix; #28760 removed the API reference's early-access label.Prefix negotiation
An unresolved client's actual REST call tries v2 first. Only a
CoderApiError404 retries the same call once on experimental. The first non-404 HTTP response, including an error, locks its prefix. Two 404s rethrow the original v2 error and leave the client unresolved; network/abort failures do not establish support. Once locked, even resource 404s do not renegotiate. Concurrent initial calls can probe independently, but cannot overwrite an established lock.WebSockets resolve an unknown prefix with a read-only
GET /chatsbefore dialing. Resolution runs inside the existing reader cancellation wrappers, soreturn(),throw(), disposal and abort can cancel the preflight. This avoids depending on factory-specific upgrade-error messages. Non-replayableReadableStreamuploads use the same preflight before consuming the body; JSON/Blob requests use actual-call fallback. This small exception avoids unsafe upload replay without adding a general retry/buffering mechanism.http:*paths remain the actual wire paths; no new event kinds were added. WebSocket preflights useop: "streamEvents"/"watchChats". The standalone watch helper defaults to v2; per-client negotiation is provided byCoderChatClient. Org-scoped model listing and its deprecated experimental fallback neither consult nor establish the chat-prefix lock.Verification tiers and dogfooding
https://dogfood.cdr.dev, reportingv2.37.0-devel+acae170664. Ambient Coder credentials were checked withcoder whoami; no tokens were created, revoked, printed, or unset. A transport-logging harness exercised REST create/archive, a successful per-chat stream upgrade, and a fresh client's listing preflight plus global watch upgrade. Screenshot, recording, and transcript are attached in a PR comment.coderd/coderd.goconfirms no/api/v2/chatsmount. Tests cover fallback success and non-404 failures, persistent locking, both-404 error fidelity, concurrent initialization, independent model lookup, body/signal preservation, streaming upload safety, and both WebSockets. No pre-2.37 deployment was available for a live fallback run.Gates
pnpm formatandpnpm check— pass.pnpm -r build,pnpm -r test— pass: 622 tests (all 597 existing + 25 new). Agent 351, provider 22, sandbox 191, effect 45, release tooling 13.pnpm publint,pnpm attw— pass.examples/into 26 typed scratch modules,pnpm --filter @coder/ai-sdk-agent typecheckpassed, scratch removed.Both Codex review loops and the
RequiredCI gate must be clean on the current head before entering the squash merge queue.Generated with
mux• Model:coder:openai/gpt-6-astra• Thinking:high