Skip to content

fix(codex-accounts): skip the usage refresh when removing an inactive Codex account - #25105

Merged
nwparker merged 1 commit into
stablyai:mainfrom
ggbdpq:fix/codex-account-removal-refresh
Nov 26, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
ggbdpq:fix/codex-account-removal-refresh

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Before: CodexAccountSelection.remove() always called startQuotaRefresh(...), which ends in refreshForCodexAccountChange. 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.
  • After: remove() keeps the normalized runtime selection from before the removal. After the settings update and syncForCurrentSelection(), 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 same isDeepStrictEqual comparison instead of comparing host plus JSON.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

  • Focused scenario test driving CodexAccountSelection.remove() with a fake store, rate-limits and runtime-home:
    • On 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 called refreshForCodexAccountChange.
    • On this branch: 6 of 6 pass. The 3 cases above no longer refresh. Removing the selected host account, removing the selected WSL account, and a sync that drops a stale host selection all still refresh.
  • src/main/rate-limits/inactive-codex-accounts.test.ts and src/main/codex-accounts/managed-homes/host-codex-managed-home-ownership.test.ts pass.
  • oxlint, oxfmt, anti-slop, native code-quality plugins, ast-grep and the changed-code-quality gate are clean on the touched file.
  • Platforms: macOS (unit level). The logic is platform-neutral, and the WSL lanes go through the same selection comparison.

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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Gate on no-op removal — CodexAccountSelection.remove() now skips syncForCurrentSelection() and refreshForCodexAccountChange(...) 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.ts wires isOwnedHostManagedHome over CodexManagedHomePath.assertHostOwnership, catching both UntrustedManagedCodexHomeError and ManagedCodexHomeTemporarilyUnavailableError and returning false, so an unprovable home fails safe to a refresh.
  • Regression coverage — five new cases in service-account-selection-and-removal.test.ts pin 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.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

Account removal now checks whether the selected host account’s home is owned by that account. When runtime selection remains unchanged and ownership is confirmed, removal skips runtime-home synchronization and quota refresh. Otherwise, the existing reconciliation and refresh flow continues. The tests cover inactive-account removal and cases where reconciliation must still run.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 030c3

Removing an inactive Codex account now leaves the active account's runtime and quota view alone, and the existing refresh path still runs when selection changes or ownership cannot be verified. No actionable merge-blocking risk remains.

Security architecture risk: Low · up to 030c3

The optimization preserves ownership checks and account cleanup, and falls back to synchronization when selection changes or ownership cannot be proven. No new security exposure was established. Recovery of quota state after a previously interrupted account switch remains incompletely verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed authority remains local to managed account selection and its runtime/quota integration. Persisted paths still pass account-specific validation before managed-home deletion; the new callback does not grant additional filesystem deletion authority.

Trust Boundaries and Controls

  • observed — The reused host ownership assertion canonicalizes paths, requires the expected account home within managed storage, rejects the system home, and checks a regular ownership marker matching the account. Untrusted or indeterminate homes do not authorize skipping reconciliation.

Resilience and Maintainability Implications

  • observed — Runtime-home construction synchronizes the current selection independently of removal. Managed host launch preparation resolves the currently selected account’s self-contained home rather than relying on a previously copied shared credential home, providing counterevidence to stale launch identity after an interrupted earlier switch.
Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed For [#24942], remove() skips synchronization and quota refresh only when the active account ID and normalized runtime selection are unchanged and the selected host account’s managed home passes the …
Out of Scope Changes check Passed The changes are limited to the account-removal refresh guard, wiring the ownership probe, and regression tests for [#24942]. The changed behavior and tests support the linked issue. No unrelated chang…
Title check Passed The title names the main change: removing an inactive Codex account no longer triggers a usage refresh. It matches the summary, the description, and the linked objectives. It uses the conventional fix…
Description check Passed The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (Fixes #24942), Visual Proof (N/A with reason), Testing with concrete results, Performance, Risk with…
Full details: Linked Issues check

Explanation

For [#24942], remove() skips synchronization and quota refresh only when the active account ID and normalized runtime selection are unchanged and the selected host account’s managed home passes the ownership probe. The service uses assertHostOwnership as a read-only probe and fails closed. Otherwise, the existing refresh path runs. The tests cover inactive removal, selected-account removal, failed ownership, system-default selection, and stale selection. They also verify that inactive-account removal still deletes its record and managed home and evicts its cache.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the account-removal refresh guard, wiring the ownership probe, and regression tests for [#24942]. The changed behavior and tests support the linked issue. No unrelated changes appear in the reviewed diff.

Full details: Title check

Explanation

The title names the main change: removing an inactive Codex account no longer triggers a usage refresh. It matches the summary, the description, and the linked objectives. It uses the conventional fix(scope) form and stays within a single sentence. At 83 characters it is slightly long but still clear.

Full details: Description check

Explanation

The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue (Fixes #24942), Visual Proof (N/A with reason), Testing with concrete results, Performance, Risk with level Low and a revert path, the Agent skill boundary checkbox, and the Checklist. It explains the mechanism in detail and states the rationale. The unchecked item is the pnpm lint/typecheck/test/build checklist entry, and the Testing section mentions lint and test results, so it is not a blocking gap. The AI Disclosure section is absent, which the template marks as optional for internal contributors. The description is mostly complete.

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

ℹ️ Recent review info

⚙️ Run configuration

  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1c7a6088-4638-4675-a474-4f653bbbfd00
📥 Commits

Reviewing files that changed from the base of the PR and between 8cd9751 and 030c3539cb1233a6940924a3136a7b3c177fa5f0.

📒 Files selected for processing (3)

  • src/main/codex-accounts/codex-account-selection.ts
  • src/main/codex-accounts/service-account-selection-and-removal.test.ts
  • src/main/codex-accounts/service.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@ggbdpq
ggbdpq force-pushed the fix/codex-account-removal-refresh branch from 030c353 to cb0bbd9 Compare October 25, 2026 12:54
@ggbdpq

ggbdpq commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto 7d18e19907 today. Upstream had modernized the test file's harness (installFakeAppEnvironment + importOriginal), so the five removal-gating regressions were re-seated onto the new harness unchanged in substance. Verification on the rebased head: the full src/main/codex-accounts/ directory passes 458/458 (including the five new cases covering inactive removal, selected removal, failed ownership probe, system default, and stale persisted selection), and pnpm run typecheck is green.

@nwparker gentle ping — happy to adjust anything.

@ggbdpq
ggbdpq force-pushed the fix/codex-account-removal-refresh branch from cb0bbd9 to 3251307 Compare November 5, 2026 21:05
@ggbdpq

ggbdpq commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and force-pushed. One conflict: the vitest environment helper import follows upstream's move into config/scripts/test-runtime/environment/, keeping this PR's rmSync usage intact.

Verified after the rebase: service-account-selection-and-removal.test.ts 14/14, typecheck:node, and format check clean.

@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]>
@nwparker
nwparker force-pushed the fix/codex-account-removal-refresh branch from 3251307 to 4995cd0 Compare November 26, 2026 22:35
@nwparker nwparker changed the title fix(codex-accounts): keep the active account's usage view intact when an inactive account is removed fix(codex-accounts): skip the usage refresh when removing an inactive Codex account Nov 26, 2026
@nwparker
nwparker merged commit aebfd35 into stablyai:main Nov 26, 2026
55 of 57 checks passed
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]: Removing an inactive Codex account refreshes the active account usage

2 participants