fix(gateway): add message deduplication to Discord and Slack adapters#4866
Closed
Mibayy wants to merge 1 commit into
Closed
fix(gateway): add message deduplication to Discord and Slack adapters#4866Mibayy wants to merge 1 commit into
Mibayy wants to merge 1 commit into
Conversation
…NousResearch#4777) Discord RESUME replays events after reconnects (~7/day observed), and Slack Socket Mode can redeliver events if the ack was lost. Neither adapter tracked which messages were already processed, causing duplicate bot responses. Add _seen_messages dedup cache (message ID → timestamp) with 5-min TTL and 2000-entry cap to both adapters, matching the pattern already used by Mattermost, Matrix, WeCom, Feishu, DingTalk, and Email. The check goes at the very top of the message handler, before any other logic, so replayed events are silently dropped. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4777 — Discord and Slack adapters process replayed events after reconnects, causing duplicate bot responses.
Discord's gateway RESUME replays events from the disconnect window (~7/day observed). Slack Socket Mode reconnects can redeliver events if the ack was lost. Neither adapter tracked which messages were already processed.
Six other adapters already implement this correctly (Mattermost, Matrix, WeCom, Feishu, DingTalk, Email). This PR brings Discord and Slack in line with the established pattern.
Changes
Discord (
gateway/platforms/discord.py):_seen_messagesdict (message ID → timestamp) with 5-min TTL, 2000-entry capon_message, before all other logicSlack (
gateway/platforms/slack.py):_seen_messagesdict (eventts→ timestamp) with same TTL/cap_handle_slack_message, before all other logicimport timeTest plan
🤖 Generated with Claude Code