Repository navigation
fix(codex-accounts): stop account mutations blocking on the quota refresh - #10225
Conversation
…resh Switching, adding, re-authing, or removing a Codex account awaited refreshForCodexAccountChange before resolving the IPC call. Since the per-account CODEX_HOME rollout (#9501) that probe runs against a cold home (10s RPC + 15s PTY fallback, 25s WSL) and can queue behind an in-flight global usage fetch, so the switcher sat unresponsive for tens of seconds and a fresh login looked stuck on the loading screen. Worse, in addAccount the awaited refresh sat inside the login cleanup try/catch: a refresh rejection after the account was durably committed deleted the just-created managed home, leaving a registered account with no home ("account never connects"). Run the refresh as best-effort background work instead. Its synchronous prefix still flips usage to "fetching" before the first await, so the switcher updates instantly and usage fills in via the normal rate-limit state pushes; a probe failure is logged and can never trigger managed-home cleanup. Fixes #10141
|
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 (2)
📝 WalkthroughWalkthroughCodex account mutations now start quota refreshes in the background instead of awaiting them. Refresh failures are caught and logged. The behavior applies to adding, reauthenticating, removing, and selecting accounts. Tests cover non-settling and rejecting refreshes, prompt mutation completion, error logging, and preservation of newly created managed account files after refresh failure. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
…resh (stablyai#10225) Switching, adding, re-authing, or removing a Codex account awaited refreshForCodexAccountChange before resolving the IPC call. Since the per-account CODEX_HOME rollout (stablyai#9501) that probe runs against a cold home (10s RPC + 15s PTY fallback, 25s WSL) and can queue behind an in-flight global usage fetch, so the switcher sat unresponsive for tens of seconds and a fresh login looked stuck on the loading screen. Worse, in addAccount the awaited refresh sat inside the login cleanup try/catch: a refresh rejection after the account was durably committed deleted the just-created managed home, leaving a registered account with no home ("account never connects"). Run the refresh as best-effort background work instead. Its synchronous prefix still flips usage to "fetching" before the first await, so the switcher updates instantly and usage fills in via the normal rate-limit state pushes; a probe failure is logged and can never trigger managed-home cleanup. Fixes stablyai#10141
Fixes #10141
Problem
Since the per-account CODEX_HOME rollout (#9501, stable in v1.4.149), users see:
Root cause
All four account mutations (
add/reauthenticate/remove/select) inCodexAccountServiceawaitedrateLimits.refreshForCodexAccountChangebefore resolving the IPC call. That refresh runs a live quota probe which, post-rollout, targets each account's cold self-contained home:fetchCodexOnly→waitForFetchIdle).So the account was already durably switched, but the UI stayed blocked on unrelated usage data.
The add-account path was worse: the awaited refresh sat inside the login-cleanup try/catch. A refresh rejection after credentials and settings were durably committed deleted the just-created managed home while the settings mutation stayed — a registered account with no home, i.e. "never connects".
Fix
startQuotaRefreshInBackground: run the refresh as best-effort background work with a logged.catch. Its synchronous prefix still executes before its first await, so the switcher flips to "fetching" instantly and usage fills in through the normal rate-limit state pushes. A probe failure can no longer reject the mutation or trigger managed-home cleanup.Reproduction / tests
New
quota refresh decouplingblock inservice.test.ts— all four failed before the fix, reproducing the reported symptoms exactly:selectAccounthung (timeout)selectAccountrejectedaddAccounthung (timeout)addAccountrejected and the managed home was deleted while the account stayed in settingsAll 48 tests pass after the fix; typecheck + oxlint + max-lines ratchet clean.
Notes
refreshForCodexAccountChangehad no other non-test callers, so rate-limit semantics are unchanged elsewhere.claude-accounts/service.tshas the identical awaited coupling at three sites.