From d5bf0d1199731dba72a8db1a10cc6ca1f0591176 Mon Sep 17 00:00:00 2001 From: oyi77 Date: Mon, 30 Mar 2026 01:47:28 +0700 Subject: [PATCH] fix: address reviewer comments for auto-disable (use getCachedSettings, immediate disable on permanent bans) --- src/sse/services/auth.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sse/services/auth.ts b/src/sse/services/auth.ts index b9b6573eaf..97af742ab7 100644 --- a/src/sse/services/auth.ts +++ b/src/sse/services/auth.ts @@ -3,6 +3,7 @@ import { validateApiKey, updateProviderConnection, getSettings, + getCachedSettings, } from "@/lib/localDb"; import { getQuotaWindowStatus, isAccountQuotaExhausted } from "@/domain/quotaCache"; import { @@ -823,17 +824,19 @@ export async function markAccountUnavailable( // T-AUTODISABLE: If auto-disable setting is enabled and error is permanent/terminal, // mark account as inactive so it is never retried again. + // Uses getCachedSettings() to avoid DB overhead on hot error path. + // NOTE: For permanent bans we disable immediately — no threshold needed, + // because a permanent ban (403 "Verify your account" / ToS violation) will + // NEVER recover, so retrying is pointless regardless of attempt count. if (result.permanent) { try { - const settings = await getSettings(); + const settings = await getCachedSettings(); const autoDisableEnabled = settings.autoDisableBannedAccounts ?? false; - const threshold = Number(settings.autoDisableBannedThreshold ?? 3); - const newBackoff = newBackoffLevel ?? backoffLevel; - if (autoDisableEnabled && newBackoff >= threshold) { + if (autoDisableEnabled) { await updateProviderConnection(connectionId, { isActive: false }); log.info( "AUTH", - `Auto-disabled ${connectionId.slice(0, 8)} — permanent error after ${newBackoff} failures (autoDisableBannedAccounts=true)` + `Auto-disabled ${connectionId.slice(0, 8)} — permanent ban detected (autoDisableBannedAccounts=true)` ); } } catch (e) {