From 6a73421d4fdb82ae8076847ced2ca4214011b927 Mon Sep 17 00:00:00 2001 From: Eyejoker Date: Tue, 24 Mar 2026 03:47:22 +0900 Subject: [PATCH] fix: use ignoreRateLimits in retryClaudeWithRotation loops Without this, token rotation was blocked by stale cooldowns even when the target token had available usage. --- src/message-agent-executor.ts | 6 ++-- src/task-scheduler.ts | 54 +++++++++++++++++------------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/message-agent-executor.ts b/src/message-agent-executor.ts index 82b9568..055e383 100644 --- a/src/message-agent-executor.ts +++ b/src/message-agent-executor.ts @@ -351,7 +351,7 @@ export async function runAgentForGroup( while ( shouldRotateClaudeToken(trigger.reason) && getTokenCount() > 1 && - rotateToken(lastRotationMessage) + rotateToken(lastRotationMessage, { ignoreRateLimits: true }) ) { logger.info( { chatJid, group: group.name, runId, reason: trigger.reason }, @@ -422,7 +422,9 @@ export async function runAgentForGroup( retryAfterMs: retryAttempt.streamedTriggerReason.retryAfterMs, }; lastRotationMessage = - typeof retryOutput.result === 'string' ? retryOutput.result : undefined; + typeof retryOutput.result === 'string' + ? retryOutput.result + : undefined; continue; } diff --git a/src/task-scheduler.ts b/src/task-scheduler.ts index 903554b..4db678b 100644 --- a/src/task-scheduler.ts +++ b/src/task-scheduler.ts @@ -450,7 +450,7 @@ async function runTask( while ( shouldRotateClaudeToken(trigger.reason) && getTokenCount() > 1 && - rotateToken(lastRotationMessage) + rotateToken(lastRotationMessage, { ignoreRateLimits: true }) ) { logger.info( { @@ -534,35 +534,33 @@ async function runTask( error = 'Claude usage exhausted'; // Fall through to task completion handling below } else { + const attempt = await runTaskAttempt(provider); + result = attempt.attemptResult; + error = attempt.attemptError; - const attempt = await runTaskAttempt(provider); - result = attempt.attemptResult; - error = attempt.attemptError; - - if ( - provider === 'claude' && - attempt.streamedTriggerReason && - !attempt.sawOutput - ) { - await retryClaudeTaskWithRotation(attempt.streamedTriggerReason); - } else if (attempt.output.status === 'error' && provider === 'claude') { - const trigger = attempt.streamedTriggerReason - ? { - shouldFallback: true, - reason: attempt.streamedTriggerReason.reason, - retryAfterMs: attempt.streamedTriggerReason.retryAfterMs, - } - : detectFallbackTrigger(error); - if (trigger.shouldFallback) { - await retryClaudeTaskWithRotation({ - reason: trigger.reason, - retryAfterMs: trigger.retryAfterMs, - }); + if ( + provider === 'claude' && + attempt.streamedTriggerReason && + !attempt.sawOutput + ) { + await retryClaudeTaskWithRotation(attempt.streamedTriggerReason); + } else if (attempt.output.status === 'error' && provider === 'claude') { + const trigger = attempt.streamedTriggerReason + ? { + shouldFallback: true, + reason: attempt.streamedTriggerReason.reason, + retryAfterMs: attempt.streamedTriggerReason.retryAfterMs, + } + : detectFallbackTrigger(error); + if (trigger.shouldFallback) { + await retryClaudeTaskWithRotation({ + reason: trigger.reason, + retryAfterMs: trigger.retryAfterMs, + }); + } + } else if (attempt.output.status === 'error') { + error = attempt.attemptError || 'Unknown error'; } - } else if (attempt.output.status === 'error') { - error = attempt.attemptError || 'Unknown error'; - } - } // end else (non-exhausted path) logger.info(