Skip to content

feat(codex): opt-in to use default ~/.codex config dir (fixes auth revocation war, supersedes #5594) - #6577

Closed
nwparker wants to merge 2 commits into
mainfrom
nwparker/fix-5370
Closed

nwparker wants to merge 2 commits into
mainfrom
nwparker/fix-5370

Conversation

@nwparker

@nwparker nwparker commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

🧑‍🤝‍🧑 Impact & ELI5

1) What's broken today (ELI5). If you use the OpenAI Codex CLI both inside Orca and outside Orca (in a plain terminal, a scheduled job, or another tool) with the same single ChatGPT/OpenAI account, your Codex login silently breaks. OpenAI only allows one active login per account, but Orca quietly keeps its own private Codex login in a separate hidden folder. So Orca and your normal ~/.codex login keep kicking each other out — like two phones signed into the same account where each one logs the other off the moment it checks in. The nasty part: Codex still says "Logged in," so you can't tell anything is wrong until a command suddenly fails with "token revoked." This hits the (relatively niche) group of power users who run Codex in multiple places on one account, but for them it's a real blocker — background/scheduled Codex jobs fail intermittently and it's extremely hard to diagnose. A previous ~/.zshenv workaround helped terminals but Orca's always-running background checker kept re-triggering the fight.

2) What this PR does (ELI5). It adds a new opt-in toggle — Settings → Accounts → Codex → "Use default Codex config directory". Flip it on and Orca stops keeping its own separate Codex login; instead it uses your normal ~/.codex login, the same one your terminal and other tools use. Crucially, it also tells Orca's background "how much quota do I have left?" checker to stop poking the private login folder, since that background checker was the thing secretly re-igniting the fight even after the manual workaround. Oh, so Orca now shares your one real Codex login instead of secretly maintaining a rival second one that logs you out.

3) Opt-in mode contract — honest answer. The toggle is OFF by default, so nobody's current behavior changes unless they choose to enable it. When it is on, host Codex has exactly one source of truth: the user's system ~/.codex. In that mode Orca intentionally does not own, switch, re-authenticate, or preview separate host managed Codex homes; stale host add/select/re-auth calls are rejected so no hidden path can spawn Codex against a rival host home. This is the contract of default-home mode, not an unfinished host hot-swap implementation. Turn the toggle off to use Orca's host managed multi-account switching again. WSL managed Codex accounts still work and keep their own managed homes. SSH/remote paths are untouched, and for everyone who leaves the toggle off this PR is a no-op.


Summary

Fixes #5370

Orca injects a private managed CODEX_HOME (~/Library/Application Support/orca/codex-runtime-home/home) into Codex processes. For a single OpenAI/ChatGPT account, OAuth enforces one active session, so two independently-refreshing homes (Orca's managed home and the user's real ~/.codex) revoke each other's single-use refresh tokens — silently breaking non-Orca Codex usage. The refresh is driven not only by interactive Codex but by Orca's background quota poller, which spawns the real codex binary against the managed home; that daemon-side session is why the issue persists even after the ~/.zshenv workaround.

This adds an opt-in "Use default Codex config directory" setting under Settings > Accounts > Codex. When enabled, Codex launched inside Orca resolves the user's system ~/.codex instead of Orca's managed home:

  • Terminals / daemon-host PTYs: all three buildPtyHostEnv call sites OR in isCodexDefaultHomeEnabled, so skipCodexHomeEnv strips CODEX_HOME/ORCA_CODEX_HOME.
  • Background quota poller + host launches (the revocation driver): prepareForRateLimitFetch and the host branch of prepareForCodexLaunch return null when the setting is on. null makes the rate-limit fetcher resolve ~/.codex and tells the commit-message agent to inject no CODEX_HOME, and it skips the managed-home sync so Orca never spawns Codex against the managed home to drive a token refresh.
  • Managed-account surfaces while enabled: host managed add/select/re-auth actions are paused in Settings, hidden from the status-bar switcher, and guarded in the main process. Inactive host managed-home quota previews are skipped because the preview fetch can spawn Codex/app-server against that separate home and refresh its token. WSL managed accounts and WSL previews remain available.

Default is off, preserving today's managed-home behavior and Codex account switching. When enabled, host default-home mode is an explicit auth-source contract: host Codex uses ~/.codex only, and Orca does not switch or refresh separate host managed homes. WSL managed accounts stay managed.

Supersedes community PR #5594

