Repository navigation
fix(codex): stop a locked auth.json from deleting a just-authenticated account (STA-4734) - #15279
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe change exports 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
…d account (STA-4734) A successful Codex login could be reported as a failure, and the rollback then deleted the managed home holding the credentials it had just written. Three reads on the add path answered "no credentials" from a read that had merely failed: - `service.ts` decided the login verdict with `existsSync(authJsonPath)`, which returns false for EPERM/EBUSY as readily as for ENOENT. The post-auth tree kill only arms after the watcher has already observed new credential bytes, so an unreadable file there is a lock, not a failed login. - `loadOAuthCredentials` read auth.json bare, so a denial surfaced as a generic error indistinguishable from a real one. - `importCodexAuthFromHome` turned an unreadable source file into "No Codex credentials found ... run `codex login` first" — advice to redo a login that had already succeeded. Each now classifies: only a definitive ENOENT/ENOTDIR means absent, everything else is `ManagedCodexHomeTemporarilyUnavailableError`. Classifying alone is inert, because the add path's rollback deletes the home for any error. `removeManagedHomeUnlessUnproven` holds the rollback back on an unproven failure — a kept home is a recoverable leak, a deleted one is permanent data loss. The mutation check for this is in the test: with the typed error but no rollback guard, the home is still destroyed. `isDefinitiveAbsence` is exported so the second credential lane reuses the host predicate instead of keeping its own copy of the errno allowlist.
Why: STA-4737 needs the same predicate from src/main/codex, which the CLI tsconfig project does not admit imports from codex-accounts into. Both branches now carry byte-identical copies so they merge cleanly in either order.
54fb213 to
384416e
Compare
|
Verdict: PASS No additional issues found. The reviewed changes preserve credentials when an auth.json read is indeterminate, while retaining cleanup and “missing credentials” behavior for definitive ENOENT/ENOTDIR cases; no follow-up code changes were needed from this review. Mutation checks
Verification and clean sweeps
|
…d account (STA-4734) (stablyai#15279) * fix(codex): stop a locked auth.json from deleting a just-authenticated account (STA-4734) A successful Codex login could be reported as a failure, and the rollback then deleted the managed home holding the credentials it had just written. Three reads on the add path answered "no credentials" from a read that had merely failed: - `service.ts` decided the login verdict with `existsSync(authJsonPath)`, which returns false for EPERM/EBUSY as readily as for ENOENT. The post-auth tree kill only arms after the watcher has already observed new credential bytes, so an unreadable file there is a lock, not a failed login. - `loadOAuthCredentials` read auth.json bare, so a denial surfaced as a generic error indistinguishable from a real one. - `importCodexAuthFromHome` turned an unreadable source file into "No Codex credentials found ... run `codex login` first" — advice to redo a login that had already succeeded. Each now classifies: only a definitive ENOENT/ENOTDIR means absent, everything else is `ManagedCodexHomeTemporarilyUnavailableError`. Classifying alone is inert, because the add path's rollback deletes the home for any error. `removeManagedHomeUnlessUnproven` holds the rollback back on an unproven failure — a kept home is a recoverable leak, a deleted one is permanent data loss. The mutation check for this is in the test: with the typed error but no rollback guard, the home is still destroyed. `isDefinitiveAbsence` is exported so the second credential lane reuses the host predicate instead of keeping its own copy of the errno allowlist. * refactor(codex): move the definitive-absence predicate to src/shared Why: STA-4737 needs the same predicate from src/main/codex, which the CLI tsconfig project does not admit imports from codex-accounts into. Both branches now carry byte-identical copies so they merge cleanly in either order.
…d account (STA-4734) (stablyai#15279) * fix(codex): stop a locked auth.json from deleting a just-authenticated account (STA-4734) A successful Codex login could be reported as a failure, and the rollback then deleted the managed home holding the credentials it had just written. Three reads on the add path answered "no credentials" from a read that had merely failed: - `service.ts` decided the login verdict with `existsSync(authJsonPath)`, which returns false for EPERM/EBUSY as readily as for ENOENT. The post-auth tree kill only arms after the watcher has already observed new credential bytes, so an unreadable file there is a lock, not a failed login. - `loadOAuthCredentials` read auth.json bare, so a denial surfaced as a generic error indistinguishable from a real one. - `importCodexAuthFromHome` turned an unreadable source file into "No Codex credentials found ... run `codex login` first" — advice to redo a login that had already succeeded. Each now classifies: only a definitive ENOENT/ENOTDIR means absent, everything else is `ManagedCodexHomeTemporarilyUnavailableError`. Classifying alone is inert, because the add path's rollback deletes the home for any error. `removeManagedHomeUnlessUnproven` holds the rollback back on an unproven failure — a kept home is a recoverable leak, a deleted one is permanent data loss. The mutation check for this is in the test: with the typed error but no rollback guard, the home is still destroyed. `isDefinitiveAbsence` is exported so the second credential lane reuses the host predicate instead of keeping its own copy of the errno allowlist. * refactor(codex): move the definitive-absence predicate to src/shared Why: STA-4737 needs the same predicate from src/main/codex, which the CLI tsconfig project does not admit imports from codex-accounts into. Both branches now carry byte-identical copies so they merge cleanly in either order.
…d account (STA-4734) (stablyai#15279) * fix(codex): stop a locked auth.json from deleting a just-authenticated account (STA-4734) A successful Codex login could be reported as a failure, and the rollback then deleted the managed home holding the credentials it had just written. Three reads on the add path answered "no credentials" from a read that had merely failed: - `service.ts` decided the login verdict with `existsSync(authJsonPath)`, which returns false for EPERM/EBUSY as readily as for ENOENT. The post-auth tree kill only arms after the watcher has already observed new credential bytes, so an unreadable file there is a lock, not a failed login. - `loadOAuthCredentials` read auth.json bare, so a denial surfaced as a generic error indistinguishable from a real one. - `importCodexAuthFromHome` turned an unreadable source file into "No Codex credentials found ... run `codex login` first" — advice to redo a login that had already succeeded. Each now classifies: only a definitive ENOENT/ENOTDIR means absent, everything else is `ManagedCodexHomeTemporarilyUnavailableError`. Classifying alone is inert, because the add path's rollback deletes the home for any error. `removeManagedHomeUnlessUnproven` holds the rollback back on an unproven failure — a kept home is a recoverable leak, a deleted one is permanent data loss. The mutation check for this is in the test: with the typed error but no rollback guard, the home is still destroyed. `isDefinitiveAbsence` is exported so the second credential lane reuses the host predicate instead of keeping its own copy of the errno allowlist. * refactor(codex): move the definitive-absence predicate to src/shared Why: STA-4737 needs the same predicate from src/main/codex, which the CLI tsconfig project does not admit imports from codex-accounts into. Both branches now carry byte-identical copies so they merge cleanly in either order.
ELI5
You sign in to Codex. The login works — the credentials land on disk. But if a virus scanner or indexer has that file open for the half-second Orca goes to read it, Orca concludes the login failed and deletes the account it just created. You try again, and again.
What Changed
Three reads on the Codex account-add path decided "there are no credentials here" from a read that had merely failed.
existsSyncreturnsfalseforEPERM,EBUSYand every unknown errno exactly as readily as forENOENT, and a barereadFileSyncthrows the same shape whether the file is missing or locked.service.tslogin verdictexistsSync(authJsonPath)ENOENT/ENOTDIRrevokes the success verdictloadOAuthCredentialsreadFileSyncManagedCodexHomeTemporarilyUnavailableErrorimportCodexAuthFromHomeexistsSync⇒ "runcodex loginfirst"And the part that makes it non-inert. Classifying alone changes nothing, because
doAddAccount'scatchdeletes the managed home for any error.removeManagedHomeUnlessUnprovenholds the rollback back when the failure is unproven — a kept home is a recoverable leak, a deleted one is permanent data loss.The definitive-absence predicate moves to
src/shared/definitive-filesystem-absence.tsso every lane reuses one errno allowlist instead of keeping its own copy. It lives insrc/sharedrather than beside the ownership gate because the CLI tsconfig project is an explicit allowlist that admitssrc/main/codexbut notsrc/main/codex-accounts.Why
This is the same category error as #15046 and #15093, on the one path where the user is actively watching: a completed OAuth flow reported as a failure, with the credentials destroyed behind it. The user's natural response — sign in again — is the loop reported in STA-4422.
The login verdict deserves special note. The post-auth tree kill only arms after the watcher has already observed new credential bytes (
loginAuthChangedrequires a defined, non-null, changed read). So by the time thatexistsSyncran, the credentials had already been positively observed. It was re-confirming something already proven, and a lock at that instant threw the proof away.Deliberately not here: the WSL lane (STA-4606), the shared config-mirror and resource-sync modules (STA-4737), and the remaining host-lane reads (STA-4735).
Linked Issue
Fixes STA-4734.
Related: STA-4422 (the reported symptom), STA-4606, STA-4735, STA-4737.
Visual Proof
N/A — no UI change. The user-visible difference is which error text appears and whether the account survives, both covered by tests.
Testing
src/main/codex-accounts/sta-4734-login-rollback-deletes-authenticated-home.test.ts— 6 tests, 3 driving the fix and 3 anchoring it.The fault rig models one denial coherently: a denied path fails
readFileSyncand reportsfalsefromexistsSync. Faulting only one lets a test pass against code that still consults the other.Mutation-checked, not assumed:
expected [] to have a length of 1— the home is still deleted. This is the check that proves the classification is not a call-site fix over a root that still destroys the data.The anchors exist because "make the failure stop failing" is the easy wrong fix: a genuinely failed login still rolls the home back, a definitively absent
auth.jsonafter a tree kill still rejects, and a genuinely empty source home still reports "No Codex credentials found".267/267
src/main/codex-accountspass; 1069/1069 acrosscodex-accounts+codex.check-changed-code-quality.mjs: 0 findings (code quality, type-aware, React Doctor).Automated tests added
Manual: not run. The trigger is a Windows file-denial race; the rig reproduces it deterministically and the earlier hardware work on this defect family (fix(codex): stop a transient filesystem error from logging out the active account #15046, fix(codex): stop resuming a session under the wrong account when a sessions tree is locked #15093) established that an ACL denial produces
EPERMon these calls.Merge note
#15287 (STA-4737) touches the same predicate. Both PRs carry byte-identical copies of
src/shared/definitive-filesystem-absence.tsand of thehost-codex-managed-home-ownership.tsimport change, so they merge cleanly in either order. Neither depends on the other.(Rebased onto
mainafter #15277 fixed an unrelated pre-existing typecheck failure.)AI Disclosure
N/A — internal.