Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix(codex): raise default quota threshold from 90% to 99% to avoid premature account blocking (#1697)

diegosouzapw8100b53fd71c
diff --git a/src/domain/quotaCache.ts b/src/domain/quotaCache.ts
index 759335228c..61017e5123 100644
--- a/src/domain/quotaCache.ts
+++ b/src/domain/quotaCache.ts
@@ -49,6 +49,7 @@ const ACTIVE_TTL_MS = 5 * 60 * 1000; // 5 minutes for active accounts
const EXHAUSTED_TTL_MS = 5 * 60 * 1000; // 5 minutes for 429-sourced entries (no resetAt)
const EXHAUSTED_REFRESH_MS = 5 * 60 * 1000; // 5 minutes: recheck exhausted accounts (aligned with TTL)
const REFRESH_INTERVAL_MS = 60 * 1000; // Background tick every 1 minute
+export const DEFAULT_QUOTA_THRESHOLD_PERCENT = 99;
// ─── State ──────────────────────────────────────────────────────────────────
@@ -260,7 +261,7 @@ export function isAccountQuotaExhausted(connectionId: string): boolean {
export function getQuotaWindowStatus(
connectionId: string,
windowName: string,
- thresholdPercent = 90
+ thresholdPercent = DEFAULT_QUOTA_THRESHOLD_PERCENT
): QuotaWindowStatus | null {
const entry = cache.get(connectionId);
if (!entry) return null;
diff --git a/src/sse/services/auth.ts b/src/sse/services/auth.ts
index 6e84b0d975..f2fdbf28f1 100644
--- a/src/sse/services/auth.ts
+++ b/src/sse/services/auth.ts
@@ -6,7 +6,12 @@ import {
getSettings,
getCachedSettings,
} from "@/lib/localDb";
-import { getQuotaCache, getQuotaWindowStatus, isAccountQuotaExhausted } from "@/domain/quotaCache";
+import {
+ DEFAULT_QUOTA_THRESHOLD_PERCENT,
+ getQuotaCache,
+ getQuotaWindowStatus,
+ isAccountQuotaExhausted,
+} from "@/domain/quotaCache";
import {
isAccountUnavailable,
getUnavailableUntil,
@@ -82,7 +87,6 @@ interface CooldownInspectionState {
retryableModelCooldownMs: number | null;
}
-const CODEX_QUOTA_THRESHOLD_PERCENT = 90;
const MIN_QUOTA_THRESHOLD_PERCENT = 1;
const MAX_QUOTA_THRESHOLD_PERCENT = 100;
const NON_RETRYABLE_MODEL_LOCKOUT_REASONS = new Set(["not_found", "not_found_local"]);
@@ -168,7 +172,10 @@ interface QuotaCacheView {
>;
}
-function normalizeQuotaThreshold(value: unknown, fallback = CODEX_QUOTA_THRESHOLD_PERCENT): number {
+function normalizeQuotaThreshold(
+ value: unknown,
+ fallback = DEFAULT_QUOTA_THRESHOLD_PERCENT
+): number {
const parsed = toNumber(value, fallback);
return Math.min(MAX_QUOTA_THRESHOLD_PERCENT, Math.max(MIN_QUOTA_THRESHOLD_PERCENT, parsed));
}
diff --git a/tests/unit/quota-policy-generalization.test.ts b/tests/unit/quota-policy-generalization.test.ts
index a99c27a172..7a0eb3480c 100644
--- a/tests/unit/quota-policy-generalization.test.ts
+++ b/tests/unit/quota-policy-generalization.test.ts
@@ -18,7 +18,7 @@ test("resolveQuotaLimitPolicy keeps codex legacy defaults when generic policy is
assert.equal(policy.enabled, true);
assert.deepEqual(policy.windows, ["session"]);
- assert.equal(policy.thresholdPercent, 90);
+ assert.equal(policy.thresholdPercent, 99);
});
test("resolveQuotaLimitPolicy enforces codex weekly window when weekly toggle is enabled", () => {
diff --git a/tests/unit/sse-auth.test.ts b/tests/unit/sse-auth.test.ts
index 8c99607eae..2add1820ef 100644
--- a/tests/unit/sse-auth.test.ts
+++ b/tests/unit/sse-auth.test.ts
@@ -264,7 +264,7 @@ test("resolveQuotaLimitPolicy normalizes Codex windows, thresholds, and defaults
});
assert.deepEqual(defaults, {
enabled: true,
- thresholdPercent: 90,
+ thresholdPercent: 99,
windows: ["session", "weekly"],
});
assert.deepEqual(generic, {