This takes over #5594 (does not close it; original author credited via Co-authored-by). Changes made on top of the original PR:

  1. Locale scope fixed: re-derived the i18n changes from current main — dropped the entire out-of-scope "Create PR" status-message block (and the malformed h3i4j5k607 key) that feat(codex): opt-in setting to use your default ~/.codex config directory #5594 introduced into en/es/ja/ko/zh. Kept only the new Codex keys + accounts-search keys, then ran pnpm run sync:localization-catalog so all five locales stay at parity. No merge conflict and no reintroduction of already-present keys.
  2. Closed the background-revocation gap that feat(codex): opt-in setting to use your default ~/.codex config directory #5594 left unaddressed (gated prepareForRateLimitFetch / host prepareForCodexLaunch), and added a test for it.
  3. Sharpened the setting description to state it also stops the background managed-home quota refresh — the mechanism that drives the revocation war.
  4. Defined the default-home mode contract: default-home mode now pauses only host managed Codex account switching, preserves WSL managed accounts, skips inactive host managed-home previews, and guards stale host account mutations in the main process.

Screenshots

Off (default) On
Toggle in Codex section, system-default managed home preserved Toggle on → Codex resolves ~/.codex, background poller stops touching the managed home

Before/after screenshots and unit-test output are attached as a PR comment (validated live over CDP in the running dev app — see comment).

Testing

  • pnpm lint (oxlint, scoped to changed files — clean)
  • pnpm typecheck (tsconfig.node.json + tsconfig.tc.web.json + tsconfig.tc.cli.json — clean)
  • pnpm test (ran src/main/ipc/pty.test.ts and src/main/codex-accounts/runtime-home-service.test.ts — 265 passing incl. 3 new; plus rate-limits/codex-accounts service + text-generation suites — 112 passing)
  • pnpm build (not run; no build-affecting changes — type/lint clean)
  • Added high-quality regression tests: PTY env coverage, runtime-home host default-home coverage, inactive host preview filtering with WSL preservation, status-bar host/WSL grouping, and service-level guards that reject host add/select/re-auth while allowing WSL selection.
  • Localization catalog parity verified (verify-localization-catalog.mjs passes with no diff).
  • Electron repro over CDP: opened Settings > Accounts > Codex, toggled the new switch through the real UI — aria-checked flips and codexUseDefaultConfigDir persists to the store and to disk (verified via fetchSettings IPC round-trip). No render crash.

AI Review Report

Reviewed the diff adversarially (treating the adopted PR author as untrusted) for correctness, edge cases, cross-platform behavior, security, and scope.

  • Cross-platform (macOS/Linux/Windows): verified. No e.metaKey / path-separator assumptions added. The PTY change ORs a boolean ahead of the existing WSL/Windows-shell conditions, preserving prior behavior when off. WSL rate-limit/launch paths return before the new host gate, so WSL homes are untouched. null returns flow correctly through getCompatibleSelectedCodexHomePath (null→null), the rate-limit fetcher (getCodexHomePath → ~/.codex), and the commit-message agent (no CODEX_HOME injected).
  • SSH / remote: the managed CODEX_HOME injection only happens for local + daemon-host terminals (buildPtyHostEnv is not on the SSH spawn path); remote shells use the remote machine's own ~/.codex. So the revocation war is inherently a local-machine problem and the fix is correctly scoped there — the description does not over-claim SSH coverage.
  • Provider-agnostic: change is Codex-auth-specific and does not touch GitHub/GitLab review code.
  • Flagged + addressed: the original PR's locale block was out of scope and malformed; re-derived. The background poller gap meant the fix was incomplete; closed it.

Security Audit

  • No new attack surface. The change only reads a boolean setting and short-circuits to null/strips env. No eval, no new spawn/exec, no network calls, no new dependencies, no path traversal, no secret reads added.
  • Reduces exposure: stops Orca from spawning Codex against the managed home in the background, which is the behavior that was revoking the user's ~/.codex OAuth session.
  • Adopted code re-verified as benign; auth.json continues to be written 0o600 by existing code paths (unchanged).

Default-home mode contract

Follow-up audit for zero-tradeoff alternatives:

  • Treating system ~/.codex as a managed account can only represent the account currently logged in there. Switching to any other host account still requires either setting CODEX_HOME away from ~/.codex or overwriting ~/.codex/auth.json with another account's tokens.
  • Explicit per-host account binding can label or verify the current ~/.codex identity, but it cannot make Codex run as a different host account while Codex is still reading ~/.codex.
  • Host managed quota previews are not guaranteed read-only: the preview path can spawn Codex/app-server against the separate managed home, and Codex may refresh that home's OAuth token. For the same OpenAI account, that is the exact revocation mechanism this opt-in disables.

