From 30be180f4b5a079d27676d2bcce26ced03bcf88f Mon Sep 17 00:00:00 2001 From: Eyejoker Date: Mon, 23 Mar 2026 23:07:35 +0900 Subject: [PATCH] fix: codex rate-limit retry immediately instead of next request --- src/message-agent-executor.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/message-agent-executor.ts b/src/message-agent-executor.ts index 5cd7b5e..07f09a1 100644 --- a/src/message-agent-executor.ts +++ b/src/message-agent-executor.ts @@ -428,22 +428,26 @@ export async function runAgentForGroup( } // Codex may report success but have streamed a rate-limit error. - // Rotate token so the NEXT request uses a fresh account. + // Rotate token and retry immediately with the new account. if ( !isClaudeCodeAgent && primaryAttempt.streamedTriggerReason && - getCodexAccountCount() > 1 + getCodexAccountCount() > 1 && + rotateCodexToken() ) { - if (rotateCodexToken()) { - logger.info( - { - chatJid, - group: group.name, - runId, - reason: primaryAttempt.streamedTriggerReason.reason, - }, - 'Codex rate-limited (streamed), rotated account for next request', - ); + logger.info( + { + chatJid, + group: group.name, + runId, + reason: primaryAttempt.streamedTriggerReason.reason, + }, + 'Codex rate-limited (streamed), retrying with rotated account', + ); + const retryAttempt = await runAttempt('codex'); + if (!retryAttempt.error) { + markCodexTokenHealthy(); + return 'success'; } }