feat: track provider usage and project weekly quota#1605
feat: track provider usage and project weekly quota#1605Aditya190803 wants to merge 3 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 👍 / 👎.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| planType: "pro", | ||
| }); | ||
| expect(state.rateLimits).toBeNull(); | ||
| }); |
There was a problem hiding this comment.
Grace period exceeds test abort timeout causing rejection
High Severity
The test passes AbortSignal.timeout(1_000) (1s) but RATE_LIMITS_PROBE_GRACE_MS is 1_500 (1.5s). When the stub ignores account/rateLimits/read, the grace timer starts after the account snapshot is set. The abort signal fires at ~1s — before the 1.5s grace timer resolves rateLimitsPayload to null — causing fail() to reject the promise with an abort error instead of the expected successful resolution.
Additional Locations (1)
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 |


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 usage quotas and display weekly/5-hour usage buckets in settings
normalizeProviderUsageFromRateLimitsin providerUsage.ts to derive standardizedServerProviderUsageBucketrecords from heterogeneous Codex and Claude rate-limit payloads.account,rateLimits, and derivedusagefields on theServerProvidersnapshot.account.rate-limits.updatedevents, and pushesserverProvidersUpdatedonly when usage materially changes.ProviderUsageRowsto the settings UI to render a progress bar, remaining percentage, and reset timestamp for each usage bucket.serverGetConfigandserverRefreshProvidersresponses now include provider usage fields; stale cached usage is dropped when the provider snapshot has a newer timestamp.Macroscope summarized 6b8ed4d.
Note
Medium Risk
Touches provider probing and WebSocket provider update logic to ingest and cache rate-limit events; bugs here could cause incorrect quota display or extra/missed
serverProvidersUpdatedpushes.Overview
Adds end-to-end provider quota/usage tracking by extending
ServerProvidersnapshots with optionalaccount,rateLimits, and normalizedusagebuckets (weekly/5-hour).Codex and Claude probes now collect rate-limit payloads (Codex via
account/rateLimits/read+account/rateLimits/updated, Claude via SDKrate_limit_eventcapture), normalize them via newnormalizeProviderUsageFromRateLimits, and attach derivedusageto provider status.The server now maintains a per-provider usage cache that merges incremental
account.rate-limits.updatedruntime events, drops stale cached usage when newer provider snapshots omit it, and only pushesserver.providersUpdatedwhen usage materially changes; the settings UI renders these buckets as progress bars with remaining percent and reset time.Written by Cursor Bugbot for commit 6b8ed4d. This will update automatically on new commits. Configure here.