feat: track provider usage and project weekly quota#1605
feat: track provider usage and project weekly quota#1605Aditya190803 wants to merge 12 commits intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 11eab91d87
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
apps/server/src/wsServer.ts
Outdated
| const mergedUsage = mergeProviderUsage(cachedUsage, provider.usage); | ||
| if (mergedUsage !== undefined) { | ||
| nextCache[provider.provider] = mergedUsage; | ||
| continue; |
There was a problem hiding this comment.
Drop stale usage cache when provider snapshot has no usage
In mergeUsageCacheFromProviders, stale entries are never evicted because mergeProviderUsage(cachedUsage, provider.usage) returns cachedUsage whenever the new snapshot omits usage, so the mergedUsage !== undefined branch always keeps the cache and bypasses shouldKeepCachedUsage. This means a newer provider snapshot (checkedAt later than cached updatedAt) can still be served with outdated quota buckets via serverGetConfig and server.providersUpdated.
Useful? React with 👍 / 👎.
| if (limit !== null && limit > 0) { | ||
| return normalizePercent((usage / limit) * 100); |
There was a problem hiding this comment.
Avoid double-scaling low usage percentages
derivePercentFromUsage converts absolute usage to percent with (usage / limit) * 100, then passes that result to normalizePercent, which multiplies any value <= 1 by 100 again. For low-but-valid percentages (for example usage=1, limit=1000), this reports 10% instead of 0.1%, causing major quota misreporting near the start of a window.
Useful? React with 👍 / 👎.
2c50e2d to
6b8ed4d
Compare
|
I cleaned up the branch history to reduce review noise and make the change set easier to reason about. What changed:
Current commit structure:
Behavior/correctness included in this cleaned history:
Validation run locally:
No functional intent change; this is primarily a history hygiene pass for clearer review. |
|
Please add screenshots |
d9e0e20 to
00875eb
Compare
ApprovabilityVerdict: Needs human review This PR introduces substantial new functionality for tracking and displaying provider usage quotas across Claude and Codex providers. There are unresolved review comments identifying potential bugs in usage percentage calculations and cache staleness handling that warrant human attention before merging. You can customize Macroscope's approvability policy. Learn more. |
… provider usage normalization
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
|
@juliusmarminge this branch got pretty janky and inconsistent so i rebuilt it cleanly new PR here: #1732 closing this one to avoid confusion |

What Changed
Why
Issue #228 asks for accurate quota visibility. This PR adds provider usage projection and makes it robust under incremental updates so UI quota values stay correct. The follow-up fixes address reviewer-reported edge cases that could misreport low usage percentages or retain stale usage after newer snapshots.
UI Changes
Checklist
Closes #228
Note
Track provider rate limit usage and display weekly quota in settings
ServerProviderUsagecontract withfiveHourandweeklybuckets, normalizing rate-limit payloads from both Claude and Codex providers into a standard shape vianormalizeProviderUsageFromRateLimitsin providerUsage.ts.account,rateLimits, andusagefields to provider snapshots.probeCodexAccountStatein codexAppServer.ts to requestaccount/rateLimits/readalongside account data, with a grace window for missing rate-limit responses.ProviderUsageRowscomponent in the settings panel showing a progress bar, remaining percentage, and reset timestamp for each provider quota bucket.Macroscope summarized c44983f.
Note
Medium Risk
Medium risk because it extends provider probing/status snapshots and client refresh behavior, which can affect provider startup/perf and the accuracy of displayed quota data across Codex/Claude.
Overview
Adds first-class provider quota tracking by introducing
ServerProviderUsage(with normalizedfiveHour/weeklybuckets) and wiring it through provider status snapshots.Updates Codex and Claude provider probes to collect
accountmetadata plus rate-limit payloads, normalize them intousage, and include these fields onServerProvidersnapshots; Codex’s app-server probe now requestsaccount/rateLimits/readwith a short grace window for missing responses.Surfaces the data in the web settings UI via quota progress rows, and updates the client to eagerly call
refreshProviders()on initial config load/snapshot so quota/usage appears without waiting for stream updates. Tests are added/updated across contracts, provider registry/probes, ingestion activity projection, and usage normalization/merge edge cases.Reviewed by Cursor Bugbot for commit c44983f. Bugbot is set up for automated code reviews on this repo. Configure here.