t3code icon indicating copy to clipboard operation
t3code copied to clipboard

feat(sidebar): show provider quota usage in the sidebar footer

Open sharull9 opened this issue 4 months ago • 2 comments

Claude and Codex both report plan limits on every turn, but nothing surfaced them until you opened provider settings. This adds a quota meter to the sidebar footer.

What's here

Server — providerRateLimits.ts parses each driver's limit payload into one shared shape ({ planType, updatedAt, windows[] }), and the provider snapshot carries it to the client. Covered by providerRateLimits.test.ts (11 tests).

Sidebar — the footer shows only the two windows that answer "what stops me now" and "what stops me this week", so its height stays predictable. Overage earns a row only once it's actually live. Bars stay quiet until they matter: primary under 75%, warning at 75%, destructive at 90%.

Tooltip — the detail surface. Every window the provider reported, each with its own relative reset ("resets in 2h" beats a wall-clock time for the question the meter raises), the plan badge, and how stale the numbers are. The hovered window keeps a full-strength bar; the rest dim. Clicking any row opens provider settings.

Claude                      MAX 20X
─────────────────────────────────────
5h                        resets in 2h
▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░   62%
Weekly                    resets in 4d
▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░   18%
─────────────────────────────────────
Updated 3m ago        Open settings ↗

Edge cases

  • rateLimits present but empty means the account has no plan limits (API key, Bedrock, Vertex) — no rows at all, rather than a permanently pending meter.
  • Authenticated but nothing reported yet shows dashed placeholder rows; the tooltip explains limits arrive when a turn ends.
  • aria-label carries the whole card as one sentence, so screen readers lose nothing to the visual layout.

Testing

providerRateLimits.test.ts passes (11/11); @t3tools/web typechecks. The sidebar itself hasn't been exercised against a live authenticated provider yet.

🤖 Generated with Claude Code


[!NOTE] Medium Risk Touches provider snapshot push path and live Claude adapter event wiring; failures are mostly best-effort (Codex probe, experimental Claude usage API) but incorrect normalization could mislead users about quota.

Overview Adds account rate limits to the provider snapshot (ServerProvider.rateLimits in contracts) and a sidebar usage meter so Claude and Codex plan quota is visible without opening settings.

Server — New providerRateLimits.ts normalizes driver-native payloads into shared { planType, updatedAt, windows[] }, merges Claude windows by label (single-window rate_limit_event vs full /usage read), and streamRateLimitUpdates republishes snapshots as limits change. Codex reads account/rateLimits/read during status probes and attaches limits on the probe result. Claude adds a PubSub rateLimitEvents side channel (so snapshot enrichment does not compete with ProviderService on the turn event queue), publishes from rate_limit_event and experimental turn-end usage read, and keeps accumulated windows in a Ref across snapshot refreshes.

Web — SidebarUsageMeter in the footer shows 5h / Weekly (and live Overage) with color thresholds, tooltips for all windows, staleness, and navigation to provider settings; empty rateLimits.windows means no plan limits apply (no placeholder rows).

Reviewed by Cursor Bugbot for commit e67d3e22a6a132d70a45dd4705f0da29c840f3d3. Bugbot is set up for automated code reviews on this repo. Configure here.

[!NOTE]

Show provider quota usage meters in the sidebar footer

  • Adds ServerProviderRateLimits to the contracts schema and threads it through provider snapshots, covering both Claude (via a streaming rateLimitEvents side channel) and Codex (via account/rateLimits/read at probe time).
  • Introduces providerRateLimits.ts with normalization and merging utilities for provider-native rate-limit payloads, including window labeling, overage logic, and staleness stamping.
  • Renders a new SidebarUsageMeter component in the sidebar footer showing per-provider usage rows (5h, Weekly, Overage) with tooltips and reset timing, clicking through to provider settings.
  • The Claude adapter publishes rate-limit events to a PubSub side channel so consumers can subscribe without interfering with the main runtime event queue.
📊 Macroscope summarized e67d3e2. 10 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

🗂️ Filtered Issues

No issues evaluated.

sharull9 avatar Jul 27 '26 06:07 sharull9

[!IMPORTANT]

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2b6cafed-5ee1-4920-9702-290d40d187a7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • [ ] 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

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[bot] avatar Jul 27 '26 06:07 coderabbitai[bot]

Approvability

Verdict: Needs human review

5 blocking correctness issues found. This PR introduces a new feature (quota usage meters in the sidebar) with ~989 additions across server and client. Multiple unresolved review comments identify potential bugs including race conditions, stale state after logout, and debug logging left in production code.

You can customize Macroscope's approvability policy. Learn more.

macroscopeapp[bot] avatar Jul 27 '26 06:07 macroscopeapp[bot]

Closing in favor of #2829 (orchestration V2).

#2829 deletes the V1 orchestration layer this PR builds on — apps/server/src/orchestration/**, provider/Layers/*Adapter.ts and provider/Services/** are removed and replaced by apps/server/src/orchestration-v2/**, with the IPC surface renamed to ORCHESTRATION_V2_WS_METHODS. The files this PR touches either no longer exist or are rewritten, so it can't be rebased — it would need reimplementing against the V2 adapters.

This is not a judgement on the change itself. Several of these are real gaps we still want fixed; the base just moved out from under them.

Once #2829 merges, please rebase onto main, port the change to the V2 equivalent, and reopen (or open a fresh PR). Ping me and I'll prioritise the review.

juliusmarminge avatar Jul 30 '26 15:07 juliusmarminge

Ok will do that

sharull9 avatar Jul 30 '26 15:07 sharull9