Skip to content

feat: add user-scoped ai-gateway-responses-websocket experiment - #30210

Closed
ThomasK33 wants to merge 2 commits into
mainfrom
tk/ai-gateway-responses-ws-experiment
Closed

ThomasK33 wants to merge 2 commits into
mainfrom
tk/ai-gateway-responses-ws-experiment

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Adds the user-scoped experiment ai-gateway-responses-websocket and delivers its per-user decision to the AI Gateway, so the upcoming OpenAI Responses WebSocket support can be rolled out per user. This PR changes no request handling: nothing reads the flag yet, and WebSocket upgrades on /openai/v1/responses still return 501.

The gateway (including standalone coder ai-gateway start) has no database access and cannot evaluate experiment rules itself. coderd's DRPC IsAuthorized therefore evaluates the experiment for the API key owner through experiments.Evaluator, which fails closed on errors. It returns the result in the new IsAuthorizedResponse.responses_websocket_enabled field. The aibridged protocol moves to 1.4; 1.x gateways keep working and ignore the field. The gateway stores the value in the request context with aibridge.WithResponsesWebSocketEnabled, and later PRs read it with aibridge.ResponsesWebSocketEnabled(ctx). The helper lives in coderd/aibridge rather than coderd/aibridged so the aibridge library can import it without an import cycle.

ExperimentEvaluator is now a required aibridgedserver.Options field. The ruleguard in scripts/rules.go forbids static checks of the new experiment in coderd, like the other user-scoped experiments.

Note: every AI Gateway request now reads the experiment rules once more in IsAuthorized; a condition rule also loads the user's organizations and groups.

Dogfood UAT via Coder Agents passed: per-user rule scoping in /api/v2/experiments, unchanged gateway HTTP for matched and unmatched users, and 501 for WebSocket upgrades.

Stack: bottom layer, base main. Follow-ups build the Responses WebSocket session core and endpoint on top.

Note

This PR was written by an AI coding agent (xum).


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-30T21:23:19.082099Z 8d9f974 Manual request
ℹ️ 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.

@ThomasK33

Copy link
Copy Markdown
Member Author

The ci workflow did not start on pull_request for this PR, so I dispatched it manually for head 8d9f974: https://github.com/coder/coder/actions/runs/36778989773

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 8d9f974c35

ℹ️ 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".

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

Add the user-scoped experiment ai-gateway-responses-websocket and deliver
its per-user decision to the AI Gateway, which cannot evaluate experiment
rules itself.

- codersdk: new ExperimentAIGatewayResponsesWebSocket, listed in
  ExperimentsKnown and ExperimentsUserScoped; the ruleguard rule in
  scripts/rules.go now covers it.
- aibridged proto: IsAuthorizedResponse gains responses_websocket_enabled;
  API version bumped to 1.4. Older 1.x gateways ignore the field.
- aibridgedserver: IsAuthorized evaluates the experiment for the API key
  owner through experiments.Evaluator (fails closed). The evaluator is a
  required server option, wired from coderd and the enterprise serve
  endpoint.
- aibridged: ServeHTTP stores the decision in the request context via
  coderd/aibridge WithResponsesWebSocketEnabled; ResponsesWebSocketEnabled
  reads it. The helper lives in coderd/aibridge so the aibridge library can
  consume it without an import cycle. Request handling is unchanged and
  WebSocket upgrades still return 501.
Cover the fail-closed default of aibridge.ResponsesWebSocketEnabled: a
context that never passed through the gateway reports the experiment off.
The gateway tests only exercise contexts where the flag was set.
@ThomasK33
ThomasK33 force-pushed the tk/ai-gateway-responses-ws-experiment branch from 8d9f974 to e6bb4fd Compare October 2, 2026 08:16
@linear-code

linear-code Bot commented Oct 8, 2026

Copy link
Copy Markdown

AIGOV-410

@github-actions github-actions Bot added the stale This issue is like stale bread. label Nov 9, 2026
@github-actions github-actions Bot closed this Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale This issue is like stale bread.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant