Skip to content

fix(codex-accounts): stop account mutations blocking on the quota refresh - #10225

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/investigate-1-4-150
Jul 23, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/investigate-1-4-150

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Fixes #10141

Problem

Since the per-account CODEX_HOME rollout (#9501, stable in v1.4.149), users see:

  • Switching Codex accounts freezes the switcher for tens of seconds before the switch "takes".
  • Adding a new Codex account completes login in the browser but the UI stays stuck on the loading screen — sometimes the account never connects at all.

Root cause

All four account mutations (add / reauthenticate / remove / select) in CodexAccountService awaited rateLimits.refreshForCodexAccountChange before resolving the IPC call. That refresh runs a live quota probe which, post-rollout, targets each account's cold self-contained home:

  • 10s RPC timeout + 15s PTY fallback (25s RPC on WSL), and
  • it can additionally queue behind an in-flight global usage fetch (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 decoupling block in service.test.ts — all four failed before the fix, reproducing the reported symptoms exactly:

  1. select + never-settling refresh → selectAccount hung (timeout)
  2. select + rejecting refresh → selectAccount rejected
  3. add + never-settling refresh → addAccount hung (timeout)
  4. add + rejecting refresh → addAccount rejected and the managed home was deleted while the account stayed in settings

All 48 tests pass after the fix; typecheck + oxlint + max-lines ratchet clean.

Notes

  • refreshForCodexAccountChange had no other non-test callers, so rate-limit semantics are unchanged elsewhere.
  • Follow-up (separate PR): claude-accounts/service.ts has the identical awaited coupling at three sites.

…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
@coderabbitai

coderabbitai Bot commented Jul 23, 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: 655a79bd-2304-4a26-a4ee-9bcb78f8cbae

📥 Commits

Reviewing files that changed from the base of the PR and between 9500ca7 and 297368d.

📒 Files selected for processing (2)
  • src/main/codex-accounts/service.test.ts
  • src/main/codex-accounts/service.ts

📝 Walkthrough

Walkthrough

Codex 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it omits required template sections like Screenshots, AI Review Report, and Security Audit. Add the missing template sections and include the testing checklist, screenshots note, AI review report, and security audit summary.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: account mutations no longer block on quota refresh.
Linked Issues check ✅ Passed The changes address #10141 by making Codex account switching and account addition resolve without waiting on quota refreshes.
Out of Scope Changes check ✅ Passed The code and tests stay focused on decoupling quota refresh from account mutations, with no clear unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@brennanb2025
brennanb2025 merged commit babf1ff into main Jul 23, 2026
2 of 3 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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
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] Codex Account Switching and Account Addition Issue

1 participant