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: auto-decay backoffLevel when rate limit window has passed

Brendan DeBeasi7df0c1607ead
diff --git a/src/sse/services/auth.ts b/src/sse/services/auth.ts
index 757bff7d8e..20ba37e35e 100644
--- a/src/sse/services/auth.ts
+++ b/src/sse/services/auth.ts
@@ -368,6 +368,29 @@ export async function getProviderCredentials(
return null;
}
+ // Auto-decay backoffLevel for accounts whose rateLimitedUntil has passed.
+ // Without this, high backoffLevel permanently deprioritizes accounts even
+ // after the rate limit window expires, creating a deadlock where the account
+ // needs a successful request to reset but never gets selected.
+ for (const c of connections) {
+ if (
+ c.backoffLevel > 0 &&
+ !isTerminalConnectionStatus(c) &&
+ !isAccountUnavailable(c.rateLimitedUntil)
+ ) {
+ c.backoffLevel = 0;
+ updateProviderConnection(c.id, {
+ backoffLevel: 0,
+ testStatus: "active",
+ lastError: null,
+ lastErrorAt: null,
+ lastErrorType: null,
+ lastErrorSource: null,
+ errorCode: null,
+ }).catch(() => {});
+ }
+ }
+
// Filter out unavailable accounts and excluded connection
const availableConnections = connections.filter((c) => {
if (excludeConnectionId && c.id === excludeConnectionId) return false;