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
fix(auth): clear stale provider error metadata
Kfir Amar9c82b3d4ca4e
diff --git a/src/sse/services/auth.ts b/src/sse/services/auth.tsindex a106fb6a55..185eb1fd30 100644--- a/src/sse/services/auth.ts+++ b/src/sse/services/auth.ts@@ -572,9 +572,12 @@ export async function markAccountUnavailable(export async function clearAccountError(connectionId: string, currentConnection: any) {// Only update if currently has error statusconst hasError =- currentConnection.testStatus === "unavailable" ||+ (currentConnection.testStatus && currentConnection.testStatus !== "active") ||currentConnection.lastError ||- currentConnection.rateLimitedUntil;+ currentConnection.rateLimitedUntil ||+ currentConnection.errorCode ||+ currentConnection.lastErrorType ||+ currentConnection.lastErrorSource;if (!hasError) return; // Skip if already clean@@ -582,6 +585,9 @@ export async function clearAccountError(connectionId: string, currentConnection:testStatus: "active",lastError: null,lastErrorAt: null,+ lastErrorType: null,+ lastErrorSource: null,+ errorCode: null,rateLimitedUntil: null,backoffLevel: 0,});diff --git a/tests/unit/auth-clear-account-error.test.mjs b/tests/unit/auth-clear-account-error.test.mjsnew file mode 100644index 0000000000..6744d37bd5--- /dev/null+++ b/tests/unit/auth-clear-account-error.test.mjs@@ -0,0 +1,63 @@+import test from "node:test";+import assert from "node:assert/strict";+import fs from "node:fs";+import os from "node:os";+import path from "node:path";++const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-auth-clear-"));+process.env.DATA_DIR = TEST_DATA_DIR;++const core = await import("../../src/lib/db/core.ts");+const providersDb = await import("../../src/lib/db/providers.ts");+const auth = await import("../../src/sse/services/auth.ts");++async function resetStorage() {+ core.resetDbInstance();+ fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });+ fs.mkdirSync(TEST_DATA_DIR, { recursive: true });+}++test.after(() => {+ core.resetDbInstance();+ fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });+});++test("clearAccountError clears stale provider error metadata after recovery", async () => {+ await resetStorage();+ core.getDbInstance().exec('ALTER TABLE provider_connections ADD COLUMN "group" TEXT');++ const created = await providersDb.createProviderConnection({+ provider: "codex",+ authType: "oauth",+ email: "[email protected]",+ accessToken: "access",+ refreshToken: "refresh",+ testStatus: "error",+ lastError: "Health check: token refresh failed",+ lastErrorType: "token_refresh_failed",+ lastErrorSource: "oauth",+ errorCode: "refresh_failed",+ rateLimitedUntil: new Date(Date.now() + 60_000).toISOString(),+ backoffLevel: 2,+ });++ await auth.clearAccountError(created.id, {+ ...created,+ testStatus: "error",+ lastError: "Health check: token refresh failed",+ lastErrorType: "token_refresh_failed",+ lastErrorSource: "oauth",+ errorCode: "refresh_failed",+ rateLimitedUntil: new Date(Date.now() + 60_000).toISOString(),+ backoffLevel: 2,+ });++ const updated = await providersDb.getProviderConnectionById(created.id);+ assert.equal(updated.testStatus, "active");+ assert.equal(updated.lastError, undefined);+ assert.equal(updated.lastErrorType, undefined);+ assert.equal(updated.lastErrorSource, undefined);+ assert.equal(updated.errorCode, undefined);+ assert.equal(updated.rateLimitedUntil, undefined);+ assert.equal(updated.backoffLevel, 0);+});