From a1ee605494dd3eecf99b5e30bc4cfe8fd22eaf30 Mon Sep 17 00:00:00 2001 From: Zico Date: Mon, 2 Mar 2026 15:16:33 -0600 Subject: [PATCH] fix(slack): prevent duplicate DM processing from app_mention events Fixes duplicate message processing in Slack DMs where both message.im and app_mention events fire for the same message, causing: - 2x token/credit usage per message - 2x API calls - Duplicate agent invocations with same runId Root cause: app_mention events should only fire for channel mentions, not DMs. Added channel_type check to skip im/mpim in app_mention handler. Evidence of bug (from production logs): - Same runId firing twice within 200-300ms - Example: runId 13cd482c... at 20:32:42.699Z and 20:32:42.954Z After fix: - One message = one runId = one processing run - 50% reduction in duplicate processing --- src/slack/monitor/events/messages.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/slack/monitor/events/messages.ts b/src/slack/monitor/events/messages.ts index 40308570d..9613d633a 100644 --- a/src/slack/monitor/events/messages.ts +++ b/src/slack/monitor/events/messages.ts @@ -63,6 +63,14 @@ export function registerSlackMessageEvents(params: { } const mention = event as SlackAppMentionEvent; + + // Skip app_mention for DMs - they're already handled by message.im event + // This prevents duplicate processing when both message and app_mention fire for DMs + const channelType = mention.channel_type; + if (channelType === "im" || channelType === "mpim") { + return; + } + await handleSlackMessage(mention as unknown as SlackMessageEvent, { source: "app_mention", wasMentioned: true,