Repository navigation
Conversation
Codex Review Summary: ❌ FailedThis 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 usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
roboomp
left a comment
There was a problem hiding this comment.
Thanks @sjawhar for the thorough path inventory and the red/green test matrix. review:p2: needs a maintainer call.
- The
ANTHROPIC_BASE_URL/Foundry half is a real fix. Discovery and web search now go where chat already goes, and Foundry mTLS is applied to them too.resolveDirectAnthropicBaseUrlkeeps the same precedence it had before. - The
OPENAI_BASE_URLhalf changes what an existing variable means: it was a fallback for models with no address and now overridesapi.openai.comfor every built-inopenairequest. Users who already export it for other tools will silently send omp's OpenAI key to that host. Maintainer: keep it, or drop that half as the PR offers? - Should-fix: no CHANGELOG entries in any of the 5 touched packages, and
readPemValueduplicatesresolveExtraCaintls-fetch.ts. Scope: theNODE_EXTRA_CA_CERTSshim on every path is a separate behavior change and could land on its own.
| | Variable | Default / behavior | | ||
| | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | `OPENAI_BASE_URL` | Base URL fallback for OpenAI-compatible requests when the model/provider supplies a default | | ||
| | `OPENAI_BASE_URL` | Replaces `https://api.openai.com/v1` on each request of a built-in `openai` model (chat, compaction, model discovery, web search, embeddings, transcription, image generation, judgments). The request is the same as the request for a provider-file `baseUrl` with this value. A provider-file `baseUrl` that is not `https://api.openai.com/v1` wins. The paths that work only with OpenAI's own service stay off: file upload, and stateful Responses chaining by default. Also the fallback address of an OpenAI-compatible model that has no address. `openai-codex` keeps its own address | |
There was a problem hiding this comment.
Maintainer call (default-behavior change). Before this PR OPENAI_BASE_URL was read only in resolveOpenAIRequestSetup when a model had no baseUrl, so it never moved a built-in openai row. Now resolveOpenAIVendorBaseUrl (packages/catalog/src/compat/vendor-base-url.ts:72-79) replaces https://api.openai.com/v1 everywhere, including an explicit provider-file baseUrl: https://api.openai.com/v1. A user who exports OPENAI_BASE_URL for the OpenAI SDK or another tool (common in shell rc files) will start sending omp's OPENAI_API_KEY and traffic to that host, and lose stateful Responses chaining and file upload, with no opt-in. The ANTHROPIC_BASE_URL/Foundry half matches chat's existing behavior; this half needs explicit sign-off, or should be split out as the PR body offers.
| * A path that does not exist throws {@link PemPathError}; other I/O errors | ||
| * bubble. | ||
| */ | ||
| export function readPemValue(value: string | undefined, name: string): string | undefined { |
There was a problem hiding this comment.
should-fix (duplication). readPemValue re-implements resolveExtraCa (line 85) in the same file: same inline-vs-path detection, same \\n expansion, same ENOENT mapping, but a different error class (PemPathError vs ExtraCaError) and a separate cache (pemValueCacheKey vs cacheKey). After this PR NODE_EXTRA_CA_CERTS is read by readPemValue in anthropic-http-options.ts (Foundry chat) and by resolveExtraCa on every path that now goes through wrapFetchForExtraCa, with different path heuristics (looksLikeFilePath vs any non-PEM value is a path). Please make resolveExtraCa call readPemValue (one error class, one reader) instead of keeping two readers for one variable.
| const result = await generateImage(withRegistryHeaders(model, registry), request, { | ||
| apiKey: registry.resolver(carrier ?? model, sessionId), | ||
| fetch: ctx.fetch ?? fetch, | ||
| fetch: ctx.fetch, |
There was a problem hiding this comment.
Scope question. This change, and the ?? wrapFetchForExtraCa(fetch) swaps in embeddings, transcription, judgment, compaction, both web searches and hosted images, add NODE_EXTRA_CA_CERTS trust to paths that are unrelated to the base-URL variables in the title. It looks right on its own, but it is a separate behavior change. Could it be split into its own PR (with its own changelog line) so the OPENAI_BASE_URL decision above does not block it?
| @@ -0,0 +1,152 @@ | |||
| /** | |||
There was a problem hiding this comment.
should-fix (convention). No CHANGELOG.md entry under ## [Unreleased] in any touched package (ai, catalog, coding-agent, agent, utils), and the PR checklist leaves that box unchecked. The OPENAI_BASE_URL meaning change in particular needs a user-facing line (### Changed, or ### Breaking Changes if kept), plus ### Fixed lines for ANTHROPIC_BASE_URL/Foundry discovery and web search, with the PR link and @sjawhar credit per AGENTS.md.
2e347d6 to
8a734e1
Compare
…es on every path OPENAI_BASE_URL and ANTHROPIC_BASE_URL now replace the vendor address on every request that sends the vendor key for a built-in model. Before this change, ANTHROPIC_BASE_URL moved only Anthropic chat, and OPENAI_BASE_URL moved no request of a built-in openai model. Responses, Chat Completions, model discovery, web search, remote compaction, image generation, embeddings, transcription and the Decisions judge sent the key to api.openai.com. Anthropic model discovery and web search sent it to api.anthropic.com. In Foundry mode, web search sent the key to api.anthropic.com without the client certificate. One resolver for each vendor, in packages/catalog/src/compat/vendor-base-url.ts, reads the variables, and Foundry mode's FOUNDRY_BASE_URL with its client certificate. A provider-file baseUrl other than the vendor's own address wins, as with XAI_BASE_URL. A built-in openai model under the variable is built again at that address, so its request is the request for a provider-file baseUrl with that value: no stateful Responses chaining by default, and no file upload. Discovered rows keep the built-in address, so the model cache stays valid after the variable is unset. Each of these paths now also trusts the CA in NODE_EXTRA_CA_CERTS, as chat does, when its caller gives no fetch of its own: it falls back to the shim of pi-utils, not to Bun's own fetch. The image tool no longer passes Bun's fetch down, so each image client falls back as before and hosted image generation takes the shim. A provider-file baseUrl already moves each of these paths. The variables did not, and no config makes web search, compaction, the judge, image generation, embeddings or transcription carry Foundry's client certificate or trust the NODE_EXTRA_CA_CERTS CA. For ANTHROPIC_BASE_URL and Foundry mode this is a defect in the library's own routing: chat follows them, and the other paths sent the key to api.anthropic.com. For OPENAI_BASE_URL the change gives the variable the meaning XAI_BASE_URL already has: it replaces the vendor address, where it was a fallback for a model with no address. A user who exports OPENAI_BASE_URL for another tool now also sends the requests of the built-in openai models there. It implements no ruling. Red to green: each row of vendor-base-url-paths.test.ts and openai-vendor-base-url-flags.test.ts whose request the change moves fails at the parent commit, where the request reaches the vendor host or sends without the CA, and passes here. Tests that assert a vendor's own address clear the variables through the test helpers, so they pass with the variables exported. Omp-Session: 01a22d4b-90a5-7749-872a-63a6da9e619f
8a734e1 to
3263b1f
Compare
What
my agents found this while optimizing our fleet
OPENAI_BASE_URLandANTHROPIC_BASE_URLnow replace the vendor address on every request that sends the vendor key for a built-inopenaioranthropicmodel. Before,ANTHROPIC_BASE_URLmoved only Anthropic chat, andOPENAI_BASE_URLmoved no request of a built-inopenaimodel, because every built-in row carrieshttps://api.openai.com/v1and the variable was read only when a model had no address.One resolver for each vendor, in
packages/catalog/src/compat/vendor-base-url.ts, reads the variables. A provider-filebaseUrlother than the vendor's own address still wins, as withXAI_BASE_URL. A built-inopenaimodel under the variable is built again at that address, so its request is the request a provider-filebaseUrlwith that value gets: no stateful Responses chaining by default, and no file upload. Discovered rows keep the built-in address, so the model cache stays valid after the variable is unset.In Foundry mode (
CLAUDE_CODE_USE_FOUNDRYwithFOUNDRY_BASE_URL), Anthropic model discovery and web search now followFOUNDRY_BASE_URLwith the client certificate ofCLAUDE_CODE_CLIENT_CERTandCLAUDE_CODE_CLIENT_KEY, as chat already did. File upload stays off there.Each of these paths now also trusts the CA in
NODE_EXTRA_CA_CERTS, as chat does, when its caller gives no fetch of its own: it falls back to thewrapFetchForExtraCashim ofpi-utils, not to Bun's ownfetch. The image tool no longer hands Bun'sfetchdown, so each image client falls back as before and hosted image generation takes the shim. A gateway behind a private CA then works on every path, not only on chat.Why
With either variable set, requests that send the key went to the vendor's host: Responses (HTTP and WebSocket), Chat Completions, model discovery, web search, remote compaction, hosted image generation, embeddings, transcription and the Decisions judge for
openai; discovery and web search foranthropic. A gateway's key then reachedapi.openai.comorapi.anthropic.com.A provider-file
baseUrlalready moves each of these paths, but nothing a user configures makes web search, compaction, the judge, image generation, embeddings or transcription carry Foundry's client certificate or trust theNODE_EXTRA_CA_CERTSCA. ForANTHROPIC_BASE_URLand Foundry mode this is a fix: chat already follows them. ForOPENAI_BASE_URLit is a change of meaning: the docs called it a fallback for a model with no address, and it now replaces the vendor address, asXAI_BASE_URLdoes. A user who exportsOPENAI_BASE_URLfor another tool now also sends the requests of omp's built-inopenaimodels there. If you would rather keep the old meaning forOPENAI_BASE_URL, say so and that half comes out of this pull request.Testing
Two new test files hold the change:
packages/coding-agent/test/vendor-base-url-paths.test.ts(one row for each path and state: the variable set, unset, a provider-filebaseUrlof another address, a provider-filebaseUrlof the vendor's own address, Foundry mode, andNODE_EXTRA_CA_CERTS) andpackages/ai/test/openai-vendor-base-url-flags.test.ts(the official-endpoint flags and Responses chaining).mainat 9b5b470, with no source change: 53 of the 99 path rows fail on their assertions (each request goes toapi.openai.comorapi.anthropic.com, or sends without the CA), the WebSocket row among them, and 4 of the 5 flag rows fail. No row fails on an import.CONNECTtoapi.openai.comorapi.anthropic.com. With the variables deleted, chat goes toapi.openai.comagain.mainat 9b5b470 and with this commit, once plain and once withOPENAI_BASE_URL,ANTHROPIC_BASE_URL,FOUNDRY_BASE_URLandCLAUDE_CODE_USE_FOUNDRYexported: type checks, lint and format pass in every package, and no test fails with this commit that passes onmain, except one run ofImageDescriptions > describes the newest images first…intest/utils/image-vision-fallback.test.ts. This change does not touch that file, and the test passed in nine of ten runs of the file alone. The existing tests that this change would break for a developer with the variables exported now clear them before each test, through one helper in each package's test helpers.bun checkpasses:bun run check:ts(lint, format and the type checks of every package) passes with this commit. The change touches no Rust file, so the Rust half does not run.