#201

fix(codex): ignore ambient API keys for local-subscription routes

OpenPerryLinkwants to merge intofrom

What changed

The Codex backend now follows the saved model route when it picks a credential. For a local route, it uses the machine-wide codex login and ignores ambient OPENAI_API_KEY and ANTHROPIC_AUTH_TOKEN values. If no Codex login exists, it fails with an actionable message instead of falling back to an unrelated key.

The route mode now travels with the agent config, so an explicit --model-auth selection or --ai-* override still takes precedence. Sandbox workers keep the existing brokered-key behavior because they have no machine-wide login.

Why

Fixes #193.

With a saved local-subscription route, buildCodexInvocation chose API-key mode whenever OPENAI_API_KEY was present in the shell. A .envrc that exports a key for another tool therefore routed Codex batches to that key's account. The batches failed with Quota exceeded even though the ChatGPT subscription was selected and working. #32 reported the same failure before the local route existed.

Verification

  • pnpm test:unit passes (62 files, 2391 tests)
  • pnpm -r build passes
  • pnpm lint passes
  • pnpm knip passes
  • pnpm test:bundle passes (29 tests)

The new packages/processor/src/__tests__/codex-invocation.test.ts fails on the old behavior with expected 'sk-ambient-unrelated' to be undefined and passes with this change. It covers three cases: a local route with an ambient key and a Codex login, a local route without a login, and a non-local route that still forwards its key.

Notes for reviewer

This PR covers the reported Codex path only. The Claude backend builds its own child environment and has a similar ambient-key path. This PR leaves that path unchanged so the fix stays scoped to the reported case; a separate PR can apply the same precedence there if that is wanted.

Explicit --ai-* provider overrides still take precedence over a saved local route, and the no-login test isolates HOME so it exercises the missing-login path even on machines that have run codex login.

Activity

4
vercel[bot]4d ago

@PerryLink is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

auto-maintain[bot]4d ago

🤖 auto-maintain review

Automated, advisory triage for @PerryLink's PR. Facts below are read from the GitHub API.

CheckResult
Author's merged PRs (this repo)0 — ⚠️ first-time contributor
Account established✅ (age 295d · 129 followers · 501 public repos)
Commits signed/verified✅ 2/2

Review panel: 🟢 low highest severity

deepsec maintainer code review: 🟢 low

No actionable defects found in the complete diff.

General code review: 🟢 low

No actionable correctness issues found in the complete diff.

Scanner and matcher quality: 🟢 low

No actionable scanner or matcher quality issues found.

Sandbox and credential boundaries: 🟢 low

Scoped credential-precedence fix: a saved local route now suppresses ambient OPENAI_API_KEY/ANTHROPIC_AUTH_TOKEN for the Codex child, with an explicit DEEPSEC_INSIDE_SANDBOX exemption so brokered sandbox keys still work; the throw happens before any tempdir/auth mirroring, no secret enters the error text or the agent env, and --ai-* override suppression matches the callers' route-resolution condition. The unchanged Claude ambient-token path is pre-existing and disclosed. No actionable credential- or sandbox-boundary defects found.

Durability and distributed state: 🟢 low

No actionable durability or distributed-state defects found in the complete diff.

Posted by auto-maintain. This automated code review is advisory; a human maintainer makes the call.