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:
Badri Narayanan S
2026-01-08 22:27:01 +05:30
committed by GitHub
2 changed files with 30 additions and 8 deletions

View File

@@ -72,8 +72,19 @@ export async function sendMessage(anthropicRequest, accountManager, fallbackEnab
const accountCount = accountManager.getAccountCount(); const accountCount = accountManager.getAccountCount();
logger.warn(`[CloudCode] All ${accountCount} account(s) rate-limited. Waiting ${formatDuration(allWaitMs)}...`); logger.warn(`[CloudCode] All ${accountCount} account(s) rate-limited. Waiting ${formatDuration(allWaitMs)}...`);
await sleep(allWaitMs); await sleep(allWaitMs);
// Add small buffer after waiting to ensure rate limits have truly expired
await sleep(500);
accountManager.clearExpiredLimits(); accountManager.clearExpiredLimits();
account = accountManager.pickNext(model); 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) { if (!account) {

View File

@@ -71,8 +71,19 @@ export async function* sendMessageStream(anthropicRequest, accountManager, fallb
const accountCount = accountManager.getAccountCount(); const accountCount = accountManager.getAccountCount();
logger.warn(`[CloudCode] All ${accountCount} account(s) rate-limited. Waiting ${formatDuration(allWaitMs)}...`); logger.warn(`[CloudCode] All ${accountCount} account(s) rate-limited. Waiting ${formatDuration(allWaitMs)}...`);
await sleep(allWaitMs); await sleep(allWaitMs);
// Add small buffer after waiting to ensure rate limits have truly expired
await sleep(500);
accountManager.clearExpiredLimits(); accountManager.clearExpiredLimits();
account = accountManager.pickNext(model); 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) { if (!account) {