Skip to content

fix(status-bar): show the Active Server's usage in the rate-limit badges - #15804

Closed
yzxcj797 wants to merge 1 commit into
stablyai:mainfrom
yzxcj797:fix/usage-badges-environment-aware-15798
Closed

yzxcj797 wants to merge 1 commit into
stablyai:mainfrom
yzxcj797:fix/usage-badges-environment-aware-15798

Conversation

@yzxcj797

Copy link
Copy Markdown
Contributor

Summary

What

When a remote Active Server owns provider accounts (hasRemoteProviderAccountOwner), the status-bar usage badges now render the server's RateLimitState — taken from the provider-accounts snapshot the neighboring account roster already consumes (snapshot.rateLimits), which the status bar now watches for the pane's lifetime. The manual refresh button re-fetches that snapshot instead of running the local poll. Until the first remote snapshot lands, the Claude/Codex rows degrade to a fetching state rather than flashing local numbers; durability flags (minimax cookie / grok auth configured) stay local so bar visibility rules keep working. Without a remote owner, nothing changes.

Why

#15798 — the accounts list is environment-aware ("Showing accounts managed by ") while the usage badges beside it polled the local device, so they sat on Refresh failed / Refreshing sign-in… forever against stale local logins — and when local logins happened to be valid, they showed numbers describing a machine that runs no agents, which looks correct while being wrong.

The data was already flowing: the runtime's accounts snapshot carries the full server-side RateLimitState (streamed with its 5-minute poll), and the AccountsPane subscribed to the same watcher but dropped the rateLimits field. The status bar now consumes it.

Testing

  • New usage-rate-limits-source.test.ts (4 cases): local owner sees the local state untouched; remote owner sees the remote snapshot verbatim; before the first snapshot the Claude/Codex rows read fetching — never the stale local error — while durability flags stay local; a null provider stays null through the degrade. 4/4.
  • Status-bar suites: 287/288 — the one failure (resource-session-classification-parity) is pre-existing on main (verified identical with this change stashed; it scans mergeSnapshotAndSessions source, untouched here).
  • pnpm run typecheck clean.

Fixes #15798

