You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(rate-limits): show saved account usage in the switcher - #24365
If you keep several Claude or Codex logins, each row in the account list now shows that login's limit, the same way the iOS accounts screen does. The row that is currently in use shows the session, weekly, and Fable numbers already in the header. Each other saved login shows its own numbers after a usage read. A dead login is not given a made-up percent.
What Changed
Before: the active account row only said Active. The limit in the header was not drawn on that row, so the login you would switch away from had no meter. Saved Claude rows stayed empty when the usage read failed. Refresh posted a form body with no scopes, which Claude Code 2.1.286 does not send, and a rejected access token whose expiry was still in the future was not refreshed at all.
After:
The active row draws the header's session, weekly, and Fable windows (Codex draws the weekly window it already has). System default gets those windows only while that row is the selected login. The Active label stays.
Other rows still draw the windows from their own usage read, using the existing used/remaining percentage setting.
Inactive Claude refresh matches Claude Code 2.1.286: JSON, the public client id, the prod scope list, and one retry with the stored scopes when the token endpoint returns invalid_scope.
If that usage read is a stale token and this call has not already refreshed, Orca refreshes once and reads usage again. A still-valid refresh token becomes windows. A refresh that fails does not invent a percent, and the CLI usage supplement still does not run for a different login.
An invalidated Codex login still offers Sign in. Other probe errors stay a status line.
Why
People who keep several saved logins pick the next account from the limit that is left. Painting the header windows on the active row uses numbers the app already has. Matching the Claude Code refresh request is what turns a rejected access token into those windows, instead of replacing the blank row with a status sentence. A dead refresh token still cannot show a real percent.
This does not persist the last reading across restart. That remains part of #14833 and is not what this change claims to finish.
Linked Issue
Part of #14833. Related: #21034. Does not close either issue.
Visual Proof
N/A for a packaged app screenshot: this change was not run inside a rebuilt desktop app. Unit tests cover the active row receiving the header windows, system default staying empty unless it is the selected login, the JSON refresh grant and the invalid_scope retry, and a not-yet-expired access token that is rejected, refreshed once, and then read as session and weekly windows.
Testing
Platforms: macOS (unit tests only).
I manually tested these changes locally
Automated tests added/updated, or explained why not below
node node_modules/vitest/vitest.mjs run --config config/vitest.config.ts on:
67 tests passed. oxlint reported 0 warnings on the production files this change edits.
AI Disclosure
Grok, xAI, was used to implement this change and the tests.
Review
Agent skill upstream boundary
Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Security: a failed OAuth read does not write or trust a CLI usage reading for a different login. The refresh log records status and error code only, not the token. Cross-platform: the grant and the row state are platform-neutral. SSH/remote: a remote-owned Codex account still does not get a local sign-in button. Mobile already draws these windows on each account row; this change is the desktop list catching up.
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)
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)
[High risk] Refactors OAuth token refresh and rate-limit display for saved accounts.
The PR appears safe to merge based on the changes since the previous review and the current state of prior findings.
Summary
The PR shows usage windows on the selected account row and uses each other saved account’s own usage read. It also updates Claude OAuth refresh requests, retries a rejected access token once, and shows account-specific error or sign-in states.
The changes since the previous review make credential rotation per-account and recognize a replaced access token even when the refresh token stays the same.
No new actionable issue was established in those changes.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
Menu[Account switcher] --> Active[Selected row: header usage]
Menu --> Inactive[Saved row: account usage read]
Inactive --> Queue[Per-account credential rotation queue]
Queue --> OAuth[Claude token refresh when needed]
Inactive --> Windows[Usage windows or status]
The reason will be displayed to describe this comment to others. Learn more.
✅ No new issues found.
Reviewed changes
Inactive Claude previews now return a classified failure — readInactiveClaudeOAuthUsage catches a rejected OAuth read and stores a makeClaudeUsageResult('error', …) with failureKind, attemptedSources: ['oauth'], and authProvenance: managed:<id>:inactive-preview, so the switcher row renders a real status instead of going blank.
Usage-panel supplement stays on the success path — fetchInactiveClaudeAccountUsage returns early when oauthLimits.status !== 'ok', so a 401 never falls through to a CLI reading that could belong to another login.
Inactive batches persist thrown failures — both Claude and Codex catch blocks store inactiveAccountPreviewFailure(...) through applyStalePolicy instead of deleting the cache, and skip the debounce stamp only when a whole batch threw with zero settlements so the next open retries.
Shared row-state maps inactive entries to a preview — new previewInactiveAccountUsage drives the switcher menus; isConfirmedSignedOut gains a Codex branch so an invalidated ChatGPT token becomes a sign-in while other probe errors keep their status line.
New Codex auth-error patterns — /please try signing in again/i and /authentication token has been invalidated/i.
One thing worth being aware of, not a defect: the new Codex branch lives in getUsageRosterRowState, which also backs UsageRosterPanel, so active-Codex rows can now flip from an error row to a sign-in row whose click routes to onSignIn rather than opening the provider. That matches the stated intent and existing component tests still pass.
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
Claude and Codex inactive-account fetch cycles now cache current, non-aborted failures as error previews. Shared row-state helpers classify active limits and inactive-account data. The Claude and Codex switcher menus use these previews to render loading, usage, sign-in, or message states. Codex authentication matching now recognizes invalidated-token messages, with tests covering authentication classification, preview states, and retry after a failed Claude fetch.
Merge Risk: Low · previous review dfa08
A failed usage read can leave an old percentage visible without warning. This is a bounded display risk; retained readings should be identified as stale.
Security architecture risk: Low · up to 64fdf
Refreshes remain tied to account-owned storage, and retries are bounded. No new account-boundary bypass or credential disclosure was established. The changed permission requests and incomplete recovery coverage warrant a low, rather than minimal, risk assessment.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The demonstrated credential-write scope is the saved account being processed, using its managed file or account-specific keychain entry. The shared coordinator does not itself confer authority over another account.
Trust Boundaries and Controls
observed — Managed credential reads and writes retain account-owned path resolution. WSL ownership checks include managed-root/path constraints and an account-matching ownership marker.
observed — The changed runtime refresh method is protected and called through runtime synchronization. The supplied test ranges exercise concurrency and token reuse; their public-API classification does not demonstrate a newly exposed external route.
observed — Inactive usage returns failed OAuth results before invoking a usage-panel supplement. The concurrency tests also expect token reuse without the token endpoint or PTY fallback.
Resilience and Maintainability Implications
inferred — A successful server-side rotation followed by a failed local write can leave storage holding an invalidated refresh token. Inactive usage keeps the new token only for the current fetch, without a demonstrated durable recovery mechanism. The base expiring-token path already had this limitation; the new stale-token retry inherits it.
observed — Inactive-preview cancellation and account-currentness checks prevent stale results from repopulating the usage cache, but an entered credential rotation has no caller abort signal. Cache cancellation is therefore distinct from cancellation of credential mutation.
Hardening Proposals
proposed — Consider an explicit recovery policy for rotated credentials that cannot be persisted, and verify removal/relogin interleavings against the same account identity. This would strengthen credential-lifecycle recovery rather than address a demonstrated account-boundary exploit.
Pre-merge checks: 5
Check name
Status
Explanation
Title check
The title "fix(rate-limits): show saved account usage in the switcher" matches the main change. The diff adds usage windows to account rows in the status bar switcher for both Claude and Codex. It als…
Description check
The description follows the repository template and fills in every required section: ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, AI Disclosure, Agent skill upstream boundary, Notes, …
Docstring Coverage
Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "fix(rate-limits): show saved account usage in the switcher" matches the main change. The diff adds usage windows to account rows in the status bar switcher for both Claude and Codex. It also fixes inactive account fetch errors and Claude refresh behavior. The title is specific and concise, and it follows a conventional commit style.
Full details: Description check
Explanation
The description follows the repository template and fills in every required section: ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, AI Disclosure, Agent skill upstream boundary, Notes, and Checklist. It states the before and after behavior, the mechanism, and the reasons for the approach. The Linked Issue section refers to #14833 as 'Part of' and does not close it. The Visual Proof section gives N/A with a reason. Some checklist items remain unchecked, including the lint, typecheck, test, and build item, and the Testing section lists macOS unit tests only. The template asks for a Linked Issue with a closing reference from outside contributors, and this description uses 'Part of' and 'Related' with no 'Fixes' line. The description is mostly complete, so it passes, but the reviewer should confirm the issue linking requirement and the unchecked build and test items.
Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Autopilot is currently an internal CodeRabbit preview.
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.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
ℹ️ Review info⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 891110b6-76ec-48aa-b6e6-559f4f03efcf
📥 Commits
Reviewing files that changed from the base of the PR and between 11e25e2af7cef1f05b501d9132e1a91626d8df75 and 3d27958b0af37d5da2e2a83cafb2a6561e18bbdb.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ No critical issues — one scope-selection edge case worth a look inline.
Reviewed changes
OAuth refresh posts a JSON grant with an explicit scope list — refreshClaudeOauthCredentials now builds a plan from the stored blob (client id, scopes, subscription) and posts application/json with scope, retrying once with the stored scopes on 400 invalid_scope.
Inactive usage re-reads the windows after a 401 — fetchInactiveClaudeAccountUsage refreshes once (and persists the rotation) when the OAuth read classifies as stale-token and no proactive refresh already ran.
Active rows paint the header windows — new previewAccountRowUsage drives both switcher menus, so the selected account's own row renders session/weekly/Fable meters (or its status line) instead of nothing.
Tests cover the JSON/scope body, the invalid_scope retry, the stored-client-id path, the 401 re-read, and active-row previews; the touched suites pass.
ℹ️ The new refresh body is covered only by a mocked net.fetch
refreshClaudeOauthCredentials now sends application/json with an explicit scope list, but the only coverage is a mocked net.fetch; the real token endpoint's accepted content type and scope semantics are not exercised. That module also backs the active managed-account launch refresh (runtime-auth-managed-credentials.ts:66), so a wrong contract would surface as a launch-time refresh failure rather than just a blank preview row. Since the PR notes no packaged-app run, a manual refresh against a real managed login would close the gap.
Technical details
# Real token-endpoint contract is unverified## Affected sites-`src/main/claude-accounts/oauth-refresh.ts:223-233` — posts `application/json` with `client_id` + `scope`; every test stubs `net.fetch`.
-`src/main/claude-accounts/runtime-auth/runtime-auth-managed-credentials.ts:66` — the same function refreshes the active managed account at launch.
## Required outcome- Confidence that the JSON body and scope list are accepted by the live `https://platform.claude.com/v1/oauth/token` endpoint for managed logins.
## Open questions for the human- Was the new body checked against a real account (not only the disassembled CLI), and does the active launch path still refresh?
A subscription login whose stored scopes do not include user:inference now retries with those stored scopes when the expanded list is rejected. A third-party client with no stored scopes omits scope instead of sending the first-party list.
The reason will be displayed to describe this comment to others. Learn more.
✅ No new issues found.
Reviewed changes
Third-party clients with no stored scopes now omit scope — scopes is string[] | null; a stored client id with an empty scope list sends no scope, so the server keeps that client's existing grant instead of being handed the first-party CLAUDE_CODE_REFRESH_SCOPES.
The invalid_scope retry is no longer gated on user:inference — storedScopeFallback now fires for any expanding first-party login with non-empty stored scopes that differ from the expanded list, so a subscription login whose blob only carries user:profile retries with that stored list.
postClaudeRefreshGrant only emits scope when non-empty — null/empty scope is dropped from the JSON body.
Tests cover both: omitting scope for a third-party client with none, and the subscription-login retry. Both fail against the prior logic, so they are real coverage.
The two scope-selection gaps raised in the previous review (oauth-refresh.ts:176-186) are addressed by this commit, and that thread is already resolved.
A saved Claude account whose managed credentials were removed reports exactly "No credentials" and no failure kind. That row is a missing sign-in, so the roster offers sign-in instead of "Refresh failed".
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ No critical issues — one maintainability note inline.
Reviewed changes
A bare No credentials inactive Claude preview now renders as signed out — isConfirmedSignedOut treats an exact No credentials error carrying no usageMetadata as a missing sign-in, so the saved-account row shows not signed in instead of a generic refresh-failure line. Covered by new assertions in usage-roster-row-state.test.ts for both getUsageRosterRowState and previewInactiveAccountUsage, which fail against the pre-commit logic.
The reason will be displayed to describe this comment to others. Learn more.
Important
The account-selection path can keep a stale access token when an inactive preview refreshed it without the server issuing a new refresh token — a response applyRefreshedToken explicitly supports. The fix is a one-condition change; details inline.
Reviewed changes
Introduced a shared credential-rotation queue — a module-global promise chain (managed-credential-rotation.ts) now serializes the inactive-preview refresh with account selection, so the two callers cannot rotate the same single-use Claude token concurrently.
Both paths re-read the managed blob inside the queue — persistRefreshedInactiveCredentials and refreshManagedAccountTokenIfNeeded re-read the latest credentials and materialize/keep that blob instead of refreshing the snapshot captured earlier, using the refresh token to detect a rotation by the other caller.
Structured the missing-credentials signal — noClaudeManagedCredentialsResult() now emits usageMetadata.failureKind: 'missing-credentials', and isConfirmedSignedOut drops its exact-string 'No credentials' match in favor of that field.
Added coverage — a new serialization test, a launch-refresh test for a refresh token another caller already rotated, and a fetcher test for a rotated token during a stale 401.
The reason will be displayed to describe this comment to others. Learn more.
✅ No new issues found.
Reviewed changes
Delta since Pullfrog's prior review (3ff08d95c8 → 64fdf7134b), which follows up on the earlier selection-path finding.
Rotation queue is now per-account — withClaudeManagedCredentialRotation(accountId, …) keeps one in-flight rotation per saved login in a Map, so a slow refresh for one account no longer head-of-line blocks another (the prior global chain's documented risk).
New storedOauthCredentialDiffers detects an access or refresh token change — replaces the refresh-token-only comparison in both the selection path and the inactive preview; token-based, so it ignores blob formatting differences.
Selection materializes a refreshed access token whose refresh token did not rotate — refreshManagedAccountTokenIfNeeded now returns the re-read blob when only the access token changed, resolving the prior [!IMPORTANT] finding (applyRefreshedToken supports a response with no refresh_token).
readAccessToken helper added and shared by the comparator; tests cover the new queue signature, per-account independence, and the access-token-only interleaving (launch-refresh and stale-401 fetcher cases).
The prior runtime-auth-managed-credentials.ts:80 thread is already resolved; no open Pullfrog threads remain. All four touched suites pass locally (44 tests).
Greptile encountered an error while reviewing this PR. Please reach out to [email protected] for assistance and include this reference: 06c6579e-9d77-49bc-9643-5e0ef085b77a.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
set -o pipefail
nl -ba src/renderer/src/components/status-bar/InlineProviderUsage.tsx | sed -n '1,220p'printf'%s\n''--- relevant inline usage tests ---'
nl -ba src/renderer/src/components/status-bar/inline-usage-bars.test.tsx | sed -n '50,210p'printf'%s\n''--- codex row remainder ---'
nl -ba src/renderer/src/components/status-bar/CodexSwitcherMenu.tsx | sed -n '247,290p'
Repository: stablyai/orca
Length of output: 16532
Show when retained usage is stale.
A thrown read can retain recent windows with status: 'error'. The row-state helper treats any retained window as kind: 'usage', and InlineUsageBars renders only the percentages and reset labels. It does not show the error or the age of the data.
Preserve the stale-window retention policy, but mark retained windows as stale or display the associated error in the switcher row. Removing the windows would conflict with the policy that preserves recent usage during transient failures.
A failed OAuth read for an inactive Claude account threw out of the batch, so the switcher kept no row. Return a classified result, retry a batch that stored nothing, and offer Codex sign-in only when the probe says that login is dead.
The active row only said Active, so the session, weekly, and Fable windows
already on the header never appeared on the login you would switch away
from. System default gets those windows only while it is the selected
login, matching the mobile accounts screen.
Inactive Claude logins also stayed blank when the access token was
rejected. Refresh posted a form body without scopes, which Claude Code
2.1.286 no longer sends, and a 401 before expiresAt never tried refresh.
The grant is now the CLI's JSON body, with one stored-scope retry on
invalid_scope. A stale-token usage read refreshes once and reads again,
so a still-valid refresh token becomes windows instead of an empty row.
A dead login is not given a made-up percent.
A saved Claude account whose managed credentials were removed reports that exact error and no failure kind. The roster was calling it a refresh failure, so the row offered no sign-in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
If you keep several Claude or Codex logins, each row in the account list now shows that login's limit, the same way the iOS accounts screen does. The row that is currently in use shows the session, weekly, and Fable numbers already in the header. Each other saved login shows its own numbers after a usage read. A dead login is not given a made-up percent.
What Changed
Before: the active account row only said Active. The limit in the header was not drawn on that row, so the login you would switch away from had no meter. Saved Claude rows stayed empty when the usage read failed. Refresh posted a form body with no scopes, which Claude Code 2.1.286 does not send, and a rejected access token whose expiry was still in the future was not refreshed at all.
After:
invalid_scope.Why
People who keep several saved logins pick the next account from the limit that is left. Painting the header windows on the active row uses numbers the app already has. Matching the Claude Code refresh request is what turns a rejected access token into those windows, instead of replacing the blank row with a status sentence. A dead refresh token still cannot show a real percent.
This does not persist the last reading across restart. That remains part of #14833 and is not what this change claims to finish.
Linked Issue
Part of #14833. Related: #21034. Does not close either issue.
Visual Proof
N/A for a packaged app screenshot: this change was not run inside a rebuilt desktop app. Unit tests cover the active row receiving the header windows, system default staying empty unless it is the selected login, the JSON refresh grant and the
invalid_scoperetry, and a not-yet-expired access token that is rejected, refreshed once, and then read as session and weekly windows.Testing
Platforms: macOS (unit tests only).
node node_modules/vitest/vitest.mjs run --config config/vitest.config.tson:src/main/claude-accounts/oauth-refresh.test.tssrc/main/rate-limits/claude-fetcher-managed-account-usage.test.tssrc/main/rate-limits/service-inactive-account-previews.test.tssrc/shared/codex-auth-errors.test.tssrc/renderer/src/components/status-bar/usage-roster-row-state.test.tssrc/renderer/src/components/status-bar/inline-usage-bars.test.tsxsrc/renderer/src/components/status-bar/codex-status-sign-in.test.tsx67 tests passed.
oxlintreported 0 warnings on the production files this change edits.AI Disclosure
Grok, xAI, was used to implement this change and the tests.
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Security: a failed OAuth read does not write or trust a CLI usage reading for a different login. The refresh log records status and error code only, not the token. Cross-platform: the grant and the row state are platform-neutral. SSH/remote: a remote-owned Codex account still does not get a local sign-in button. Mobile already draws these windows on each account row; this change is the desktop list catching up.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)