-
Notifications
You must be signed in to change notification settings - Fork 670
feat(routing): use pool-aware quota evidence for policy profiles #1282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fb7a498
test(routing): define pool-aware policy quota evidence
Wibias ba00ac7
feat(routing): aggregate Codex pool quota evidence
Wibias 62ed87a
test(routing): cover live policy pool aggregation path
Wibias 9d7a581
fix(routing): keep percentless Codex quota unknown
Wibias b31abdd
test(routing): keep credits-only pool quota unknown
Wibias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { afterEach, describe, expect, test } from "bun:test"; | ||
|
|
||
| import { clearAccountQuota, setAccountQuotaFromParsed } from "../src/codex/quota"; | ||
| import { codexPoolQuotaEvidence, quotaEvidenceForCandidate } from "../src/routing/quota"; | ||
|
|
||
| afterEach(() => clearAccountQuota()); | ||
|
|
||
| describe("Codex pool quota evidence for routing policies", () => { | ||
| test("uses the best known usable headroom instead of only one active account", () => { | ||
| setAccountQuotaFromParsed("low", { weeklyPercent: 95 }); | ||
| setAccountQuotaFromParsed("healthy", { weeklyPercent: 20 }); | ||
| expect(codexPoolQuotaEvidence([ | ||
| { accountId: "low", plan: "plus" }, | ||
| { accountId: "healthy", plan: "plus" }, | ||
| ])).toMatchObject({ known: true, exhausted: false, headroom: 0.8, source: "codex-pool" }); | ||
| }); | ||
|
|
||
| test("the live policy evidence path aggregates the reconciled pool", () => { | ||
| setAccountQuotaFromParsed("active", { weeklyPercent: 96 }); | ||
| setAccountQuotaFromParsed("alternate", { weeklyPercent: 25 }); | ||
| expect(quotaEvidenceForCandidate({ | ||
| provider: "openai", | ||
| model: "gpt-5.6", | ||
| codexAccountId: "active", | ||
| codexAccountPlan: "plus", | ||
| })).toMatchObject({ known: true, exhausted: false, headroom: 0.75, source: "codex-pool" }); | ||
| }); | ||
|
|
||
| test("reports exhausted only when every pool account is known exhausted", () => { | ||
| setAccountQuotaFromParsed("a", { weeklyPercent: 100, weeklyResetAt: Date.now() + 60_000 }); | ||
| setAccountQuotaFromParsed("b", { weeklyPercent: 100, weeklyResetAt: Date.now() + 120_000 }); | ||
| const evidence = codexPoolQuotaEvidence([ | ||
| { accountId: "a", plan: "plus" }, | ||
| { accountId: "b", plan: "plus" }, | ||
| ]); | ||
| expect(evidence.known).toBe(true); | ||
| expect(evidence.exhausted).toBe(true); | ||
| expect(evidence.headroom).toBe(0); | ||
| expect(evidence.resetAtMs).toBeDefined(); | ||
| }); | ||
|
|
||
| test("does not call a partially unknown pool exhausted", () => { | ||
| setAccountQuotaFromParsed("known-exhausted", { weeklyPercent: 100 }); | ||
| expect(codexPoolQuotaEvidence([ | ||
| { accountId: "known-exhausted", plan: "plus" }, | ||
| { accountId: "unknown", plan: "plus" }, | ||
| ])).toEqual({ known: false }); | ||
| }); | ||
|
|
||
| test("credits-only cached evidence stays unknown", () => { | ||
| setAccountQuotaFromParsed("known-exhausted", { weeklyPercent: 100 }); | ||
| setAccountQuotaFromParsed("credits-only", { resetCredits: 7 }); | ||
| expect(codexPoolQuotaEvidence([ | ||
| { accountId: "known-exhausted", plan: "plus" }, | ||
| { accountId: "credits-only", plan: "plus" }, | ||
| ])).toEqual({ known: false }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.