From 045cdf1f753269fef7acd9542907898344b0b589 Mon Sep 17 00:00:00 2001 From: asepharyana Date: Thu, 24 Sep 2026 17:52:17 +0700 Subject: [PATCH] =?UTF-8?q?fix(gateway):=20align=20stuck-recovery=20thresh?= =?UTF-8?q?old=20with=20batch=20timeout=20(300s=E2=86=92120s)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit recovery-worker used a hardcoded STUCK_PROCESSING_AGE_MS=300_000 while messagesCleanup's default and AI_ANALYSIS_PROCESSING_TIMEOUT_MS are both 120s. Rows stuck between 2 and 5 minutes were never reverted by the recovery worker — they looked permanently stuck (and accumulated under load) even though the batch budget had long passed. Now derives the threshold from config so the two knobs can never drift again. --- .../src/modules/ai-moderation/recovery-worker.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/discord-gateway/src/modules/ai-moderation/recovery-worker.ts b/services/discord-gateway/src/modules/ai-moderation/recovery-worker.ts index 52156bbb..162b6d14 100644 --- a/services/discord-gateway/src/modules/ai-moderation/recovery-worker.ts +++ b/services/discord-gateway/src/modules/ai-moderation/recovery-worker.ts @@ -26,8 +26,16 @@ import { const logger = createChildLogger("ai-recovery"); -/** Revert messages stuck in `processing` for longer than this. */ -const STUCK_PROCESSING_AGE_MS = 300_000; +/** + * Revert messages stuck in `processing` for longer than this. + * Kept in lockstep with the batch processing timeout + * (AI_ANALYSIS_PROCESSING_TIMEOUT_MS, default 120s): a row sitting past the + * batch budget is a leak, not a legitimate slow batch. messagesCleanup's + * default was lowered 300s→120s in 2026-08-24; this constant was missed and + * stayed at 300s — messages looked stuck for up to 5 minutes before recovery + * touched them. + */ +const STUCK_PROCESSING_AGE_MS = config.AI_ANALYSIS_PROCESSING_TIMEOUT_MS; /** * Starts the periodic recovery worker.