Skip to content

fix(accounts): fetch usage for the settings-selected Claude account - #34247

Open
eatmoreduck wants to merge 1 commit into
stablyai:mainfrom
eatmoreduck:fix/34201-usage-active-account
Open

eatmoreduck wants to merge 1 commit into
stablyai:mainfrom
eatmoreduck:fix/34201-usage-active-account

Conversation

@eatmoreduck

Copy link
Copy Markdown
Contributor

ELI5

The usage popover's percentages and the "Claude account" name under them could disagree: the name follows the account selected in Settings, while the numbers were fetched with whatever account the profile router happened to point at. Now the fetch always uses the Settings-selected account.

What Changed

Before: prepareForRateLimitFetch prepared credentials via router.preparation() — the router's current pointer, which can lag or disagree with the Settings selection. The popover's email row (resolveClaudeStatusAccountState) reads the Settings selection on every render, and accounts.list derives its active account from the same settings, so when the two sources disagreed the popover showed one account's quota under another account's name (#34201).

After: prepareForRateLimitFetch resolves the active account with the existing getSelectedClaudeAccountIdForTarget(settings, target) helper (host slot, or the per-distro WSL slot), and prepares that account's credentials through the existing accountUsagePreparation(accountId) — the same per-account preparation the inactive-account usage fetch already uses. With no selection, the system-default preparation() path is unchanged. A failed preparation still degrades to the existing profile:unavailable usage error rather than interrupting other providers.

Why

Every consumer that names an account (email row, accounts.list) agrees by construction because both read the settings selection; the fetch was the only side with its own notion. Routing it through the same selection removes the disagreement at its only source, reusing the two existing primitives instead of adding a third notion of "active". Alternative considered: making the email row follow the fetch's account instead — but the settings selection is what every other surface (launch routing, accounts UI) already treats as authoritative.

Linked Issue

Fixes #34201

Visual Proof

N/A — the change is credential selection for a background fetch (which account's OAuth identity the usage request carries), not layout; verified by unit tests asserting the prepared account. The rendered popover is unchanged apart from the numbers now matching the named account.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Not manually tested: verified at the service level. Two new cases in runtime-auth-service.test.ts (red before the fix, green after):

  1. with a settings-selected account, prepareForRateLimitFetch prepares that account via accountUsagePreparation(activeId) and never calls the router's global preparation();
  2. with no selection, the system-default preparation() path is unchanged.

Regression: all 1,123 tests under src/main/claude-accounts and src/main/rate-limits pass except service-zcode-usage.test.ts's "rejects an old CLI account result" case, which fails identically on a clean checkout of origin/main (unrelated synthetic-credential fixture read); pnpm run typecheck and oxlint clean.

AI Disclosure

GLM coding agent (Zhipu), human-supervised: the agent traced both data chains, wrote the red tests and the fix; the contributor reviewed the diff and the regression matrix.

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

Cross-platform: the WSL branch resolves through the same helper's per-distro selection and uses the WSL router's two-argument accountUsagePreparation; the stopped-distro guard and the catch-to-profile:unavailable degradation are unchanged, so polling other providers is never interrupted. Backwards compatibility: with no managed accounts selected the behavior is byte-for-byte the old path.

The status popover reads the email row from the settings selection every
render, but the quota numbers went through prepareForRateLimitFetch,
which prepared whatever the profile router currently pointed at, so the
percentages could belong to a different account than the one named under
them. Resolve the active account with getSelectedClaudeAccountIdForTarget
and prepare that account's credentials for the fetch; without a selection
the system-default preparation is unchanged.

Fixes stablyai#34201
@coderabbitai

coderabbitai Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 541b522b-d8f3-4ceb-a8ef-11231c1acea6
Commits

Reviewing files that changed from the base of the PR and between 6357bd7 and 7180319.

Files selected for processing: 2
  • src/main/claude-accounts/runtime-auth-service.test.ts
  • src/main/claude-accounts/runtime-auth-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.

Walkthrough

prepareForRateLimitFetch now checks the selected Claude account ID. When an ID is selected, it requests account-specific usage preparation from the WSL or host router. Otherwise, it uses the existing general preparation. Tests cover both cases.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 71803

Claude usage requests now follow the account selected in Settings, so the usage shown matches the account email. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: usage is fetched for the Claude account selected in Settings.
Description check Passed The description is complete and directly explains the user impact, implementation, rationale, linked issue, visual proof, testing, AI disclosure, and compatibility considerations. The repository Check…
Linked Issues check Passed Issue #34201 requires the Claude usage values and displayed account identity to refer to the same account. prepareForRateLimitFetch now resolves the Settings selection with `getSelectedClaudeAccount…
Out of Scope Changes check Passed The reviewed changes are limited to quota-fetch account selection in runtime-auth-service.ts and tests in runtime-auth-service.test.ts. The implementation and tests directly support issue #34201. …
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
Full details: Description check

Explanation

The description is complete and directly explains the user impact, implementation, rationale, linked issue, visual proof, testing, AI disclosure, and compatibility considerations. The repository Checklist section is omitted, but the substantive checklist information is covered elsewhere and the description explains that manual testing was not performed.

Full details: Linked Issues check

Explanation

Issue #34201 requires the Claude usage values and displayed account identity to refer to the same account. prepareForRateLimitFetch now resolves the Settings selection with getSelectedClaudeAccountIdForTarget and uses account-specific preparation for host and WSL targets. The no-selection path still uses router preparation(). Tests cover selected-account preparation and the no-selection fallback.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to quota-fetch account selection in runtime-auth-service.ts and tests in runtime-auth-service.test.ts. The implementation and tests directly support issue #34201. No unrelated change is shown.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

  • Autofix · 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

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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]: Usage popover shows the active Claude account's usage under a different account's email

1 participant