Repository navigation
fix(codex): preserve managed-account MCP .credentials.json on per-account-home migration (#8440) - #9461
Closed
brennanb2025 wants to merge 10 commits into
Conversation
…ount-home migration (#8440) Codex file-mode MCP OAuth tokens live in $CODEX_HOME/.credentials.json, keyed by MCP server URL with no account identity of their own. The legacy shared-mirror -> per-account-home migration only carried auth.json, so an existing managed account with authed MCP servers had its tokens stranded on upgrade and silently needed re-auth. Carry the shared mirror's .credentials.json into the same identity-proven per-account home alongside auth.json: only into the single uniquely-matched active account (no cross-account leak), only when the destination has none yet (never clobber a newer file the account authed in its own home), atomic 0600, absent-source no-op. New MCP auth already lands in the per-account home since that home is CODEX_HOME.
…Windows
The harness built its app with execFileSync('npx', ['electron-vite', ...]),
but npx resolves to a .cmd shim on Windows that execFileSync cannot launch
(ENOENT), so the harness could not build its own app there and required
--skip-build with a prebuilt out/main/index.js.
Extract resolveElectronViteBuildCommand(repoRoot): it runs the repository-local
electron-vite JS entry (node_modules/electron-vite/bin/electron-vite.js) with
the current Node binary (process.execPath), which resolves identically on
macOS, Linux, and Windows with no shell. It throws a clear error if the local
entry is missing (install deps or pass --skip-build). --skip-build behavior is
unchanged.
Add regression coverage asserting the build command uses process.execPath and
the repo-local JS entry (not npx), and that a missing entry fails clearly.
… marker The auth carry and the MCP .credentials.json carry (#8440) shared one existence-only v1 marker, so any build that stamped the auth-only marker first would strand the MCP store forever. The MCP carry now concludes via its own per-account-mcp-creds-migration-v1.json marker and runs even when the auth marker is already present; ordering is code-enforced instead of landing-discipline-enforced. Also isolate per-account read failures: one stale or deleted account home no longer aborts the whole migration. The broken account stays in the unique-identity ambiguity gate via its stored fields but is never read or written, so the active account still migrates.
… bytes A raw JSON.parse SyntaxError from loadOAuthCredentials could carry auth file fragments into logs and the add/reauth error surface. Throw a sanitized error instead; filesystem errors still propagate unchanged.
…oot guard The main-process guard now refuses to start with ORCA_E2E_USER_DATA_DIR set but the real user home, and this was the one caller not updated — the temporary pairing runtime crashed before emitting its pairing URL.
Resolve symlinks before the disposable-root containment checks so a symlinked temp parent cannot smuggle the throwaway home inside the primary home, and give the final cleanup rm Windows retry/force so a briefly lingering codex handle cannot strand the credential-bearing root.
The Windows gate-D run proved strict zero-event whole-profile containment is structurally unreachable with the real-home flag ON: system-default spawn sites deliberately delete CODEX_HOME so native codex resolves the real ~/.codex, and on Windows the binary ignores the USERPROFILE sandbox. Its own volatile runtime churn (root sqlite/WAL/SHM, tmp/, log/) is the shipped Phase-1 design, not a candidate defect. --lane-aware-containment records those designed events without aborting while every other real-home write — auth.json, config.toml, .credentials.json, hooks.json, sessions/, anything unknown — remains a hard violation and still aborts the run. Default behavior is unchanged (strict); the absolute zero-event claim stays carried by macOS runs, where HOME does sandbox native codex.
… off --system-default-real-home off seeds and env-pins the flag OFF so every codex spawn gets an explicit managed CODEX_HOME and native codex never resolves the OS profile. This is the only Windows configuration where the strict zero-event whole-profile tripwire is reachable, and it matches the stable-rollout default; flag-ON runs keep lane-aware classification.
…onale The rollout ships all codex-home changes at once (no phased rollout), so flag OFF is the emergency kill-switch lane, not the stable default.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem (#8440)
Managed Codex accounts moved from a shared runtime-home mirror to per-account homes (each home = that account's
CODEX_HOME). The legacy→per-account migrationmigrateLegacySharedAuthToPerAccountHomecarried onlyauth.jsonfrom the shared mirror. Codex stores file-mode MCP OAuth tokens in$CODEX_HOME/.credentials.json(separate fromauth.json). So an existing managed account that had authed MCP servers got those tokens stranded on upgrade → its MCP servers silently need re-auth..credentials.jsonsemantics findingGround truth from the codex 0.144.5 binary (
rmcp-client/src/oauth.rs), corroborating #8440:mcp_oauth_credentials_store:file | keyring | auto | ephemeral.filemode →$CODEX_HOME/.credentials.json, entries keyed by{type,url,headers}under anMCP_OAUTHmap. It is MCP-server-scoped (keyed by server URL), NOT account-identity-scoped — the file carries no account identity claim of its own.keyringmode → global macOS Keychain service"Codex MCP Credentials"(notCODEX_HOME-scoped, unaffected). macOS default (auto→keyring) is why [Bug] Critical Bug: OAuth Login Not Persisting for MCPs in Orca Terminals #8440 was cannot-repro on standard macOS; file mode bites Linux/headless/SSH.Implication for migration: because the file has no identity to match on, we cannot independently identity-match it. The only proof that a shared mirror's
.credentials.jsonbelongs to a given account is the co-located, identity-provenauth.json. So we treat it strictly as a companion of the uniquely-identity-matchedauth.json.Chosen handling + why
Carry
.credentials.jsonfrom the shared mirror into the per-account home at the same proven-ownership gate that governsauth.json:matches.length === 1 && matches[0].account.id === activeHostAccountId(the shared mirror is uniquely proven to be the active account's) — so it lands in exactly one account's home, no cross-account leak. Ambiguous/duplicate identity → nothing carried..credentials.jsonalready present in the per-account home (a newer store the account authed in its own home going forward).auth.jsonwrite, so a crash can't leave a partial MCP store or widen perms on sensitive tokens.Going forward: new MCP auth for a managed account already lands in its per-account home, since that home is
CODEX_HOME. Covered by the "already-current" test (store carried without needing an auth rewrite).Files changed
src/main/codex-accounts/legacy-shared-auth-migration.ts— addhomePathto the trusted-account record;migrateSharedMcpCredentials()helper; invoke it at the proven-ownership gate before auth freshness branching.src/main/codex-accounts/legacy-shared-auth-migration.test.ts— 5 new sandboxed tests: carry into proven home (0600); carry when auth already-current; absent-source no-op; newer per-account file not clobbered; no leak to non-matching (ambiguous) account.Test evidence (sandboxed temp homes only — never touches real
~/.codex)npx vitest run --config config/vitest.config.ts src/main/codex-accounts/legacy-shared-auth-migration.test.ts→ 11 passed (6 existing + 5 new).src/main/codex-accounts/suite → 172 passed (8 files).pnpm run check:max-lines-ratchet→ OK.config/tsconfig.node.json→ clean (exit 0). Note: run with TS 5.9.2 via npx (repo pinstypescript@^7, native tsc unavailable in this worktree); change is simple typed additions.Landing note
This also needs porting to PR-E #9179 (the per-account
CODEX_HOMEchange) for landing — same migration seam and stranding risk.