Skip to content

Commit c99cd28

Browse files
fix(shared): a zero-credit cap no longer marks seat-based Codex out of usage
Codex reports a monthly credit cap (individualLimit) beside the 5-hour and weekly plan windows. On a seat-based workspace that gives members no credits, that cap reads 0 of 0 and maps to a 100%-used monthly window, so exhaustedUsageWindow called the whole provider exhausted and new threads, text generation and MCP thread creation switched to the fallback model. Credits only pay for use past the plan windows, so the credit cap now counts as exhausting Codex only when no plan windows are reported (usage- based Enterprise plans). Plan windows at 100% still exhaust it. Fixes #34234 AI-assisted; verified with the tests and tools listed above.
1 parent 7e440fe commit c99cd28

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎packages/shared/src/usageLimits.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ describe("new thread model fallback", () => {
130130
["antigravity", ["gemini-weekly"], "claude-opus-5-5", false],
131131
["antigravity", ["3p-weekly"], "claude-opus-5-5", true],
132132
["antigravity", ["gemini-weekly"], "antigravity-default", true],
133+
["codex", ["individual"], "gpt-5.5", true],
133134
["opencode", ["go_weekly"], "opencode/big-pickle", false],
134135
["opencode", ["go_weekly"], "opencode-go/big-pickle", true],
135136
] as const)("matches %s pools %s to %s", (driver, ids, model, usesFallback) => {

‎packages/shared/src/usageLimits.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export function exhaustedUsageWindow(
2828
now: number,
2929
model?: string,
3030
) {
31-
const exhausted = (provider?.usageLimits?.windows ?? []).filter(
31+
const windows = provider?.usageLimits?.windows ?? [];
32+
const exhausted = windows.filter(
3233
(window) =>
3334
(window.usedPercent ?? 0) >= 100 &&
3435
(!window.resetsAt ||
@@ -54,6 +55,13 @@ export function exhaustedUsageWindow(
5455
);
5556
});
5657
}
58+
case "codex": {
59+
// Seat-based plans spend credits only past their plan windows, so the credit cap blocks only plans without them.
60+
const hasPlanWindows = windows.some(
61+
(window) => window.id === "primary" || window.id === "secondary",
62+
);
63+
return exhausted.find((window) => window.id !== "individual" || !hasPlanWindows);
64+
}
5765
case "opencode":
5866
return exhausted.find(
5967
(window) => !window.id.startsWith("go_") || model.startsWith("opencode-go/"),

0 commit comments

Comments
 (0)