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
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
Merge PR 2951 into release/v3.8.8
diegosouzapwfa4bd6c68c06
diff --cc open-sse/handlers/chatCore.tsindex 40b92b48f8,d86468c1c0..7fa8fdf045--- a/open-sse/handlers/chatCore.ts+++ b/open-sse/handlers/chatCore.ts@@@ -4418,31 -4272,9 +4428,31 @@@ export async function handleChatCore();}} else {- log?.warn?.("TOKEN", `${provider.toUpperCase()} | refresh failed`);+ log?.warn?.("TOKEN", `${provider?.toUpperCase()} | refresh failed`);if (isUnrecoverableRefreshError(newCredentials) && onCredentialsRefreshed) {- await onCredentialsRefreshed({ testStatus: "expired", isActive: false });+ // Front 3 (reuse-race tolerance): before deactivating, re-read the DB.+ // If a sibling/concurrent refresh already rotated this connection's+ // refresh_token (common for Codex/OpenAI under one shared Auth0 client),+ // the failure we saw was a stale-token reuse — the account is healthy+ // with the newer token, so keep it active instead of killing it.+ let alreadyRotated = false;+ if (typeof connectionId === "string" && connectionId && attemptedRefreshToken) {+ try {+ const latest = await getProviderConnectionById(connectionId);+ if (wasRefreshTokenRotated(attemptedRefreshToken, latest?.refreshToken)) {+ alreadyRotated = true;+ log?.warn?.(+ "TOKEN",+ `${provider.toUpperCase()} | refresh_token already rotated by a concurrent refresh — keeping connection active`+ );+ }+ } catch {+ // DB read failed — fall through to the safe default (deactivate).+ }+ }+ if (!alreadyRotated) {+ await onCredentialsRefreshed({ testStatus: "expired", isActive: false });+ }}}}