Repository navigation
Support ChatGPT subscription relay for ug codex - #1341
andy-xu-db wants to merge 3 commits into
Conversation
Relayed OpenAI Model Provider Services ({"openai": {"relayed": {}}}) are now usable by
codex. A relayed launch keeps Codex's own ChatGPT login (requires_openai_auth, no ug auth
command) and runs a loopback proxy that adds the Databricks token in
X-Databricks-AI-Gateway-Token on the AI Gateway /codex/ routes, mirroring relayed Claude.
Co-authored-by: Isaac <no-reply@databricks.com>
|
/ug-review |
Polly AI ReviewBlocking issuesNone substantiated. Security vulnerabilitiesNone substantiated in the changed code. Native Codex authentication behavior was not exercised. Non-blocking notes
ApproachThe existing relay handler, token cache, and child-process lifecycle are appropriate building blocks. No broader refactor is needed. Managed-conflict detection should be checked against Windows’ documented provider-replacement behavior. SummaryDiff size (computed): 8 files; +383 / -50 lines (433 changed text lines); 0 binary files.
Shares use additions + deletions, including generated text and lockfiles. Binary files have no line count. Tests include fixtures/helpers under test paths and colocated test/spec files; categories are path-based, not coverage measurements. ChangesThe change enables The implementation, tests, and ownership documentation support that outcome. No dependencies, lockfiles, generated files, or shared test fixtures change. The size is proportionate; consolidating the two proxy-construction scenarios would remove duplicate setup without reducing coverage. TestsTest-by-test assessmentAll changed tests are additions. No existing tests or assertions are removed. The table also assesses the new inline setup.
The most useful missing regression is a combined relay-plus-OTLP launch, including failure after the relay starts. Extend the existing launch component scenario rather than adding a separate E2E suite. The login test also needs realistic success and failure responses. Existing shared proxy tests cover refresh, retries, streaming, rejection, and loopback transport; duplicating that matrix is unnecessary. A live check would uniquely establish native Codex configuration precedence and deployed subscription authentication. No tests were executed during this review. The PR reports 1927 passing tests across the six named test files and a clean For manual verification in an isolated profile, run ScopeNo unrelated changes were found. Provider parsing, eligibility, configuration ownership, login handling, proxy lifecycle, tests, and documentation all contribute to CLI subscription relay support. Desktop implementation remains outside this diff. Automated review by Polly · workflow run |
httpx adds Accept-Encoding: gzip, deflate by default, so the gateway compressed responses that the proxy relays raw. Codex sends no Accept-Encoding and can't decode gzip, so it printed error bodies as binary. Ask for identity unless the client set its own encoding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Treat any managed model_providers.Databricks entry in Windows requirements.toml as a relay conflict, since that file replaces the whole provider entry. Fold the Codex relay proxy tests into one that runs through the bound handler, and model login success/failure realistically. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🥞 Stacked PR
Use this link to review incremental changes.
Summary
ug codex --provider <mps>now works with a relayed OpenAI Model Provider Service ({"openai": {"relayed": {}}}, created by the "ChatGPT/Codex Subscription" option in databricks-eng/universe#2891795). Codex runs on the developer's own ChatGPT subscription through AI Gateway, the same way relayed Claude Code uses a Claude subscription.codex, and a relayed Anthropic service only byclaude, as before.requires_openai_auth = trueand has noug auth-tokencommand, so Codex sends its own ChatGPT login (Authorization+ChatGPT-Account-ID). ug never reads that token. Codex rejects anauthcommand combined withrequires_openai_auth, so a relayed block can't keep the command.start_relay_proxy(..., codex=True), upstreamai-gateway/codex/, the plain handler). It adds the Databricks token inX-Databricks-AI-Gateway-Tokenon the/codex/v1/responsesand/codex/v1/modelsswap routes (databricks-eng/universe#2853663, #2854855). Codex's-cprovider points at the bound port, and the proxy can run alongside the OTLP proxy for one child.Accept-Encoding: identitywhen the client sent none. Otherwise httpx's default gzip request reaches the gateway, and the relayed raw body comes back compressed. Codex can't decode gzip and would print error bodies as binary.codex login statusmust report a ChatGPT login (an API key doesn't count); otherwise ug runscodex login./etc/codex/managed_config.toml(or Windowsrequirements.toml). If that file definesmodel_provideror the Databricks provider'sbase_url/auth, which would beat the-cflags, configure fails and asks you to runug revertor contact your admin, matching relayed Claude.OAUTH_TOKEN, since ug has no ChatGPT token and Codex lists models through the proxy. Smart routing with a relayed provider is refused.The Codex desktop app half is in the next PR in this stack.
Testing
tests/test_databricks.py,tests/test_gateway_proxy.py(including the real upstream join/v1/responses→{ws}/ai-gateway/codex/v1/responses) andtests/test_agent_codex.py(relayed overlay, staleauthpruned, managed conflicts and the relay-compatible scope, launch login and proxy wiring, no catalog fetch, smart-routing refusal).pytest tests/test_databricks.py tests/test_gateway_proxy.py tests/test_agent_codex.py tests/test_cli.py tests/test_agent_claude.py tests/test_agents_init.pywith theENABLE_SMART_ROUTING_*/SMART_ROUTER_NAME/UG_AUTO_UPGRADE_AGENTenv vars unset: 1927 passed.just lintclean.enableOpenAiRelayedAuthon, but this machine has no ChatGPT login and its managed Codex file pins the default provider.This pull request and its description were written by Isaac.