@devries-cameron20 / t3code Mirror · read-only / commits / ee21337d84
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 23:30 UTC

fix(shared): a zero-credit cap no longer marks seat-based Codex out of usage (#34243)

Julius Marminge committed Nov 11, 2026 at 11:56 UTC ee21337d84d9db280fd74899e8ba82cd29a0a89c
3 files changed +46 -1
apps/server/src/provider/codexUsageLimits.test.ts
+36
@@ -1,3 +1,5 @@
1 +import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
2 +import { exhaustedUsageWindow } from "@t3tools/shared/usageLimits";
3 import * as CodexErrors from "effect-codex-app-server/errors";
4 import { describe, expect, it } from "vite-plus/test";
5
@@ -39,6 +41,40 @@ describe("codexRateLimitsToLimits", () => {
41 expect(codexRateLimitsToUpdate(snapshot)).toEqual({ windows });
42 });
43
44 + it("keeps a seat-based workspace with a zero credit cap usable while its plan windows have room", () => {
45 + const usageLimits = codexRateLimitsToLimits({
46 + checkedAt,
47 + snapshot: {
48 + limitId: "codex",
49 + planType: "team",
50 + rateLimitReachedType: null,
51 + primary: { usedPercent: 0, resetsAt: 1_784_000_000, windowDurationMins: 300 },
52 + secondary: { usedPercent: 14, resetsAt: 1_784_500_000, windowDurationMins: 10080 },
53 + individualLimit: { remainingPercent: 0, resetsAt: 1_796_083_200 },
54 + },
55 + });
56 + expect(
57 + exhaustedUsageWindow(
58 + {
59 + instanceId: ProviderInstanceId.make("codex"),
60 + driver: ProviderDriverKind.make("codex"),
61 + enabled: true,
62 + installed: true,
63 + version: null,
64 + status: "ready",
65 + auth: { status: "authenticated" },
66 + checkedAt,
67 + models: [],
68 + slashCommands: [],
69 + skills: [],
70 + usageLimits,
71 + },
72 + Date.parse(checkedAt),
73 + "gpt-6.1-sol",
74 + ),
75 + ).toBeUndefined();
76 + });
77 +
78 it("maps primary and secondary onto the session and weekly windows", () => {
79 expect(
80 codexRateLimitsToLimits({
packages/shared/src/usageLimits.test.ts
+1
@@ -130,6 +130,7 @@ describe("new thread model fallback", () => {
130 ["antigravity", ["gemini-weekly"], "claude-opus-5-5", false],
131 ["antigravity", ["3p-weekly"], "claude-opus-5-5", true],
132 ["antigravity", ["gemini-weekly"], "antigravity-default", true],
133 + ["codex", ["individual"], "gpt-5.5", true],
134 ["opencode", ["go_weekly"], "opencode/big-pickle", false],
135 ["opencode", ["go_weekly"], "opencode-go/big-pickle", true],
136 ] as const)("matches %s pools %s to %s", (driver, ids, model, usesFallback) => {
packages/shared/src/usageLimits.ts
+9 -1
@@ -28,7 +28,8 @@ export function exhaustedUsageWindow(
28 now: number,
29 model?: string,
30 ) {
31 - const exhausted = (provider?.usageLimits?.windows ?? []).filter(
31 + const windows = provider?.usageLimits?.windows ?? [];
32 + const exhausted = windows.filter(
33 (window) =>
34 (window.usedPercent ?? 0) >= 100 &&
35 (!window.resetsAt ||
@@ -54,6 +55,13 @@ export function exhaustedUsageWindow(
55 );
56 });
57 }
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 + }
65 case "opencode":
66 return exhausted.find(
67 (window) => !window.id.startsWith("go_") || model.startsWith("opencode-go/"),