Skip to content

fix(gateway): add message deduplication to Discord and Slack adapters#4866

Closed
Mibayy wants to merge 1 commit into
NousResearch:mainfrom
Mibayy:fix/discord-slack-message-dedup-4777
Closed

fix(gateway): add message deduplication to Discord and Slack adapters#4866
Mibayy wants to merge 1 commit into
NousResearch:mainfrom
Mibayy:fix/discord-slack-message-dedup-4777

Conversation

@Mibayy

@Mibayy Mibayy commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

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):

  • Add _seen_messages dict (message ID → timestamp) with 5-min TTL, 2000-entry cap
  • Dedup check at top of on_message, before all other logic
  • Prune on threshold exceeded

Slack (gateway/platforms/slack.py):

  • Add _seen_messages dict (event ts → timestamp) with same TTL/cap
  • Dedup check at top of _handle_slack_message, before all other logic
  • Add import time

Test plan

  • Discord: Simulate RESUME by restarting gateway — no duplicate responses
  • Discord: Normal messages still processed correctly (single response)
  • Slack: Reconnect Socket Mode — no duplicate responses
  • Slack: Normal messages still processed correctly
  • Verify dedup cache doesn't grow unbounded (>2000 entries triggers prune)

🤖 Generated with Claude Code

…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>
@teknium1

teknium1 commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #4878. Your commit was cherry-picked onto current main with authorship preserved. Clean implementation that follows the established dedup pattern from the other adapters — thanks @Mibayy!

@teknium1 teknium1 closed this Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(gateway): Discord and Slack adapters missing message deduplication

2 participants