From ad84d0a1bbe09c2ed7e2732fb962ea03b9c94637 Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Mon, 22 Jun 2026 17:45:32 +0700 Subject: [PATCH] fix: messages with text+media also go into text batch immediately MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Previously: text+media message went ONLY to media array → text waited for vision - Now: text part goes to text batch (immediate LLM analysis), media parallel - DB update is idempotent — second write to same message_id overwrites - User sees text moderation results instantly, media follows when ready --- .../src/modules/ai-moderation/aiAnalysisWorker.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/services/discord-gateway/src/modules/ai-moderation/aiAnalysisWorker.ts b/services/discord-gateway/src/modules/ai-moderation/aiAnalysisWorker.ts index 18baedf..ce98cd3 100644 --- a/services/discord-gateway/src/modules/ai-moderation/aiAnalysisWorker.ts +++ b/services/discord-gateway/src/modules/ai-moderation/aiAnalysisWorker.ts @@ -163,6 +163,9 @@ async function processBatch(job: { // ── Split: text-only vs media ────────────────────────────────────── // Text-only analysis runs fast (single LLM call, no vision). // Media analysis is slow (download + vision → LLM). + // Messages with BOTH text and media go into both arrays: + // - text batch → analyzes the text content immediately + // - media batch → analyzes images/video when ready // By splitting here, text results are saved to DB immediately // instead of waiting for media downloads to finish. // ──────────────────────────────────────────────────────────────────── @@ -173,6 +176,11 @@ async function processBatch(job: { const meta = msg.metadata ? extractMessageMediaEvidence(msg.metadata) : null; if (meta && (meta.attachments.length > 0 || meta.stickers.length > 0 || meta.embeds.length > 0)) { media.push(msg); + // If the message also has text content, analyze it in the text batch too + const rawContent = msg.edited_content ?? msg.content; + if (rawContent.trim().length > 0) { + textOnly.push(msg); + } } else { textOnly.push(msg); }