So the safe contract is: default-home mode means host Codex uses the system ~/.codex identity only. Host managed switching/previews resume when the toggle is off. WSL managed account switching remains available because WSL uses separate WSL runtime homes rather than the host ~/.codex.

Made with Orca 🐋

… revocation war

Fixes #5370.

Orca injects a private managed CODEX_HOME into Codex processes. For a single
OpenAI/ChatGPT account, OAuth enforces one active session, so two independently
refreshing homes (Orca's managed home and the user's ~/.codex) revoke each
other's single-use refresh tokens — silently breaking non-Orca Codex usage.
The refresh is driven both by interactive Codex and by Orca's BACKGROUND quota
poller, which spawns the real codex binary against the managed home.

Adds an opt-in "Use default Codex config directory" setting (Settings >
Accounts > Codex). When enabled:
- PTY launches inject no CODEX_HOME (all three buildPtyHostEnv sites OR in
  isCodexDefaultHomeEnabled), so terminals resolve ~/.codex.
- The background quota poller and host Codex launches resolve the system
  ~/.codex home instead of spawning codex against the managed home — closing
  the revocation gap that persisted even after the ~/.zshenv workaround.

Supersedes community PR #5594: re-derives the locale changes (drops the
out-of-scope "Create PR" status-message block, keeps only the new Codex keys),
closes the background-revocation gap left unaddressed by the original PR, and
sharpens the setting description to state it also disables the managed-home
quota refresh.

Co-authored-by: Eilon Goldberg <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@nwparker, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 12 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 22d389f8-150f-4e80-9354-63972feb28b4

📥 Commits

Reviewing files that changed from the base of the PR and between e51b2df and 6040d44.

📒 Files selected for processing (21)
  • src/main/agent-hooks/managed-agent-hook-controls.ts
  • src/main/codex-accounts/inactive-codex-rate-limit-accounts.test.ts
  • src/main/codex-accounts/inactive-codex-rate-limit-accounts.ts
  • src/main/codex-accounts/runtime-home-service.test.ts
  • src/main/codex-accounts/runtime-home-service.ts
  • src/main/codex-accounts/service.test.ts
  • src/main/codex-accounts/service.ts
  • src/main/index.ts
  • src/main/ipc/pty.test.ts
  • src/main/ipc/pty.ts
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/renderer/src/components/settings/accounts-search.ts
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/renderer/src/components/status-bar/status-bar-runtime-groups.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/constants.ts
  • src/shared/types.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker

Copy link
Copy Markdown
Contributor Author

Evidence

Unit / regression tests

$ ./node_modules/.bin/vitest run --config config/vitest.config.ts \
    src/main/ipc/pty.test.ts src/main/codex-accounts/runtime-home-service.test.ts

 Test Files  2 passed (2)
      Tests  265 passed (265)

New tests (verbose, all passing):

✓ pty.test.ts > registerPtyHandlers > spawn environment >
    skips the managed Codex home when codexUseDefaultConfigDir is enabled
✓ pty.test.ts > registerPtyHandlers > spawn environment >
    still injects the managed Codex home when codexUseDefaultConfigDir is off
