Repository navigation
fix(codex-accounts): skip the usage refresh when removing an inactive Codex account - #25105
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Gate on no-op removal —
CodexAccountSelection.remove()now skipssyncForCurrentSelection()andrefreshForCodexAccountChange(...)only when the active id, the normalized runtime selection, and the selected host home's ownership are all unchanged; every other outcome keeps the previous refresh behavior. - Read-only ownership probe —
service.tswiresisOwnedHostManagedHomeoverCodexManagedHomePath.assertHostOwnership, catching bothUntrustedManagedCodexHomeErrorandManagedCodexHomeTemporarilyUnavailableErrorand returningfalse, so an unprovable home fails safe to a refresh. - Regression coverage — five new cases in
service-account-selection-and-removal.test.tspin the skip for inactive removal and the retained sync/refresh for removing the selected account, a missing ownership marker, the system-default host, and a stale persisted host selection.
The gate is fail-safe in the right direction: startup already syncs the runtime mirror, inactive previews live in a separate cache that evictInactiveCodexCache clears and re-pushes, and every uncertainty case (null host, stale id, WSL-lane change, unproven/unreadable home) falls through to the old refresh path. Removal semantics proper (record deletion, managed-home cleanup, cache eviction, credit-ledger cleanup) are untouched.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
030c353 to
cb0bbd9
Compare
|
Rebased onto @nwparker gentle ping — happy to adjust anything. |
cb0bbd9 to
3251307
Compare
|
Rebased onto current Verified after the rebase: @nwparker gentle ping — happy to adjust anything. |
… Codex account Removing a Codex account always forced a quota refresh, which blanks the active account's usage bars while it re-probes. Only start the refresh when a runtime lane's selection actually changed. Also compare runtime selections with isDeepStrictEqual instead of JSON.stringify. Fixes stablyai#24942 Co-authored-by: ggbdpq <[email protected]>
3251307 to
4995cd0
Compare

ELI5
When you removed a Codex account you weren't using, Orca still treated it as an account switch. It cleared the usage bars of the account you are using and re-fetched them from scratch. Your active setup hadn't changed, so that refresh did nothing useful. Now removing an unused account leaves the active account's usage view alone.
What Changed
CodexAccountSelection.remove()always calledstartQuotaRefresh(...), which ends inrefreshForCodexAccountChange. That call puts the Codex usage view into a fetching state, which blanks the active bars, and then forces a cold probe. It ran even when the removed account wasn't selected in any runtime lane.remove()keeps the normalized runtime selection from before the removal. After the settings update andsyncForCurrentSelection(), it compares that with the selection read back from the store. The quota refresh only runs if a lane's selection changed. That happens when the removed account was selected on host or WSL, or when sync repaired or dropped a stale selection. Everything else in removal is unchanged: record deletion, managed-home cleanup, cache eviction, credit-ledger cleanup, the runtime-home sync and the system-default lifecycle hook.normalizeActiveSelection()now uses the sameisDeepStrictEqualcomparison instead of comparinghostplusJSON.stringify(wsl). The result is the same, and the check no longer depends on key order.Why
The issue asks for exactly this: removing an inactive account shouldn't clear the active account's quota bars and trigger a cold probe. The gate is one condition at the single removal entry point. "Selection changed" is the signal the usage view actually depends on, and the selection is re-read after sync, so any repair sync makes still triggers a refresh. If in doubt, it refreshes, as before.
Linked Issue
Fixes #24942
Visual Proof
N/A. There is no layout change. The only visible difference is that the Codex usage bars no longer briefly blank after removing an inactive account, and this logic runs in the main process. Reproducing it in the app needs several real signed-in Codex accounts. Instead, the behavior is pinned by a focused test against
CodexAccountSelection(results under Testing).Testing
CodexAccountSelection.remove()with a fake store, rate-limits and runtime-home:main: 3 of 6 fail. Removing an inactive host account, an inactive WSL account, or any account while the host is on the system default all calledrefreshForCodexAccountChange.src/main/rate-limits/inactive-codex-accounts.test.tsandsrc/main/codex-accounts/managed-homes/host-codex-managed-home-ownership.test.tspass.Performance
None, because this only runs when a user removes a Codex account, and it does less work there by skipping a forced quota probe in the common case. The extra selection comparison costs about 0.27 µs with one WSL lane and about 3.6 µs with 50 lanes (micro-benchmark, Node 24). It adds no I/O, subprocesses or polling.
Risk
Level: Low. If the comparison missed a real selection change, the usage view would show stale bars until the next scheduled poll. The comparison reads the selection back after
syncForCurrentSelection(), so sync repairs are covered. No persisted format or IPC changes. A plain revert backs it out.Review
Agent skill upstream boundary
Notes
Original fix by @ggbdpq in #25105. Their selection-unchanged gate is kept in a reduced form: it drops the extra ownership-probe dependency, which the post-sync selection re-read makes unnecessary. Cross-platform, SSH/remote and mobile: no impact beyond the shared selection logic.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)