Conversation
The preemptive quota scheduler calculated deferrals from the nearest reset window. When a later primary or secondary reset was still active, that shortened the effective cooldown and let requests resume too early. Use the longest relevant reset window for 429 deferrals and for near-exhaustion quota deferrals so cooldowns stay aligned with the latest active quota window.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 25 minutes and 8 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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 |
|
Superseded by #387, which rebuilds the full open PR stack onto one reviewed integration branch. |
|
Closing in favor of #387. |
Problem
PreemptiveQuotaScheduler.getDeferral()was computing cooldowns from the nearest reset window.That causes cooldown drift when a later primary or secondary quota window is still active: the scheduler can resume traffic early even though another active quota window has not reset yet.
Fix
Use the longest relevant reset window instead of the nearest one.
429snapshots, defer until the latest active reset across primary and secondary windows.Changes
lib/preemptive-quota-scheduler.ts429deferralstest/preemptive-quota-scheduler.test.tsValidation
note: greptile review for oc-chatgpt-multi-auth. cite files like
lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.Greptile Summary
replaces nearest-window cooldown selection with longest-window in
getDeferral(), fixing premature quota resumption when a longer secondary reset window is still active. both the 429 and near-exhaustion paths now correctly defer until all relevant windows have reset, backed by two new regression tests.Confidence Score: 5/5
safe to merge — the fix is correct, all 16 tests pass, and the change is well-scoped
both findings are p2 style/coverage; the core logic correctly uses Math.max across windows for both the 429 and near-exhaustion paths, which is exactly the stated intent. no concurrency issues — all scheduler methods are synchronous with no async gaps in the map mutations. no filesystem or token handling touched.
no files require special attention; redundancy in getDeferral is cosmetic only
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["getDeferral(key, now)"] --> B{scheduler enabled?} B -- no --> Z[defer: false, waitMs: 0] B -- yes --> C{snapshot exists?} C -- no --> Z C -- yes --> D["compute primaryWait = max(0, primary.resetAtMs - now)\ncompute secondaryWait = max(0, secondary.resetAtMs - now)\nlongestWait = max(primaryWait, secondaryWait)"] D --> E{status === 429\nAND longestWait > 0?} E -- yes --> F["bounded = min(longestWait, maxDeferralMs)\ndefer: true, reason: rate-limit"] E -- no --> G{primaryNearExhausted\nOR secondaryNearExhausted?} G -- yes --> H["nearExhaustedWait = max(\n primaryNearExhausted ? primaryWait : 0,\n secondaryNearExhausted ? secondaryWait : 0\n)"] H --> I{nearExhaustedWait > 0?} I -- yes --> J["bounded = min(nearExhaustedWait, maxDeferralMs)\ndefer: true, reason: quota-near-exhaustion"] I -- no --> Z G -- no --> ZPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix: stop quota scheduler cooldown drift" | Re-trigger Greptile