Merge pull request #72 from s21v1d9p/fix/optimistic-rate-limit-retry
fix: add optimistic reset for transient 429 rate limit errors
This commit is contained in:
@@ -72,8 +72,19 @@ export async function sendMessage(anthropicRequest, accountManager, fallbackEnab
|
||||
const accountCount = accountManager.getAccountCount();
|
||||
logger.warn(`[CloudCode] All ${accountCount} account(s) rate-limited. Waiting ${formatDuration(allWaitMs)}...`);
|
||||
await sleep(allWaitMs);
|
||||
|
||||
// Add small buffer after waiting to ensure rate limits have truly expired
|
||||
await sleep(500);
|
||||
accountManager.clearExpiredLimits();
|
||||
account = accountManager.pickNext(model);
|
||||
|
||||
// If still no account after waiting, try optimistic reset
|
||||
// This handles cases where the API rate limit is transient
|
||||
if (!account) {
|
||||
logger.warn('[CloudCode] No account available after wait, attempting optimistic reset...');
|
||||
accountManager.resetAllRateLimits();
|
||||
account = accountManager.pickNext(model);
|
||||
}
|
||||
}
|
||||
|
||||
if (!account) {
|
||||
@@ -197,10 +208,10 @@ export async function sendMessage(anthropicRequest, accountManager, fallbackEnab
|
||||
}
|
||||
|
||||
if (isNetworkError(error)) {
|
||||
logger.warn(`[CloudCode] Network error for ${account.email}, trying next account... (${error.message})`);
|
||||
await sleep(1000); // Brief pause before retry
|
||||
accountManager.pickNext(model); // Advance to next account
|
||||
continue;
|
||||
logger.warn(`[CloudCode] Network error for ${account.email}, trying next account... (${error.message})`);
|
||||
await sleep(1000); // Brief pause before retry
|
||||
accountManager.pickNext(model); // Advance to next account
|
||||
continue;
|
||||
}
|
||||
|
||||
throw error;
|
||||
|
||||
@@ -71,8 +71,19 @@ export async function* sendMessageStream(anthropicRequest, accountManager, fallb
|
||||
const accountCount = accountManager.getAccountCount();
|
||||
logger.warn(`[CloudCode] All ${accountCount} account(s) rate-limited. Waiting ${formatDuration(allWaitMs)}...`);
|
||||
await sleep(allWaitMs);
|
||||
|
||||
// Add small buffer after waiting to ensure rate limits have truly expired
|
||||
await sleep(500);
|
||||
accountManager.clearExpiredLimits();
|
||||
account = accountManager.pickNext(model);
|
||||
|
||||
// If still no account after waiting, try optimistic reset
|
||||
// This handles cases where the API rate limit is transient
|
||||
if (!account) {
|
||||
logger.warn('[CloudCode] No account available after wait, attempting optimistic reset...');
|
||||
accountManager.resetAllRateLimits();
|
||||
account = accountManager.pickNext(model);
|
||||
}
|
||||
}
|
||||
|
||||
if (!account) {
|
||||
@@ -264,10 +275,10 @@ export async function* sendMessageStream(anthropicRequest, accountManager, fallb
|
||||
}
|
||||
|
||||
if (isNetworkError(error)) {
|
||||
logger.warn(`[CloudCode] Network error for ${account.email} (stream), trying next account... (${error.message})`);
|
||||
await sleep(1000); // Brief pause before retry
|
||||
accountManager.pickNext(model); // Advance to next account
|
||||
continue;
|
||||
logger.warn(`[CloudCode] Network error for ${account.email} (stream), trying next account... (${error.message})`);
|
||||
await sleep(1000); // Brief pause before retry
|
||||
accountManager.pickNext(model); // Advance to next account
|
||||
continue;
|
||||
}
|
||||
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user