Skip to content

fix(accounts): refresh status-bar usage on remote account switch - #20044

Open
rafapolo wants to merge 3 commits into
stablyai:mainfrom
rafapolo:fix/status-bar-usage-account-switch-refresh
Open

rafapolo wants to merge 3 commits into
stablyai:mainfrom
rafapolo:fix/status-bar-usage-account-switch-refresh

Conversation

@rafapolo

Copy link
Copy Markdown

Summary

  • When a paired remote Orca server's accounts.subscribe stream broadcasts a fresh snapshot after the active Claude/Codex account is switched, the snapshot's rateLimits field (refreshed usage for the new account) was received in AccountsPane but never applied to the shared store.
  • As a result, the bottom-left status-bar usage meter kept showing the outgoing account's numbers after a remote account switch, until a manual refresh.
  • This only affected the remote/paired-environment path — local account switches already refresh correctly via the rateLimits:update IPC push (ClaudeAccountSelection.select() → refreshForClaudeAccountChange()).
  • Fix: apply snapshot.rateLimits to the store via the existing setRateLimitsFromPush action whenever the field is present (it is null for local snapshots, so local behavior is unaffected).

Test plan

  • Added AccountsPane.remote-rate-limit-snapshot.test.tsx covering: (1) a remote snapshot with a populated rateLimits payload updates the store, (2) a local snapshot with rateLimits: null leaves the store untouched.
  • pnpm run tc:web
  • pnpm vitest run --config config/vitest.config.ts src/renderer/src/components/settings/AccountsPane.test.tsx src/renderer/src/components/settings/AccountsPane.remote-rate-limit-snapshot.test.tsx
  • oxlint on changed files

🤖 Generated with Claude Code

https://claude.ai/code/session_01UPMdb1h2Ens95YLBgjSFRK

The accounts.subscribe snapshot already carries refreshed rate-limit
usage after switching the active Claude/Codex account on a paired
remote server, but AccountsPane discarded the field instead of
pushing it into the shared store, so the bottom-left usage meter kept
showing the outgoing account's numbers.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UPMdb1h2Ens95YLBgjSFRK
@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

AccountsPane now applies remote snapshot rate limits through applyRemoteAccountRateLimits. The store merges Claude and Codex fields while preserving other local provider limits. New tests verify remote merging and unchanged state for local snapshots with rateLimits: null.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 7b6fd

Switching back to the local account can temporarily show remote usage or use a remote runtime target. Reload local rate limits on the local snapshot.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug, affected remote path, fix, and tests, but it does not follow the required template. It omits the required ELI5, What Changed, Why, Linked Issue, Visual Proof, Review,… Update the description to use the repository template. Add a linked issue after “Fixes #”, provide visual proof or write “N/A” with a reason, complete the required testing and checklist sections, and include the required review, boundary, n…
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: refreshing status-bar usage after switching accounts on a remote server.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the bug, affected remote path, fix, and tests, but it does not follow the required template. It omits the required ELI5, What Changed, Why, Linked Issue, Visual Proof, Review, Agent skill upstream boundary, Notes, and Checklist sections.

Resolution

Update the description to use the repository template. Add a linked issue after “Fixes #”, provide visual proof or write “N/A” with a reason, complete the required testing and checklist sections, and include the required review, boundary, notes, and AI disclosure information as applicable.

  • Fix all pre-merge checks with AI

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.

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

Important

The fix wholesale-replaces the renderer's shared rate-limit store with the remote snapshot, clobbering desktop-local provider usage. Only claude/codex are remote-scoped; the other providers are fetched from the desktop's own local credentials and get wiped on every snapshot.

Reviewed changes

  • Apply snapshot.rateLimits in AccountsPane — the onSnapshot handler now calls setRateLimitsFromPush(snapshot.rateLimits) when the field is present, and adds the action to the effect's dependency array.
  • New AccountsPane.remote-rate-limit-snapshot.test.tsx — covers a remote snapshot with populated rateLimits updating the store and a local snapshot with rateLimits: null leaving it untouched.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

