Skip to content

feat(routing): use pool-aware quota evidence for policy profiles - #1282

Merged
Wibias merged 5 commits into
devfrom
feat/pool-aware-routing-quota
Aug 8, 2026
Merged

feat(routing): use pool-aware quota evidence for policy profiles#1282
Wibias merged 5 commits into
devfrom
feat/pool-aware-routing-quota

Conversation

@Wibias

@Wibias Wibias commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Use Codex pool capacity when scoring an OpenAI policy candidate instead of treating the currently active account as the whole provider.

Expected semantics:

  • use the best known usable quota headroom across the live pool
  • mark the pool exhausted only when every relevant account is known exhausted
  • if all known accounts are exhausted but another account is unknown, keep pool quota unknown rather than falsely excluding it
  • keep account identities out of route traces
  • keep the existing account pool responsible for the physical account choice
  • share the same evidence helper between live routing and profile dry-runs

TDD state

The first commit intentionally adds failing tests for the missing pool aggregation helper. Implementation follows after the red state is confirmed.

Scope

  • quota evidence only; Codex pool health is already pool-aware on current dev
  • no routing-profile schema changes
  • no account-pool strategy changes
  • exact account selectors remain unchanged

Base inspected: dev at 3ad5bb6bd3f76f6879d84b78ea39edd3e01ec296.

Summary by CodeRabbit

  • New Features
    • Added Codex pool quota evaluation across multiple accounts.
    • Plans now apply the appropriate quota windows for each account.
    • Routing can report available pool headroom when at least one account remains usable.
    • Preserves unknown quota status when account data is unavailable.
    • Retains account-level evaluation when pool aggregation is not applicable.
  • Bug Fixes
    • Improved quota handling for exhausted pools, reset times, and partially unavailable account information.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 132b20f9-c130-4595-ba3f-db5f8219210a

📥 Commits

Reviewing files that changed from the base of the PR and between 62ed87a and b31abdd.

📒 Files selected for processing (2)
  • src/routing/quota.ts
  • tests/routing-policy-pool-quota.test.ts

📝 Walkthrough

Walkthrough

The quota module adds Codex pool aggregation with plan-specific windows and unknown-state handling. OpenAI candidate evaluation uses pooled evidence for multi-account plans. Tests cover headroom, exhaustion, reset timestamps, and partial unknown data.

Changes

Codex pool quota routing

Layer / File(s) Summary
Codex pool quota aggregation
src/routing/quota.ts
Adds CodexPoolQuotaAccount and codexPoolQuotaEvidence. Plan-specific windows determine usage and reset data. Pool evidence selects known usable headroom and reports unknown or exhausted states according to account coverage.
Plan-aware candidate evaluation and validation
src/routing/quota.ts, tests/routing-policy-pool-quota.test.ts
Aggregates cached accounts when a plan and multiple accounts are present. Single-account and plan-less evaluation remains account-specific. Tests cover headroom, live aggregation, reset timestamps, exhaustion, and unknown data.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CandidateEvaluation
  participant CachedAccounts
  participant codexPoolQuotaEvidence
  CandidateEvaluation->>CachedAccounts: Read cached Codex accounts
  CachedAccounts-->>CandidateEvaluation: Return account pool
  CandidateEvaluation->>codexPoolQuotaEvidence: Aggregate plan-specific quota
  codexPoolQuotaEvidence-->>CandidateEvaluation: Return RouteQuotaEvidence
Loading

Possibly related PRs

Suggested reviewers: ingwannu, lidge-jun

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: using pool-aware quota evidence for routing policy profiles.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/pool-aware-routing-quota

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.

@github-actions github-actions Bot added the enhancement New feature or request label Aug 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/routing/quota.ts`:
- Around line 40-66: Update codexAccountQuotaEvidence so it returns { known:
false } when maxPercent is undefined, before reporting exhaustion or usable
headroom; retain the existing evidence calculation when an applicable percentage
exists. Add a regression test covering a pool with one exhausted account and one
cached account lacking both weeklyPercent and monthlyPercent, ensuring the
latter remains unknown and cannot be treated as usable capacity.
- Around line 121-126: Replace the listAccountQuotas() membership used by the
input.codexAccountPlan evidence path with active CodexPoolQuotaAccount[] from
the shared config/account-pool layer. Populate every active account with its
plan and required current selector state, including deletion, credentials,
pause/avoid, reauth, credential generation, and probe lease data, before calling
codexPoolQuotaEvidence. Preserve the pool-size guard and add a regression
proving a removed high-headroom cached account cannot make the pool usable.
🪄 Autofix

❌ Autofix failed (check again to retry)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 74f567be-1f17-46b9-9901-563feeb58bfa

📥 Commits

Reviewing files that changed from the base of the PR and between 3ad5bb6 and 62ed87a.

📒 Files selected for processing (2)
  • src/routing/quota.ts
  • tests/routing-policy-pool-quota.test.ts

Comment thread src/routing/quota.ts
Comment thread src/routing/quota.ts
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

⚠️ Branch updated during autofix.

The branch was updated while autofix was in progress. Please try again.

Wibias commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

Review follow-up: the credits-only finding was valid and is fixed in 9d7a581 + b31abdd with a regression test. I re-checked the broader membership comment against the existing state-store contract: listAccountQuotas() is the reconciled quota snapshot and reconcileCodexQuotaAccounts() prunes IDs outside the live config generation. Pause/reauth/cooldown/soft-avoid remain separate health/pool-selection dimensions by design; duplicating the selector inside quota scoring would couple two evidence dimensions and drift from the existing pool authority. The PR therefore keeps quota aggregation over the reconciled quota snapshot rather than introducing a second account-eligibility implementation.

@Wibias
Wibias marked this pull request as ready for review August 8, 2026 12:05
@Wibias
Wibias merged commit f5147cb into dev Aug 8, 2026
39 of 42 checks passed
@Wibias
Wibias deleted the feat/pool-aware-routing-quota branch August 8, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant