Skip to content

fix(codex): persist outgoing managed tokens before real-home lane takeover (PR-C) - #9175

Closed
brennanb2025 wants to merge 2 commits into
brennanb2025/codex-home-consolidationfrom
brennanb2025/codex-ma-c-readback
Closed

brennanb2025 wants to merge 2 commits into
brennanb2025/codex-home-consolidationfrom
brennanb2025/codex-ma-c-readback

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

What

Guarantees the outgoing managed Codex account's refreshed OAuth token is read back (persisted to its canonical per-account home) before the real-home / system-default lane takes over the shared runtime home — on the launch path, not only on the explicit select path. Closes GAP-6 in the real-home consolidation work.

Why

prepareForCodexLaunch (runtime-home-service.ts) returns null early for the real-home lane, before syncForCurrentSelection runs. The outgoing managed account's refreshed-token read-back normally happens inside doSelectAccount → syncForCurrentSelection. Any path that drops the selection to the system default without going through syncForCurrentSelection — e.g. the selection nulled out-of-band, or the auto-deselect when an active managed account's auth.json goes missing — hands off to the real-home lane while a freshly Codex-refreshed token sits unpersisted in the shared runtime home. On the next real-home launch that token is silently dropped → token loss.

Change

  • New readBackOutgoingManagedHostAccountBeforeSystemDefault() runs the managed→system-default transition (via syncForCurrentSelection) when a managed account is still recorded as synced (lastSyncedAccountId !== null), and is invoked right before the real-home lane's early return null.
  • The real-home lane implies host === null, so this restores only Orca's runtime mirror from ~/.codex — it never writes the real ~/.codex (lastSyncedAccountId !== null routes to the snapshot-restore branch, never the writeSystemDefaultAuth path).
  • No-op once the selection has already been reconciled to the system default, so the normal explicit-select path does not double-write.

Test evidence

npx vitest run --config config/vitest.config.ts src/main/codex-accounts/runtime-home-service.test.ts → 89 passed (86 existing + 3 new). pnpm run typecheck:node → clean.

New tests (all sandboxed — never touch the real ~/.codex):

  1. managed→default at launch (not via select) still persists a mirror-refreshed token to the outgoing account's home. Verified as a real guard: with the fix removed this test fails (outgoing home keeps the stale token).
  2. auto-deselect on missing managed auth persists the previous account's refresh before handing off to the real home, and the follow-up real-home launch stays a no-op.
  3. normal (explicit) deselect path does not re-run the transition on the subsequent real-home launch (spy asserts syncForCurrentSelection is not called again) → no double-write / no regression.

Guardrails

  • Never mutates the real ~/.codex (asserted; restore path only reads it and writes Orca's runtime mirror).
  • No regression to flag-OFF or the normal select path (covered by existing suite + test 3).
  • No max-lines disables; follows AGENTS.md / CLAUDE.md.

Matrix rows covered

  • Row 3 — managed → system-default transition at launch (real-home lane), token read-back preserved.
  • Row 6 — auto-deselect (active managed auth.json missing) → system-default handoff, outgoing refresh preserved.

…eover (PR-C)

prepareForCodexLaunch returns null early for the real-home / system-default
lane before syncForCurrentSelection runs. If a managed account is still
recorded as synced when the selection has dropped to the system default
(nulled without a sync pass, or auto-deselect on missing managed auth), a
Codex-refreshed token stranded in the shared runtime home is never persisted
to its canonical per-account home -> token loss.

Read the outgoing managed account's refreshed token back before the real home
takes over. The real-home lane implies host === null, so running the
managed->system-default transition restores only Orca's runtime mirror from
~/.codex and never writes the real ~/.codex. It is a no-op once the selection
has already been reconciled, so the normal select path does not double-write.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing as superseded: #9501 (real-home routing + self-contained multi-account homes) explicitly lists this draft as superseded in its description, and that consolidation merged and shipped in v1.4.149 stable.

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