setRateLimitsFromPush wholesale-replaced the shared rate-limit store
with the paired remote server's own RateLimitService.getState(),
which covers every provider, not just Claude/Codex. Since Gemini,
MiniMax, Grok, OpenCode Go, Kimi, and Antigravity are never
remote-scoped (they always read this desktop's own local
credentials), that clobbered their usage with the remote host's
unrelated local readings on every snapshot. Add
applyRemoteAccountRateLimits to merge in only the Claude/Codex
fields and leave the rest of the store untouched.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UPMdb1h2Ens95YLBgjSFRK
@rafapolo

Copy link
Copy Markdown
Author

Good catch — fixed in d43c0a3. Replaced the wholesale setRateLimitsFromPush(snapshot.rateLimits) with a new applyRemoteAccountRateLimits store action that merges in only claude/codex (plus their claudeTarget/codexTarget/inactiveClaudeAccounts/inactiveCodexAccounts) from the remote snapshot, leaving Gemini/MiniMax/Grok/OpenCode Go/Kimi/Antigravity untouched since those are never remote-scoped. Added a regression test asserting a pre-existing local Grok reading survives a remote Claude-usage merge.

@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

  • Scoped remote rate-limit merge — AccountsPane now applies snapshot.rateLimits through a new applyRemoteAccountRateLimits action instead of setRateLimitsFromPush, so only the remote-owned claude/codex/targets/inactive-account fields are merged and desktop-local providers plus their durability flags survive.
  • Strengthened test — the remote-snapshot test now seeds a desktop-local grok usage and asserts (by identity) it is not overwritten by the remote host's grok reading, which would fail under the prior wholesale replace.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@BeeSouul

Copy link
Copy Markdown

Opened #21466 with a reproduction of this exact symptom on a paired remote host (Orca 1.4.205 desktop, 1.4.203 remote), including per-account ground truth read from the usage endpoint, the remote host logs, and screenshots of the same popover showing identical figures under two different account names while both headers read "Updated just now".

It should cover the linked issue and visual proof the automated review asked for here. Happy to test a build on that setup.

…e-account-switch-refresh

# Conflicts:
#	src/renderer/src/components/settings/AccountsPane.tsx

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Reload local rate limits when leaving the remote scope. · rate-limits.ts:144-155

src/renderer/src/store/slices/rate-limits.ts:144-155
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reload local rate limits when leaving the remote scope.

applyRemoteAccountRateLimits replaces the shared Claude/Codex usage, runtime targets, and inactive-account caches. The local account snapshot sets rateLimits to null, and AccountsPane skips the update for that snapshot. Local status-bar consumers can therefore continue to use remote targets and caches, while feature-wall consumers can show remote usage.

Reload the local rate-limit state when the local snapshot arrives. Keep the existing merge for unrelated providers.

Suggested fix
   const applyRemoteAccountRateLimits = useAppStore((s) => s.applyRemoteAccountRateLimits)
+  const fetchRateLimits = useAppStore((s) => s.fetchRateLimits)
...
           if (snapshot.rateLimits) {
             applyRemoteAccountRateLimits(snapshot.rateLimits)
+          } else if (!activeRuntimeEnvironmentId) {
+            void fetchRateLimits()
           }
...
-  }, [activeRuntimeEnvironmentId, applyRemoteAccountRateLimits])
+  }, [activeRuntimeEnvironmentId, applyRemoteAccountRateLimits, fetchRateLimits])

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 3034007a-1d39-4031-a800-2e7fbc60be0b

📥 Commits

Reviewing files that changed from the base of the PR and between d43c0a3 and 7b6fd89.

📒 Files selected for processing (1)
  • src/renderer/src/components/settings/AccountsPane.tsx

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

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.

2 participants