With a remote Active Server, the usage badges kept polling the local
device: the accounts roster next to them was already environment-aware
('Showing accounts managed by <server>'), but the numbers came from the
local rate-limits slice, so the badges sat on 'Refresh failed' forever —
or worse, showed valid-looking numbers describing a machine that runs
no agents (stablyai#15798).

The provider-accounts snapshot the roster already consumes carries the
server's full RateLimitState; the status bar now watches that snapshot
when a remote environment owns accounts and renders its numbers. The
manual refresh re-fetches the snapshot instead of the local poll. Until
the first snapshot lands, Claude/Codex rows degrade to a fetching state
rather than flashing local numbers; without a remote owner nothing
changes.
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The status bar now detects remote active-server ownership and subscribes to provider-account snapshots. It resolves effective rate limits from local state or remote snapshots. It marks Claude and Codex as fetching before the first remote snapshot. Manual refresh fetches remote snapshots for remote-owned usage and retains local refresh behavior otherwise. Provider segments and usage-configuration flags use the effective rate-limit state. Unit tests cover source selection and fallback behavior.

Merge Risk: 🟡 Moderate · up to 48274

The change can show usage from the wrong active server after switching, refresh the wrong server's data, or hide locally configured MiniMax and Grok badges when remote data arrives. The PR is not merge-ready until these bounded correctness issues are addressed.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, rationale, issue, and testing, but omits required visual proof and most template sections. Add the required template sections, including Visual Proof with before/after evidence or N/A, checklist status, and review notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 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 describes the main change: status-bar badges now show usage from the active server.
Linked Issues check ✅ Passed The implementation addresses #15798 by using remote snapshot rate limits, refreshing remotely, and avoiding stale local values before the snapshot arrives.
Out of Scope Changes check ✅ Passed The changed status-bar logic and focused tests directly support the linked issue and stated objectives.

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.

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

Actionable comments posted: 2

Caution

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

⚠️ Outside diff range comments (1)
src/renderer/src/components/status-bar/StatusBar.tsx (1)

2128-2154: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Include the remote selection in handleRefresh dependencies.

handleRefresh captures remoteUsageOwner and activeRuntimeEnvironmentId, but omits both dependencies. After a server change, the next refresh can use the previous owner mode or request the previous server's snapshot. Add both dependencies and a regression test that switches servers before refresh.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 03260c64-e656-474d-ae0a-d59ee1fe50ba

📥 Commits

Reviewing files that changed from the base of the PR and between 4fd93ea and 48274b9.

📒 Files selected for processing (3)
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/renderer/src/components/status-bar/usage-rate-limits-source.test.ts
  • src/renderer/src/components/status-bar/usage-rate-limits-source.ts

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

Comment on lines +2056 to +2085
const remoteUsageOwner = hasRemoteProviderAccountOwner(settings)
const activeRuntimeEnvironmentId = settings?.activeRuntimeEnvironmentId?.trim() || null
const [remoteRateLimits, setRemoteRateLimits] = useState<RateLimitState | null>(null)
useEffect(() => {
if (!remoteUsageOwner) {
setRemoteRateLimits(null)
return
}
const watcher = watchProviderAccounts(
{ activeRuntimeEnvironmentId },
{
onSnapshot: (snapshot) => {
if (snapshot.rateLimits) {
setRemoteRateLimits(snapshot.rateLimits)
}
},
onError: (error) => {
console.error('Failed to stream remote usage snapshot:', error)
}
}
)
return () => {
watcher.close()
}
}, [remoteUsageOwner, activeRuntimeEnvironmentId])
const effectiveRateLimits = resolveStatusBarUsageRateLimits(
rateLimits,
remoteRateLimits,
remoteUsageOwner
)

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Scope remote rate limits to the active server.

When the user switches from remote server A to remote server B, remoteUsageOwner stays true and remoteRateLimits still contains server A data. The new watcher starts, but the status bar renders server A usage until server B sends its first snapshot.

Clear the state when the active server changes, or store the owner ID with the snapshot and ignore data whose owner does not match activeRuntimeEnvironmentId.

Comment on lines +21 to +22
if (remoteRateLimits) {
return remoteRateLimits

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Preserve local durability flags for remote usage.

Lines 21-22 replace minimaxCookieConfigured and grokAuthConfigured with remote values. StatusBar.tsx uses these effective values for visibility. This can hide locally configured MiniMax or Grok bars after the remote snapshot arrives.

Keep remote usage fields, but overwrite these two flags with localRateLimits values. Update the remote-snapshot test to assert this contract. The PR objective requires these durability flags to remain local for visibility rules.

Proposed fix
   if (remoteRateLimits) {
-    return remoteRateLimits
+    return {
+      ...remoteRateLimits,
+      minimaxCookieConfigured: localRateLimits.minimaxCookieConfigured,
+      grokAuthConfigured: localRateLimits.grokAuthConfigured
+    }
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (remoteRateLimits) {
return remoteRateLimits
if (remoteRateLimits) {
return {
...remoteRateLimits,
minimaxCookieConfigured: localRateLimits.minimaxCookieConfigured,
grokAuthConfigured: localRateLimits.grokAuthConfigured
}

@nwparker

Copy link
Copy Markdown
Contributor

Thanks for this @yzxcj797 — you found the right lever. Reusing ProviderAccountsSnapshot.rateLimits (which the accounts roster already consumes) means this needed no new RPC and no new stream opcode, which is exactly the cheapest form of option 1 in #15798.

Fork PRs in this repo only get the track-community-pr workflow, so I carried your commit onto an internal branch where it can run the full CI matrix: #15880. Your commit is cherry-picked with its original authorship intact, and my follow-up commit credits you with Co-authored-by.

I did add fixes on top, the main one being: markProviderFetching overwrote status but kept the local session/weekly windows, so getTightestUsageSection() still returned data and the badge kept rendering the local percentages — the degrade only kicked in when local data was already absent (which is why the test fixture with session: null passed). That plus honest handling of watcher errors, owner-scoping the cached snapshot across server switches, and the useCallback deps. All written up in the PR description.

Really appreciate the contribution — please don't close this one; I'll link it from #15880.

@nwparker

Copy link
Copy Markdown
Contributor

Thanks, @yzxcj797! This was rebuilt on current main and merged in #29430 (your approach was used). Closing as superseded.

@nwparker nwparker closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants