From 55042ca9eb2ec02764dcc2efc6598c97f4c42f95 Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Tue, 2 Jun 2026 22:03:44 +0700 Subject: [PATCH] chore: no staged changes --- .../src/modules/ai-moderation/aiAnalyzer.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/services/discord-gateway/src/modules/ai-moderation/aiAnalyzer.ts b/services/discord-gateway/src/modules/ai-moderation/aiAnalyzer.ts index e90fc9d..dd2cc17 100644 --- a/services/discord-gateway/src/modules/ai-moderation/aiAnalyzer.ts +++ b/services/discord-gateway/src/modules/ai-moderation/aiAnalyzer.ts @@ -162,6 +162,26 @@ const conversationConsecutiveErrors = new Map(); const MAX_CONSECUTIVE_ERRORS = 5; const CONVERSATION_CB_COOLDOWN_MS = 60000; +function recordConversationBatchFailure(conversationKey: string): void { + const nextCount = (conversationConsecutiveErrors.get(conversationKey) ?? 0) + 1; + conversationConsecutiveErrors.set(conversationKey, nextCount); + + if (nextCount >= MAX_CONSECUTIVE_ERRORS) { + conversationErrorCooldown.set( + conversationKey, + Date.now() + CONVERSATION_CB_COOLDOWN_MS, + ); + logger.warn( + { conversationKey, consecutiveErrors: nextCount }, + "Conversation circuit breaker triggered due to consecutive batch errors", + ); + } +} + +function resetConversationBatchFailures(conversationKey: string): void { + conversationConsecutiveErrors.delete(conversationKey); +} + // --------------------------------------------------------------------------- // Individual fallback queue — runs PARALLEL to the batch pipeline. //