✓ runtime-home-service.test.ts > CodexRuntimeHomeService >
    targets the default ~/.codex home for launch and quota fetch when the opt-in is on
  • The PTY test asserts that with the setting on, a spawned terminal has no CODEX_HOME/ORCA_CODEX_HOME even when a managed home is selected and ambient CODEX_HOME=/tmp/ambient-... values are present (they are stripped, not leaked). With the setting off, the managed home is still injected.
  • The runtime-home test asserts that with the setting on, prepareForRateLimitFetch() and prepareForCodexLaunch() both return null — i.e. the background quota poller and host launches resolve the system ~/.codex home instead of spawning Codex against the managed home (which is what revoked the user's ~/.codex OAuth session).

Also green: oxlint (changed files), tsgo (node + web + cli configs), and verify-localization-catalog.mjs (all 5 locales at parity, no diff).

Live Electron validation (CDP, dev build of this branch)

Attached to the running dev instance of nwparker/fix-5370 over CDP, opened Settings > Accounts > Codex, and exercised the new toggle through the real UI:

  • The "Use default Codex config directory" switch renders in the Codex section with the corrected description ("…Also stops Orca's background quota poller from refreshing the managed home, so it no longer revokes your ~/.codex session…").
  • Clicking the switch flips aria-checked and persists codexUseDefaultConfigDir to the store and to disk (confirmed via a fetchSettings IPC round-trip returning true).
  • No render crash; matches the styling of neighboring toggles.

Before (off — default): the switch renders unfilled in the Codex section; Orca keeps its managed CODEX_HOME.

After (on): the switch renders filled/enabled; aria-checked="true" and codexUseDefaultConfigDir: true persisted via IPC.

Screenshots were captured live (validation-screenshots/codex-toggle-off-clean.png / codex-toggle-on-clean.png). They are intentionally not committed (repo rule: never commit PR evidence images) and inline upload requires gh-attach, which is disallowed here — the CDP-verified state above is the load-bearing proof. A reviewer can reproduce in ~30s: Settings > Accounts > Codex > toggle "Use default Codex config directory".

Before/after reasoning

  • Before: with a managed account (or even system-default), Orca's background quota poller spawns codex against the managed CODEX_HOME, refreshing that home's single-use OAuth token. Because OpenAI enforces one active session per account, this revokes the token in ~/.codex, so env -u CODEX_HOME codex exec outside Orca starts failing with "refresh token already used / revoked".
  • After (setting on): terminals inject no CODEX_HOME, and the background poller + host launches resolve ~/.codex directly (no codex spawn against the managed home), so the two homes no longer fight over the single session.

@nwparker

Copy link
Copy Markdown
Contributor Author

Update: default-home tradeoff narrowed

Pushed 6040d44873 to reduce the caveat from "Codex hot-swap/auth-sync disabled" to a host-only pause:

  • host default-home mode now treats host Codex as system ~/.codex in Settings/status bar and disables host managed add/select/re-auth controls without deleting the saved host selection
  • stale/direct host managed add/select/re-auth calls are rejected in the main process before any codex login or managed-home sync can run
  • inactive host managed-home quota previews are skipped while default-home mode is on
  • WSL managed Codex accounts remain selectable and their inactive quota previews still run

Tradeoff status: not fully zero for host. Preserving host hot-swap while using the real ~/.codex would require Orca to mutate/copy the user's real Codex auth during account switches, which would introduce a larger auth-ownership risk. The remaining caveat is now limited to host managed account switching while the opt-in is enabled; default-off behavior and WSL managed accounts are preserved.

Validation:

  • vitest run --config config/vitest.config.ts src/main/codex-accounts/service.test.ts src/main/codex-accounts/inactive-codex-rate-limit-accounts.test.ts src/renderer/src/components/status-bar/status-bar-runtime-groups.test.ts -> 31 passing
  • vitest run --config config/vitest.config.ts src/main/ipc/pty.test.ts src/main/codex-accounts/runtime-home-service.test.ts -> 265 passing
  • pnpm run sync:localization-catalog
  • pnpm run verify:localization-coverage
  • pnpm exec oxlint ...changed TS/TSX files...
  • pnpm run typecheck
  • git diff --check

@nwparker

Copy link
Copy Markdown
Contributor Author

Follow-up audit: host default-home contract

Did one more pass on whether host managed switching/previews can safely stay available while default-home mode is enabled.

Conclusion: host default-home and host managed hot-swap are logically mutually exclusive unless Orca takes ownership of the user's real ~/.codex/auth.json.

Why:

  • Treating ~/.codex as a managed account can only represent the account currently logged in there; switching to another host account still requires either setting CODEX_HOME away from ~/.codex or overwriting ~/.codex/auth.json.
  • Explicit host account binding can label/verify the current system identity, but it cannot make Codex run as a different account while Codex is still reading ~/.codex.
  • Host managed previews are not guaranteed read-only: the preview path can spawn Codex/app-server against the separate managed home, and Codex may refresh that OAuth token. For the same OpenAI account, that is the revocation mechanism this opt-in disables.

No code change from this pass. I updated the PR body to frame the behavior as an explicit opt-in mode contract: when enabled, host Codex uses the system ~/.codex identity only; host managed switching/previews resume when the toggle is off; WSL managed accounts remain available.

@nwparker

Copy link
Copy Markdown
Contributor Author

Closing as superseded after checking current main.

Superseded by merged #9501 and the WSL direct-home cutover in #16854. System-default Codex launches now use the real system home without injecting a managed CODEX_HOME, while managed accounts retain their separate homes. This older opt-in toggle achieves the earlier goal by disabling account controls that the shipped routing now preserves.

Closing this PR only; its branch is being retained.

@nwparker nwparker closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant