Skip to content

fix(codex): stop a locked auth.json from deleting a just-authenticated account (STA-4734) - #15279

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sta-4734-codex-login-rollback
Aug 18, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sta-4734-codex-login-rollback

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

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. existsSync returns false for EPERM, EBUSY and every unknown errno exactly as readily as for ENOENT, and a bare readFileSync throws the same shape whether the file is missing or locked.

Site Before After
service.ts login verdict existsSync(authJsonPath) only a definitive ENOENT/ENOTDIR revokes the success verdict
loadOAuthCredentials bare readFileSync classifies; unreadable ⇒ ManagedCodexHomeTemporarilyUnavailableError
importCodexAuthFromHome existsSync ⇒ "run codex login first" that advice is now reserved for a real absence

And the part that makes it non-inert. Classifying alone changes nothing, because doAddAccount's catch deletes the managed home for any error. removeManagedHomeUnlessUnproven holds 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.ts so every lane reuses one errno allowlist instead of keeping its own copy. It lives in src/shared rather than beside the ownership gate because the CLI tsconfig project is an explicit allowlist that admits src/main/codex but not src/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 (loginAuthChanged requires a defined, non-null, changed read). So by the time that existsSync ran, 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 readFileSync and reports false from existsSync. Faulting only one lets a test pass against code that still consults the other.

Mutation-checked, not assumed:

  • Revert all three source changes ⇒ the 3 fix-driving tests go red, the 3 anchors stay green.
  • Revert only the rollback guard, keeping the typed error ⇒ 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.json after a tree kill still rejects, and a genuinely empty source home still reports "No Codex credentials found".

Merge note

#15287 (STA-4737) touches the same predicate. Both PRs carry byte-identical copies of src/shared/definitive-filesystem-absence.ts and of the host-codex-managed-home-ownership.ts import change, so they merge cleanly in either order. Neither depends on the other.

(Rebased onto main after #15277 fixed an unrelated pre-existing typecheck failure.)

AI Disclosure

N/A — internal.

@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 98f810c5-218a-40b4-98bd-ef13360116a0

📥 Commits

Reviewing files that changed from the base of the PR and between 54fb213 and 384416e.

📒 Files selected for processing (3)
  • src/main/codex-accounts/host-codex-managed-home-ownership.ts
  • src/main/codex-accounts/service.ts
  • src/shared/definitive-filesystem-absence.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/codex-accounts/service.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The change exports isDefinitiveAbsence and reuses it for credential reads. Missing auth.json files retain login-related errors, while inaccessible files produce temporary-unavailability errors. Account-add, account-import, and login rollback preserve managed homes when credential access does not prove authentication failure. Windows login completion checks readable credentials instead of file existence. New tests cover permission errors, genuine login failures, Windows tree termination, unreadable source credentials, and empty homes.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the Codex fix for locked auth.json files deleting newly authenticated accounts.
Description check ✅ Passed The description covers the required ELI5, changes, rationale, linked issue, visual proof, testing, and AI disclosure sections with clear scope.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

…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.
@brennanb2025

brennanb2025 commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor Author

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

  • src/main/codex-accounts/service.ts:1647-1650: reverted the ManagedCodexHomeTemporarilyUnavailableError rollback guard. The named test keeps the managed home and its credentials when the identity read is denied went red because the managed home was deleted.
  • src/main/codex-accounts/service.ts:1911-1921: reverted the unreadable-auth classification in loadOAuthCredentials to a bare readFileSync. The same named test went red because the EPERM error was no longer the temporary-unavailability type.
  • src/main/codex-accounts/service.ts:810-815: reverted the definitive-absence split in importCodexAuthFromHome so every read failure was treated as temporary. The named test still reports a genuinely empty source home as having no credentials went red.
  • src/main/codex-accounts/service.ts:1827-1830: reverted the post-auth close check to reject the locked-file case. The named test treats a denied auth.json after a Windows tree kill as the success it is went red.

Verification and clean sweeps

  • src/main/codex and src/main/codex-accounts: 101 files passed, 1 skipped; 1,069 tests passed, 6 skipped.
  • pnpm typecheck passed after pnpm install --frozen-lockfile.
  • node config/scripts/check-changed-code-quality.mjs passed with zero new findings (native, type-aware, and React Doctor checks).
  • Readiness sweep found no crash/cast/retry or unbounded-growth issue, security/supply-chain issue, performance/resource regression, functional regression, persisted-state/backward-compatibility issue, or cross-platform/remoting issue.
  • Checked sibling call sites using the shared isDefinitiveAbsence predicate and confirmed the copies on the sibling filesystem-safety PRs are byte-identical. No inconsistent errno allowlist remains.
  • Deliberately left readLoginAuthSnapshot as a local tri-state helper: it must distinguish definitive absence (null) from indeterminate/unreadable (undefined) for the Windows watcher, which the boolean shared predicate cannot represent. No WSL call-site or remote wire change was introduced because this PR does not touch those lanes.
  • No Electron/UI surface, renderer code, or mobile-facing contract is touched; screenshots and UI QA are not applicable.

@brennanb2025
brennanb2025 merged commit 2b2529c into main Aug 18, 2026
46 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…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.
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…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.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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