From 5974d3116414931d8db72c0df590c79c00b16fa0 Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Thu, 11 Jun 2026 00:02:40 +0700 Subject: [PATCH] fix: avoid double markFailed in AI proxy retry loop Response handler already calls markFailed() on non-2xx and network errors (which rotates the proxy). The preamble at attempt >= 2 was calling markFailed() again, double-rotating and skipping a proxy. Changed preamble to use rotate() instead of markFailed(). Co-Authored-By: Claude Fable 5 --- src/lib/ai-proxy.ts | 2 +- src/lib/anthropic-proxy.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/ai-proxy.ts b/src/lib/ai-proxy.ts index 8653580..768f85d 100644 --- a/src/lib/ai-proxy.ts +++ b/src/lib/ai-proxy.ts @@ -318,7 +318,7 @@ export async function handleChatCompletion( } else if (attempt === 1 && proxyPool && proxyPool.size > 0) { init.proxy = proxyPool.getProxyUrl()!; } else if (attempt >= 2 && proxyPool && proxyPool.size > 0) { - const next = proxyPool.markFailed(); + const next = proxyPool.rotate(); if (!next) break; init.proxy = proxyPool.getProxyUrl()!; } else { diff --git a/src/lib/anthropic-proxy.ts b/src/lib/anthropic-proxy.ts index ebdf19d..18c927d 100644 --- a/src/lib/anthropic-proxy.ts +++ b/src/lib/anthropic-proxy.ts @@ -408,7 +408,7 @@ export async function handleAnthropicMessages( } else if (attempt === 1 && proxyPool && proxyPool.size > 0) { init.proxy = proxyPool.getProxyUrl()!; } else if (attempt >= 2 && proxyPool && proxyPool.size > 0) { - const next = proxyPool.markFailed(); + const next = proxyPool.rotate(); if (!next) break; init.proxy = proxyPool.getProxyUrl()!; } else {