Repository navigation
fix(accounts): fetch usage for the settings-selected Claude account - #34247
eatmoreduck wants to merge 1 commit into
Conversation
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
|
No actionable comments were generated in the recent review.
|
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:
prepareForRateLimitFetchprepared credentials viarouter.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, andaccounts.listderives 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:
prepareForRateLimitFetchresolves the active account with the existinggetSelectedClaudeAccountIdForTarget(settings, target)helper (host slot, or the per-distro WSL slot), and prepares that account's credentials through the existingaccountUsagePreparation(accountId)— the same per-account preparation the inactive-account usage fetch already uses. With no selection, the system-defaultpreparation()path is unchanged. A failed preparation still degrades to the existingprofile:unavailableusage 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
Not manually tested: verified at the service level. Two new cases in
runtime-auth-service.test.ts(red before the fix, green after):prepareForRateLimitFetchprepares that account viaaccountUsagePreparation(activeId)and never calls the router's globalpreparation();preparation()path is unchanged.Regression: all 1,123 tests under
src/main/claude-accountsandsrc/main/rate-limitspass exceptservice-zcode-usage.test.ts's "rejects an old CLI account result" case, which fails identically on a clean checkout oforigin/main(unrelated synthetic-credential fixture read);pnpm run typecheckandoxlintclean.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
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:unavailabledegradation 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.