Skip to content

fix(codex): stop a transient filesystem error from logging out the active account - #15046

Merged
brennanb2025 merged 2 commits into
mainfrom
brennan/sta-4422-bug-orca-codex-sessions-keep-logging-out-login-issue
Aug 17, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennan/sta-4422-bug-orca-codex-sessions-keep-logging-out-login-issue

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1906 $\color{#cf222e}{\Huge{\mathbf{−}}}$​70 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1836
Prod 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​731 $\color{#cf222e}{\Huge{\mathbf{−}}}$​212 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​519

Fixes STA-4422 · closes #14737

The bug

A user reported Codex accounts logging out at random, and logins that report success while the account stays inactive.

One unreadable read of a managed Codex home's ownership marker cleared the active account selection, permanently. On Windows any exclusive lock — Defender real-time scanning, a backup agent, a sync client — makes every read of that marker fail with EBUSY. The background rate-limit poll runs every 15 minutes, plus once at every app start (when antivirus is busiest, which matches the "I opened Orca and I was logged out" reports).

Reproduced live on a Windows host against an isolated Orca profile, driven over CDP:

PHASE1 before      {"active":"35e6dde4-…","host":"35e6dde4-…","n":1}
PHASE1 after poll  {"active":"35e6dde4-…","host":"35e6dde4-…","n":1}   healthy poll, selection survives
PHASE2 lock held on .orca-managed-home (FileShare.None)
PHASE2 after poll  {"active":null,"host":null,"n":1}                   logged out
PHASE3 lock released
PHASE3 after poll  {"active":null,"host":null,"n":1}                   does not heal

A rig replicating the gate's exact call sequence on that box measured the trigger's reliability: 18,522 iterations idle → 0 failures; 23,257 under the lock → 23,257 failures (100%); 11,205 after release → 0. The gate isn't flaky under contention — it is totally broken for the lock's duration. The poll only has to land inside one such window, once, ever.

Root cause

The ownership gate answered two very different questions through one channel:

  • "This home is not ours" — a successful observation that failed a trust check (path escaped containment, marker names a different account).
  • "We could not read it" — EBUSY. The home may be perfectly valid.

Both surfaced as a throw, which the caller flattened to null, which three call sites took as proof the home was untrustworthy and wrote activeCodexManagedAccountId: null.

Refusing to use an unverified home is correct. Erasing the user's account selection because a file was briefly locked is not.

The fix

The gate now returns a tri-state verdict. untrusted comes only from a proven trust failure, or a definitive ENOENT/ENOTDIR where absence is itself the verdict. Every other filesystem exception is indeterminate. Only untrusted may touch persisted state.

The subtle part: null already meant "fall through to the system default" on both the launch and poll paths. So simply not-clearing would have run a different account behind a UI still showing the selected one — a credential-identity bug, worse than the logout. The refusal needed real channels rather than a sentinel:

Path Behaviour on indeterminate
Rate-limit poll explicit skip. Returning null would not have skipped — the fetcher maps null to ~/.codex and would have spawned a token-refreshing app-server inside the user's real credential home
Pane launch typed refusal; both PTY implementations convert it to a clean rejection with a retry message, including the re-resolution after the async auth-readiness wait
Automatic session resume selected home resolved eagerly, so an unreadable account can't be silently replaced by another one in the ranking
Config-sync status distinct managed-home-unavailable stall instead of reporting synced, with a bounded renderer retry (30s × 10) so it clears without a remount

Deliberately no retry or grace window inside the gate: it is synchronous, runs on the Electron main process, and startup iterates every managed account — a sleep there would freeze the UI. Recovery is just the next readable evaluation.

Second symptom: "login succeeded but the account is still inactive"

The status bar's Sign in button called a re-auth that captured the selection before login and restored it after — so re-authenticating a deselected account restored null. A fully successful login left the account inactive, with no success toast to distinguish it from a failure. That's the reporter's second screenshot.

It now activates the account it just signed in — but only when the pre-login selection was empty, so it can't silently switch accounts for multi-account users from a control labelled "Sign in to see usage". It uses the pre-login capture, not a post-login read, because the runtime poll runs outside the account mutation queue and could clear the primary while OAuth is open. It also runs the same restart prompt an explicit switch does, plus success and error toasts.

Not in this change

The WSL lane has the same class of defect, including a path that rmSyncs a credential mirror on a transient read. It is pre-existing, and these host code paths cannot reach it — getSelfContainedManagedHostAccount excludes WSL accounts, so the tri-state change leaves that lane byte-for-byte as it was. It needs distro-scoped read-back suppression and a restart-safe ownership contract, which is a design change rather than a bug fix. Filed separately with a full specification.

Two pre-existing session-tree probes can also route a resume to another account (existsSync(sessions) and a blanket lstat catch). Also filed separately — they route to another account today with the ownership gate uninvolved, so they are not regressions of this change.

This does not eliminate every logout. The Codex CLI's own credential manager collapses any read error into "not logged in" and persists auth.json by truncate-in-place, so some reported logouts originate below Orca. There is also an independent refresh-token rotation race, where the quota probe can race a user's live Codex pane over one rotating token; that is a real, unrecoverable logout and is tracked separately.

Testing

  • New regression test with a held lock (not a single-shot fault, which any retry would mask), asserting the selection survives, updateSettings is never called, repeated evaluations never accumulate into a destructive verdict, and recovery is automatic.
  • A paired test proving the gate is not toothless: a marker naming a different account is still untrusted and still deselects.
  • Both PTY implementations assert zero spawn calls on refusal — "selection survived" is vacuous there, since existing tests prove a null re-resolution intentionally launches without CODEX_HOME.
  • Every new test was mutation-checked: the fix was broken, the test confirmed red, then restored.
  • Full suite: 50,983 passing. The single failure is terminal-history-async-delete.test.ts, a wall-clock assertion (elapsedMs < 150) in a file this branch does not touch; it passes in isolation and fails only under full-suite parallel load.
  • All three typechecks clean; oxfmt and oxlint clean (lint gate proven live by injecting a violation).

Known coverage gap

src/main/index.ts has no unit-test entry point in this repo, so the eager resume-gate wiring is covered by typecheck plus tests at both ends rather than directly. The AI Vault propagation paths (index.ts:1468-1475, :2591-2597) are likewise uncovered.

@coderabbitai

coderabbitai Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds verdict-based managed Codex home ownership checks with separate handling for untrusted and temporarily unavailable homes. Runtime-home, launch, resume, rate-limit, and configuration-sync flows now preserve selection or reject operations when managed files cannot be read. Rate-limit APIs return structured resolution states. Reauthentication gains optional activation for empty selections. The renderer adds sign-in feedback, synchronization retries, and localized status messages.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description clearly explains the bug, fix, scope, linked issues, and testing, but it omits the required Visual Proof and checklist sections. Add the required template sections, including Visual Proof with N/A and a reason if applicable, plus the completed checklist and review notes.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses both objectives in [#14737]: it preserves selection during transient marker failures and activates accounts after successful login when selection was empty.
Out of Scope Changes check ✅ Passed The changes remain aligned with [#14737], including logout prevention, inactive-login handling, and required user-facing refusal and status behavior.
Title check ✅ Passed The title clearly identifies the main fix: preventing transient filesystem errors from logging out the active Codex account.
✨ Finishing Touches 💡 1
📝 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (3)
src/renderer/src/components/status-bar/codex-status-sign-in.test.tsx (1)

2-9: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Shorten the test preambles.

Keep only the non-obvious test setup rationale.

  • src/renderer/src/components/status-bar/codex-status-sign-in.test.tsx#L2-L9: reduce the symptom narrative to a brief setup-specific comment.
  • src/main/codex-accounts/service-reauthenticate-activation.test.ts#L1-L8: reduce the workflow narrative to the race condition that the test requires.

As per coding guidelines, “Comments must be concise, non-obvious, and brief.”

Source: Coding guidelines

src/main/codex-accounts/host-codex-managed-home-ownership.ts (1)

13-21: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Shorten the rationale comments.

These three comment blocks span 6 to 9 lines each and narrate the caller behavior. Reduce each to one line that states the non-obvious constraint, for example: untrusted may clear the persisted selection, indeterminate may not (#STA-4422).

As per coding guidelines: "Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code."

Also applies to: 64-69, 190-196

Source: Coding guidelines

src/main/rate-limits/service.ts (1)

1812-1824: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add direct tests for the skip resolution paths.

Test a full cycle with { kind: 'skip' } to confirm that Codex does not fetch, prior Codex state remains unchanged, and other providers continue. Test a Codex-only cycle to confirm that it does not set a fetching state. Test a ready-to-skip transition while a fetch is in flight to confirm that the result is not applied.

Also applies to: 1901-1905, 1942-1946


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: efc54fb4-f53d-4f36-8302-22ac8c65e152

📥 Commits

Reviewing files that changed from the base of the PR and between b279f66 and 4bd6e7a20682f2a13456a359007c07e6fc58fbb8.

📒 Files selected for processing (37)
  • src/main/codex-accounts/host-codex-managed-home-ownership.ts
  • src/main/codex-accounts/runtime-home-managed-auth-recovery.test.ts
  • src/main/codex-accounts/runtime-home-mirrored-status-home.test.ts
  • src/main/codex-accounts/runtime-home-per-account-homes.test.ts
  • src/main/codex-accounts/runtime-home-real-home-lane-routing.test.ts
  • src/main/codex-accounts/runtime-home-resume-selection-gate.test.ts
  • src/main/codex-accounts/runtime-home-retained-auth-provenance.test.ts
  • src/main/codex-accounts/runtime-home-service-per-account-migration.test.ts
  • src/main/codex-accounts/runtime-home-service.ts
  • src/main/codex-accounts/runtime-home-wsl-managed-accounts.test.ts
  • src/main/codex-accounts/runtime-home-wsl-system-default.test.ts
  • src/main/codex-accounts/service-reauthenticate-activation.test.ts
  • src/main/codex-accounts/service-reset-credit-target-routing.test.ts
  • src/main/codex-accounts/service-test-harness.ts
  • src/main/codex-accounts/service.ts
  • src/main/codex-accounts/sta-4422-transient-ownership-error.test.ts
  • src/main/index.ts
  • src/main/ipc/codex-accounts.ts
  • src/main/ipc/codex-config-sync.test.ts
  • src/main/ipc/codex-config-sync.ts
  • src/main/ipc/pty-spawn-codex-home-unavailable.test.ts
  • src/main/ipc/pty.ts
  • src/main/rate-limits/service-account-target-selection.test.ts
  • src/main/rate-limits/service-inactive-account-previews.test.ts
  • src/main/rate-limits/service.ts
  • src/main/text-generation/commit-message-agent-environment.test.ts
  • src/preload/api/agent-account-api.ts
  • src/preload/index.ts
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/renderer/src/components/status-bar/codex-status-sign-in.test.tsx
  • 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/codex-config-sync-types.ts

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

Comment thread src/main/codex-accounts/service.ts Resolved
Comment on lines 1513 to +1547
await fetchSettings()
if (mountedRef.current && accountsExpandedRef.current) {
const nextActiveAccountId = getCodexStatusActiveId(next, target)
if (previousActiveAccountId !== nextActiveAccountId) {
// Why: sign-in that lands on a new active account changes pane credentials
// exactly like an explicit switch, so it owes the same restart prompt.
await markLiveCodexSessionsForRestart({
previousAccountLabel: resolveCodexRestartPromptAccountLabel(
accountState.accounts,
previousActiveAccountId
),
nextAccountLabel: resolveCodexRestartPromptAccountLabel(
next.accounts,
nextActiveAccountId
),
previousAccountId: previousActiveAccountId ?? null,
nextAccountId: nextActiveAccountId ?? null,
target
})
if (mountedRef.current) {
setAccountsExpanded(false)
}
} else if (mountedRef.current && accountsExpandedRef.current) {
await fetchInactiveCodexAccountUsage()
}
toast.success(
translate('auto.components.status.bar.StatusBar.codexSignInSuccess', 'Signed in to Codex')
)
} catch (error) {
console.error('Failed to re-authenticate Codex account from status bar:', error)
toast.error(
translate(
'auto.components.status.bar.StatusBar.codexSignInError',
'Codex sign-in failed. Please try again.'
)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Do not report a completed sign-in as failed.

fetchSettings() and markLiveCodexSessionsForRestart() run after reauthenticate() succeeds. If either operation rejects, the outer catch shows the sign-in failure toast even though Codex credentials were updated. Handle post-sign-in synchronization failures separately, then preserve the success result.

Comment on lines +1537 to +1545
toast.success(
translate('auto.components.status.bar.StatusBar.codexSignInSuccess', 'Signed in to Codex')
)
} catch (error) {
console.error('Failed to re-authenticate Codex account from status bar:', error)
toast.error(
translate(
'auto.components.status.bar.StatusBar.codexSignInError',
'Codex sign-in failed. Please try again.'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use generated renderer localization keys.

Replace codexSignInSuccess and codexSignInError with keys generated from <filePath>:<text>. The new suffixes do not follow the renderer localization key format.

Based on learnings, generate locale keys as the first 10 characters of the SHA-1 hash of <filePath>:<text>.

Source: Learnings

Comment thread src/renderer/src/i18n/locales/es.json Resolved
…tive account

A single unreadable read of a managed Codex home's ownership marker cleared the
user's active account selection, permanently. On Windows any exclusive lock —
Defender real-time scanning, a backup agent, a sync client — makes every read of
that marker fail with EBUSY, and the background rate-limit poll runs every 15
minutes plus once at every app start.

Root cause: the ownership gate answered two very different questions through one
channel. "This home is not ours" (a successful observation that failed a trust
check) and "we could not read it" both surfaced as a throw, which the caller
flattened to null, which three call sites took as proof the home was
untrustworthy and wrote activeCodexManagedAccountId: null.

Refusing to USE an unverified home is correct. Erasing the user's account
selection because a file was briefly locked is not.

The gate now returns a tri-state verdict. `untrusted` comes only from a proven
trust failure or a definitive ENOENT/ENOTDIR where absence is itself the
verdict; every other filesystem exception is `indeterminate`. Only `untrusted`
may touch persisted state.

Because `null` already meant "fall through to the system default" on both the
launch and poll paths, not-clearing on its own would have run a DIFFERENT
account behind a UI still showing the selected one. So the refusal needed real
channels rather than a sentinel:

- the poll returns an explicit skip; returning null would not have skipped at
  all, since the fetcher maps null to ~/.codex and would have spawned a
  token-refreshing app-server inside the user's real credential home
- pane launch throws a typed temporary-unavailability error that both PTY
  implementations convert into a clean refusal with a retry message, including
  the re-resolution after the async auth-readiness wait
- automatic session resume resolves the selected home eagerly, so an unreadable
  account can no longer be silently replaced by another one in the ranking
- config-sync status reports a distinct managed-home-unavailable stall instead
  of "synced", with a bounded renderer retry so it clears on its own

Also fixes the ticket's second symptom. The status bar's Sign in button called a
re-auth that captured the selection before login and restored it after, so
re-authenticating a deselected account restored `null` — a successful login that
left the account inactive, with no success toast to distinguish it from failure.
It now activates the account it just signed in, but only when the pre-login
selection was empty, so it cannot silently switch accounts for multi-account
users, and it runs the same restart prompt an explicit switch does.

No retry or grace window inside the synchronous gate: it runs on the Electron
main process in a loop over accounts, so a sleep there would freeze the UI.
Recovery is simply the next readable evaluation.

The WSL lane has the same class of defect, including one path that deletes a
credential mirror. It is pre-existing, unreachable from these host code paths,
and deliberately left for its own change; the host clearing sites cannot reach a
WSL account because getSelfContainedManagedHostAccount excludes them.

Fixes STA-4422
@brennanb2025
brennanb2025 force-pushed the brennan/sta-4422-bug-orca-codex-sessions-keep-logging-out-login-issue branch from cbd99ec to 7ac8420 Compare August 17, 2026 08:17
@OrcaWin

OrcaWin commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Windows QA proof (secret-safe):

Before

Before

During lock

During lock

After

After

@brennanb2025
brennanb2025 merged commit 7ae6aed into main Aug 17, 2026
87 of 89 checks passed
AmethystLiang pushed a commit that referenced this pull request Aug 20, 2026
…tive account (#15046)

* fix(codex): stop a transient filesystem error from logging out the active account

A single unreadable read of a managed Codex home's ownership marker cleared the
user's active account selection, permanently. On Windows any exclusive lock —
Defender real-time scanning, a backup agent, a sync client — makes every read of
that marker fail with EBUSY, and the background rate-limit poll runs every 15
minutes plus once at every app start.

Root cause: the ownership gate answered two very different questions through one
channel. "This home is not ours" (a successful observation that failed a trust
check) and "we could not read it" both surfaced as a throw, which the caller
flattened to null, which three call sites took as proof the home was
untrustworthy and wrote activeCodexManagedAccountId: null.

Refusing to USE an unverified home is correct. Erasing the user's account
selection because a file was briefly locked is not.

The gate now returns a tri-state verdict. `untrusted` comes only from a proven
trust failure or a definitive ENOENT/ENOTDIR where absence is itself the
verdict; every other filesystem exception is `indeterminate`. Only `untrusted`
may touch persisted state.

Because `null` already meant "fall through to the system default" on both the
launch and poll paths, not-clearing on its own would have run a DIFFERENT
account behind a UI still showing the selected one. So the refusal needed real
channels rather than a sentinel:

- the poll returns an explicit skip; returning null would not have skipped at
  all, since the fetcher maps null to ~/.codex and would have spawned a
  token-refreshing app-server inside the user's real credential home
- pane launch throws a typed temporary-unavailability error that both PTY
  implementations convert into a clean refusal with a retry message, including
  the re-resolution after the async auth-readiness wait
- automatic session resume resolves the selected home eagerly, so an unreadable
  account can no longer be silently replaced by another one in the ranking
- config-sync status reports a distinct managed-home-unavailable stall instead
  of "synced", with a bounded renderer retry so it clears on its own

Also fixes the ticket's second symptom. The status bar's Sign in button called a
re-auth that captured the selection before login and restored it after, so
re-authenticating a deselected account restored `null` — a successful login that
left the account inactive, with no success toast to distinguish it from failure.
It now activates the account it just signed in, but only when the pre-login
selection was empty, so it cannot silently switch accounts for multi-account
users, and it runs the same restart prompt an explicit switch does.

No retry or grace window inside the synchronous gate: it runs on the Electron
main process in a loop over accounts, so a sleep there would freeze the UI.
Recovery is simply the next readable evaluation.

The WSL lane has the same class of defect, including one path that deletes a
credential mirror. It is pre-existing, unreachable from these host code paths,
and deliberately left for its own change; the host clearing sites cannot reach a
WSL account because getSelfContainedManagedHostAccount excludes them.

Fixes STA-4422

* test(codex): cover pending reset home ownership
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…tive account (stablyai#15046)

* fix(codex): stop a transient filesystem error from logging out the active account

A single unreadable read of a managed Codex home's ownership marker cleared the
user's active account selection, permanently. On Windows any exclusive lock —
Defender real-time scanning, a backup agent, a sync client — makes every read of
that marker fail with EBUSY, and the background rate-limit poll runs every 15
minutes plus once at every app start.

Root cause: the ownership gate answered two very different questions through one
channel. "This home is not ours" (a successful observation that failed a trust
check) and "we could not read it" both surfaced as a throw, which the caller
flattened to null, which three call sites took as proof the home was
untrustworthy and wrote activeCodexManagedAccountId: null.

Refusing to USE an unverified home is correct. Erasing the user's account
selection because a file was briefly locked is not.

The gate now returns a tri-state verdict. `untrusted` comes only from a proven
trust failure or a definitive ENOENT/ENOTDIR where absence is itself the
verdict; every other filesystem exception is `indeterminate`. Only `untrusted`
may touch persisted state.

Because `null` already meant "fall through to the system default" on both the
launch and poll paths, not-clearing on its own would have run a DIFFERENT
account behind a UI still showing the selected one. So the refusal needed real
channels rather than a sentinel:

- the poll returns an explicit skip; returning null would not have skipped at
  all, since the fetcher maps null to ~/.codex and would have spawned a
  token-refreshing app-server inside the user's real credential home
- pane launch throws a typed temporary-unavailability error that both PTY
  implementations convert into a clean refusal with a retry message, including
  the re-resolution after the async auth-readiness wait
- automatic session resume resolves the selected home eagerly, so an unreadable
  account can no longer be silently replaced by another one in the ranking
- config-sync status reports a distinct managed-home-unavailable stall instead
  of "synced", with a bounded renderer retry so it clears on its own

Also fixes the ticket's second symptom. The status bar's Sign in button called a
re-auth that captured the selection before login and restored it after, so
re-authenticating a deselected account restored `null` — a successful login that
left the account inactive, with no success toast to distinguish it from failure.
It now activates the account it just signed in, but only when the pre-login
selection was empty, so it cannot silently switch accounts for multi-account
users, and it runs the same restart prompt an explicit switch does.

No retry or grace window inside the synchronous gate: it runs on the Electron
main process in a loop over accounts, so a sleep there would freeze the UI.
Recovery is simply the next readable evaluation.

The WSL lane has the same class of defect, including one path that deletes a
credential mirror. It is pre-existing, unreachable from these host code paths,
and deliberately left for its own change; the host clearing sites cannot reach a
WSL account because getSelfContainedManagedHostAccount excludes them.

Fixes STA-4422

* test(codex): cover pending reset home ownership
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tive account (stablyai#15046)

* fix(codex): stop a transient filesystem error from logging out the active account

A single unreadable read of a managed Codex home's ownership marker cleared the
user's active account selection, permanently. On Windows any exclusive lock —
Defender real-time scanning, a backup agent, a sync client — makes every read of
that marker fail with EBUSY, and the background rate-limit poll runs every 15
minutes plus once at every app start.

Root cause: the ownership gate answered two very different questions through one
channel. "This home is not ours" (a successful observation that failed a trust
check) and "we could not read it" both surfaced as a throw, which the caller
flattened to null, which three call sites took as proof the home was
untrustworthy and wrote activeCodexManagedAccountId: null.

Refusing to USE an unverified home is correct. Erasing the user's account
selection because a file was briefly locked is not.

The gate now returns a tri-state verdict. `untrusted` comes only from a proven
trust failure or a definitive ENOENT/ENOTDIR where absence is itself the
verdict; every other filesystem exception is `indeterminate`. Only `untrusted`
may touch persisted state.

Because `null` already meant "fall through to the system default" on both the
launch and poll paths, not-clearing on its own would have run a DIFFERENT
account behind a UI still showing the selected one. So the refusal needed real
channels rather than a sentinel:

- the poll returns an explicit skip; returning null would not have skipped at
  all, since the fetcher maps null to ~/.codex and would have spawned a
  token-refreshing app-server inside the user's real credential home
- pane launch throws a typed temporary-unavailability error that both PTY
  implementations convert into a clean refusal with a retry message, including
  the re-resolution after the async auth-readiness wait
- automatic session resume resolves the selected home eagerly, so an unreadable
  account can no longer be silently replaced by another one in the ranking
- config-sync status reports a distinct managed-home-unavailable stall instead
  of "synced", with a bounded renderer retry so it clears on its own

Also fixes the ticket's second symptom. The status bar's Sign in button called a
re-auth that captured the selection before login and restored it after, so
re-authenticating a deselected account restored `null` — a successful login that
left the account inactive, with no success toast to distinguish it from failure.
It now activates the account it just signed in, but only when the pre-login
selection was empty, so it cannot silently switch accounts for multi-account
users, and it runs the same restart prompt an explicit switch does.

No retry or grace window inside the synchronous gate: it runs on the Electron
main process in a loop over accounts, so a sleep there would freeze the UI.
Recovery is simply the next readable evaluation.

The WSL lane has the same class of defect, including one path that deletes a
credential mirror. It is pre-existing, unreachable from these host code paths,
and deliberately left for its own change; the host clearing sites cannot reach a
WSL account because getSelfContainedManagedHostAccount excludes them.

Fixes STA-4422

* test(codex): cover pending reset home ownership
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.

[Bug] Orca Codex Sessions Keep Logging Out / Login Issue

2 participants