From c703fb32fb200b48fe173a79e2ba0b989c54bd97 Mon Sep 17 00:00:00 2001 From: Badri Narayanan S Date: Sun, 21 Dec 2025 19:57:50 +0530 Subject: [PATCH] fix where models didnt wait if retrydelay is less than 2 mins for multi account scenario --- src/cloudcode-client.js | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/src/cloudcode-client.js b/src/cloudcode-client.js index e19bac6..7127916 100644 --- a/src/cloudcode-client.js +++ b/src/cloudcode-client.js @@ -256,19 +256,12 @@ export async function sendMessage(anthropicRequest, accountManager) { ); } - if (accountManager.getAccountCount() === 1) { - // Single account mode: wait for reset - console.log(`[CloudCode] Single account rate-limited. Waiting ${formatDuration(waitMs)}...`); - await sleep(waitMs); - accountManager.clearExpiredLimits(); - account = accountManager.pickNext(); - } else { - // Multi-account: all exhausted - throw proper error - throw new Error( - `RESOURCE_EXHAUSTED: All ${accountManager.getAccountCount()} accounts rate-limited. ` + - `quota will reset after ${formatDuration(waitMs)}. Next available: ${resetTime}` - ); - } + // Wait for reset (applies to both single and multi-account modes) + const accountCount = accountManager.getAccountCount(); + console.log(`[CloudCode] All ${accountCount} account(s) rate-limited. Waiting ${formatDuration(waitMs)}...`); + await sleep(waitMs); + accountManager.clearExpiredLimits(); + account = accountManager.pickNext(); } if (!account) { @@ -509,19 +502,12 @@ export async function* sendMessageStream(anthropicRequest, accountManager) { ); } - if (accountManager.getAccountCount() === 1) { - // Single account mode: wait for reset - console.log(`[CloudCode] Single account rate-limited. Waiting ${formatDuration(waitMs)}...`); - await sleep(waitMs); - accountManager.clearExpiredLimits(); - account = accountManager.pickNext(); - } else { - // Multi-account: all exhausted - throw proper error - throw new Error( - `RESOURCE_EXHAUSTED: All ${accountManager.getAccountCount()} accounts rate-limited. ` + - `quota will reset after ${formatDuration(waitMs)}. Next available: ${resetTime}` - ); - } + // Wait for reset (applies to both single and multi-account modes) + const accountCount = accountManager.getAccountCount(); + console.log(`[CloudCode] All ${accountCount} account(s) rate-limited. Waiting ${formatDuration(waitMs)}...`); + await sleep(waitMs); + accountManager.clearExpiredLimits(); + account = accountManager.pickNext(); } if (!account) {