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(