Repository navigation
fix(combos): hold a spent usage window for ten minutes, not sixty seconds #5874
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
Closed
vadymhimself
wants to merge
5
commits into
lidge-jun:dev
from
vadymhimself:fix/codex-exhaustion-cooldown-duration
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6306126
fix(combos): hold a spent usage window for ten minutes, not 60 seconds
vadymhimself 9285e60
fix(combos): treat a bare 1308 as a spent window, and document the hold
vadymhimself fbfaf63
docs(combos): put the usage-window hold ahead of the request-rate fal…
vadymhimself 2232bda
docs(combos): document the usage-window hold in every passage and locale
vadymhimself 251fd65
test(combos): pin that exhaustion outranks the request-rate fallback
vadymhimself 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
72 changes: 72 additions & 0 deletions
72
tests/codex-integration/combo-codex-exhaustion-cooldown.test.ts
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,72 @@ | ||
| import { afterEach, describe, expect, test } from "bun:test"; | ||
| import { | ||
| clearComboTargetCooldowns, | ||
| comboFailureCooldownScope, | ||
| comboFailureDecision, | ||
| coolComboTarget, | ||
| isComboTargetInCooldown, | ||
| } from "../../src/combos/failover"; | ||
|
|
||
| /** | ||
| * The ChatGPT Codex backend reports a depleted plan window as HTTP 502 `upstream_server_error` | ||
| * carrying the prose `The usage limit has been reached`, never the documented 429. The | ||
| * quota-cap predicate is gated on 429, so a dead account took the generic 60-second cooldown and | ||
| * was re-offered every minute: 942 doomed sends in 72h of production ledger, each surfacing as | ||
| * `adapter_eof`, plus 94 downstream `503 No available targets`. See #5860. | ||
| * | ||
| * The fix is duration only. Delete the exhaustion arm of `coolComboTarget`'s `cooldownMs` chain | ||
| * and the ten-minute assertions below go back to 60 seconds. | ||
| */ | ||
| const combo = "codex-exhaustion-burn-test"; | ||
| const target = { provider: "openai", model: "gpt-6-astra" }; | ||
| const now = Date.UTC(2026, 8, 24, 12, 0, 0); | ||
| const EXHAUSTED = "The usage limit has been reached"; | ||
|
|
||
| afterEach(() => clearComboTargetCooldowns(combo)); | ||
|
|
||
| describe("a depleted Codex plan window", () => { | ||
| test.each([ | ||
| ["502 prose", 502, "upstream_server_error", EXHAUSTED], | ||
| ["429 structured code", 429, "usage_limit_exceeded", "quota"], | ||
| ["structured usage_limit_reached", 502, "usage-limit-reached", "upstream error"], | ||
| ["vendor 5-hour window", 429, "1308", "Usage limit reached for 5 hour"], | ||
| ])("cools the target for ten minutes, not 60s (%s)", (_label, status, code, message) => { | ||
| coolComboTarget(combo, target, { now, status, code, message }); | ||
| // The whole point: still cooling a minute later, when the 60s default would have expired. | ||
| expect(isComboTargetInCooldown(combo, target, now + 60_000)).toBe(true); | ||
| expect(isComboTargetInCooldown(combo, target, now + 10 * 60_000 - 1)).toBe(true); | ||
| expect(isComboTargetInCooldown(combo, target, now + 10 * 60_000)).toBe(false); | ||
| }); | ||
|
|
||
| test("hops without blacking out the whole provider", () => { | ||
| // Scope and decision are untouched by this change: a Codex 502 still resolves `target` scope | ||
| // and `hop` through the existing `status >= 500` path, which is why the status-blind prose | ||
| // match is kept out of `isProviderScopedQuotaCap`. | ||
| expect(comboFailureCooldownScope(502, EXHAUSTED, { code: "upstream_server_error" })).toBe("target"); | ||
| expect(comboFailureDecision(502, EXHAUSTED, { code: "upstream_server_error" })).toBe("hop"); | ||
| }); | ||
|
|
||
| test("an unrelated 502 keeps the 60-second default", () => { | ||
| coolComboTarget(combo, target, { now, status: 502, code: "upstream_server_error", message: "bad gateway" }); | ||
| expect(isComboTargetInCooldown(combo, target, now + 60_000 - 1)).toBe(true); | ||
| expect(isComboTargetInCooldown(combo, target, now + 60_000)).toBe(false); | ||
| }); | ||
|
|
||
| test("a bare 1308 code with no prose still takes the exhaustion hold", () => { | ||
| coolComboTarget(combo, target, { now, status: 429, code: "1308", message: "" }); | ||
| expect(isComboTargetInCooldown(combo, target, now + 10 * 60_000 - 1)).toBe(true); | ||
| expect(isComboTargetInCooldown(combo, target, now + 10 * 60_000)).toBe(false); | ||
| }); | ||
|
|
||
| test("an explicit server Retry-After still outranks the exhaustion default", () => { | ||
| coolComboTarget(combo, target, { now, status: 502, code: "upstream_server_error", message: EXHAUSTED, retryAfter: "30" }); | ||
| expect(isComboTargetInCooldown(combo, target, now + 30_000 - 1)).toBe(true); | ||
| expect(isComboTargetInCooldown(combo, target, now + 30_000)).toBe(false); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| test("an operator's configured cooldownMs still outranks the exhaustion default", () => { | ||
| coolComboTarget(combo, target, { now, status: 502, code: "upstream_server_error", message: EXHAUSTED, cooldownMs: 5_000 }); | ||
| expect(isComboTargetInCooldown(combo, target, now + 5_000 - 1)).toBe(true); | ||
| expect(isComboTargetInCooldown(combo, target, now + 5_000)).toBe(false); | ||
| }); | ||
| }); | ||
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
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.