Repository navigation
feat(codex): account quota policy (5h/weekly) with automatic rotation - #366
diegosouzapw merged 2 commits into
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a comprehensive system for managing Codex account quotas, specifically addressing 5-hour and weekly usage limits. The primary goal is to prevent service disruptions by automatically rotating traffic away from accounts nearing their quota exhaustion and re-enabling them after reset times, thereby improving reliability and reducing manual intervention for users. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Code Review SummaryStatus: Issues Resolved | Recommendation: Merge Overview
The previously flagged issue has been addressed in this diff:
Files Reviewed (7 files)
Positive observations:
|
There was a problem hiding this comment.
Code Review
This pull request introduces a quota management policy for Codex accounts, allowing for automatic rotation when usage thresholds for 5-hour or weekly windows are met. The changes include backend logic for tracking and enforcing these policies, as well as frontend components in the dashboard to manage them. The documentation has also been updated accordingly. My review focuses on improving code maintainability by reducing duplication, avoiding side effects in getter functions, and improving readability. I've identified a few areas for improvement, such as extracting duplicated logic into helper functions and replacing magic numbers with named constants.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0967295a51
ℹ️ 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".
- add quota window status helper for Codex session (5h) and weekly windows - enforce policy-based account filtering when enabled windows reach threshold - return all-rate-limited metadata when no Codex account is eligible - add per-account dashboard toggles for 5h and weekly policy controls - merge codexLimitPolicy safely on provider updates to preserve partial settings - document purpose and usage scenarios in README (EN + ID + i18n note)
- add user-facing success/error notifications for Codex limit toggle API calls - deduplicate Codex policy default normalization in providers page - make getQuotaWindowStatus side-effect free (no cache mutation in getter) - avoid stale threshold blocking after resetAt has passed - extract named Codex quota threshold constant - extract helper for earliest future reset date selection
0967295 to
1555883
Compare
|
😺 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1555883633
ℹ️ 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".
| if (policy.use5h && sessionStatus?.reachedThreshold) { | ||
| reasons.push(`5h usage ${Math.round(sessionStatus.usedPercentage)}%`); |
There was a problem hiding this comment.
Handle cold quota cache before applying Codex policy
This policy check treats a missing window status as eligible (sessionStatus/weeklyStatus stay null and no reason is added), so a fresh process with an empty quota cache will route traffic through accounts even when their 5h/weekly usage is already above the configured threshold. Because the cache is only populated after usage fetches/429-derived entries, the new default-ON policy can be silently bypassed after restart until another path seeds quota data.
Useful? React with 👍 / 👎.
| if (policyEligibleConnections.length === 0 && availableConnections.length > 0) { | ||
| const earliestResetAt = getEarliestFutureDate( | ||
| blockedByPolicy.map((entry) => entry.resetAt) | ||
| ); |
There was a problem hiding this comment.
Include cooldown accounts when computing retryAfter
When all currently available Codex accounts are filtered by quota policy, retryAfter is computed only from blockedByPolicy, but accounts already excluded by rateLimitedUntil are ignored here even if they recover sooner. In mixed states (policy-blocked + temporarily rate-limited), this can return a much later fallback window (often 5m), and downstream code uses it to set Retry-After, causing clients to back off longer than necessary.
Useful? React with 👍 / 👎.
…t-limit-rotation Thanks @rexname (Maulana Hasanudin)! 🎉 Codex account quota policy (5h/weekly) with auto-rotation is now merged. Highlights: - Per-account policy toggles (5h + weekly ON/OFF) in the Provider dashboard - Accounts automatically skipped when enabled quota window reaches 90% threshold - Auto re-eligibility when resetAt timestamp passes (no manual intervention needed) - Side-effect free `getQuotaWindowStatus` getter design - Safe partial merge of `codexLimitPolicy` on provider updates Merged on top of main (v2.5.0) with no conflicts. Analytics label fix (diegosouzapw#356) included. Thanks for the excellent quality and the 2-commit cleanup round! 🙏
- PR diegosouzapw#368: gpt-5.4 in Codex model registry (cx/gpt-5.4, codex/gpt-5.4) - PR diegosouzapw#367: Codex fast tier toggle (default-off, full stack, 48 tests) - PR diegosouzapw#366: Codex quota policy 5h/weekly with auto-rotation - fix diegosouzapw#356: analytics charts show provider display names not raw IDs
…t-limit-rotation Thanks @rexname (Maulana Hasanudin)! 🎉 Codex account quota policy (5h/weekly) with auto-rotation is now merged. Highlights: - Per-account policy toggles (5h + weekly ON/OFF) in the Provider dashboard - Accounts automatically skipped when enabled quota window reaches 90% threshold - Auto re-eligibility when resetAt timestamp passes (no manual intervention needed) - Side-effect free `getQuotaWindowStatus` getter design - Safe partial merge of `codexLimitPolicy` on provider updates Merged on top of main (v2.5.0) with no conflicts. Analytics label fix (diegosouzapw#356) included. Thanks for the excellent quality and the 2-commit cleanup round! 🙏
- PR diegosouzapw#368: gpt-5.4 in Codex model registry (cx/gpt-5.4, codex/gpt-5.4) - PR diegosouzapw#367: Codex fast tier toggle (default-off, full stack, 48 tests) - PR diegosouzapw#366: Codex quota policy 5h/weekly with auto-rotation - fix diegosouzapw#356: analytics charts show provider display names not raw IDs
…t-limit-rotation Thanks @rexname (Maulana Hasanudin)! 🎉 Codex account quota policy (5h/weekly) with auto-rotation is now merged. Highlights: - Per-account policy toggles (5h + weekly ON/OFF) in the Provider dashboard - Accounts automatically skipped when enabled quota window reaches 90% threshold - Auto re-eligibility when resetAt timestamp passes (no manual intervention needed) - Side-effect free `getQuotaWindowStatus` getter design - Safe partial merge of `codexLimitPolicy` on provider updates Merged on top of main (v2.5.0) with no conflicts. Analytics label fix (diegosouzapw#356) included. Thanks for the excellent quality and the 2-commit cleanup round! 🙏
- PR diegosouzapw#368: gpt-5.4 in Codex model registry (cx/gpt-5.4, codex/gpt-5.4) - PR diegosouzapw#367: Codex fast tier toggle (default-off, full stack, 48 tests) - PR diegosouzapw#366: Codex quota policy 5h/weekly with auto-rotation - fix diegosouzapw#356: analytics charts show provider display names not raw IDs
Why
Codex accounts can hit 5-hour and weekly quota windows during active sessions. When that happens, routing may repeatedly pick an account that is near exhaustion, causing avoidable failures and manual intervention.
This PR adds account-level limit policy controls and predictable rotation so traffic keeps flowing through eligible accounts.
What was implemented
5h(ON/OFF)Weekly(ON/OFF)session(5h) andweeklywindows.resetAt) so accounts become eligible again after reset.codexLimitPolicyin provider update API.Practical scenarios
5h ON+Weekly ON: account is skipped when either window reaches threshold.5h OFF+Weekly ON: only weekly window can block the account.5h ON+Weekly OFF: only 5h window can block the account.resetAtpasses: the account becomes eligible again automatically.Files changed
src/domain/quotaCache.tssrc/sse/services/auth.tssrc/app/api/providers/[id]/route.tssrc/app/(dashboard)/dashboard/providers/[id]/page.tsxREADME.mddocs/i18n/README.mddocs/i18n/id/README.mdVerification
npm run -s typecheck:core