openclaw - ✅(Solved) Fix [Bug]: Discord collect-mode auto-reply drain causes duplicate message delivery [1 pull requests, 2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#50892Fetched 2026-04-08 01:06:51
View on GitHub
Comments
2
Participants
3
Timeline
5
Reactions
0
Author
Timeline (top)
commented ×2cross-referenced ×2referenced ×1

When an agent session uses collect queue mode on Discord, the auto-reply drain mechanism delivers the same response message twice to the Discord channel. This happens consistently for normal conversational replies (not cron, not announce — just regular agent responses).

Root Cause

Actual behavior

The reply appears twice — same content, same bot user, within milliseconds of each other. This is caused by the collect-mode auto-reply drain posting the message twice at the Discord delivery layer.

Fix Action

Workaround

Using message(action=send) for explicit delivery followed by NO_REPLY to suppress the auto-reply drain avoids duplication. However, this is not practical for normal conversational flows where the agent should just reply naturally.

PR fix notes

PR #51304: fix: track sent items in collect-mode drain to prevent duplicate delivery

Description (problem / solution / changelog)

Summary

Fixes #50892

In Discord collect-mode, the auto-reply drain could deliver duplicate messages. The drain loop snapshots queue.items, sends a combined collected message, then splices the items out. Under certain timing conditions (e.g. new items arrive during the await runFollowup, loop continues, and items are revisited), the same items could be included in a second batch and sent again.

Root Cause

The collect-mode drain in src/auto-reply/reply/queue/drain.ts does:

  1. const items = queue.items.slice() — snapshot
  2. await runFollowup({prompt: combined}) — async, can yield
  3. queue.items.splice(0, items.length) — remove sent items

Between steps 2 and 3, or across loop iterations when queue.droppedCount > 0 keeps the loop alive, items that were already sent can be included in the next snapshot and sent again.

The same pattern applies to the individual-send path via drainCollectQueueStep / drainCollectItemIfNeeded.

Fix

Introduce a sentItems: Set<FollowupRun> scoped to the drain session using object identity:

  • Individual drain path: Wrap runFollowup to skip items already in sentItems, add on first send
  • Batch collect path: Filter snapshot to exclude already-sent items before building the combined prompt; if all items already sent, clear queue and exit; mark items as sent before the await

The Set uses reference equality so it has O(1) lookup with zero false positives within a drain session.

Changes

  • src/auto-reply/reply/queue/drain.ts: Add sentItems tracking set; filter individual and batch collect paths

Changed files

  • src/auto-reply/reply/queue/drain.ts (modified, +26/-4)
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Summary

When an agent session uses collect queue mode on Discord, the auto-reply drain mechanism delivers the same response message twice to the Discord channel. This happens consistently for normal conversational replies (not cron, not announce — just regular agent responses).

Environment

  • OpenClaw version: 2026.3.13 (61d171a)
  • Channel: Discord
  • Queue mode: collect
  • OS: macOS (Apple Silicon M1)

Steps to reproduce

  1. Configure a Discord agent with collect queue mode (default for most agents)
  2. Send a message to the agent in a Discord channel
  3. Agent processes and generates a reply
  4. Observe that the same reply appears twice in the Discord channel

Expected behavior

The agent reply should appear exactly once in the Discord channel.

Actual behavior

The reply appears twice — same content, same bot user, within milliseconds of each other. This is caused by the collect-mode auto-reply drain posting the message twice at the Discord delivery layer.

Workaround

Using message(action=send) for explicit delivery followed by NO_REPLY to suppress the auto-reply drain avoids duplication. However, this is not practical for normal conversational flows where the agent should just reply naturally.

Related issues

This may share a root cause with other duplicate delivery bugs:

  • #37844 (Discord bot sends duplicate replies)
  • #26612 (Occasional duplicate message posts)
  • #42695 (Cron delivery duplicates announce mode messages)
  • #30816 (Discord timeout and duplicate delivery)
  • #45500 (Duplicate delivery on LLM retry)

The collect-mode drain path appears to be a distinct trigger from the cron/announce paths reported in those issues.

Additional context

  • The duplication is specific to Discord; other channels (Telegram, etc.) are not affected in our setup
  • Affects all agents using collect mode, not just specific ones
  • Observed consistently since at least 2026-03-09
  • Rate of duplication: ~24% of replies in our observation window

extent analysis

Fix Plan

To fix the issue of duplicate replies in Discord channels when using collect queue mode, we need to modify the auto-reply drain mechanism to prevent it from posting the same message twice.

Step-by-Step Solution

  1. Identify the duplicate message check: In the Discord delivery layer, add a check to see if a message with the same content and bot user has been sent within a short time frame (e.g., 1 second).
  2. Implement a message cache: Create a cache to store recently sent messages, including their content and timestamp.
  3. Check the cache before sending: Before sending a message, check the cache to see if a similar message has been sent recently. If so, skip sending the duplicate message.

Example Code (Python)

import datetime

# Create a cache to store recently sent messages
message_cache = {}

def send_message(message):
    # Check if a similar message has been sent recently
    if is_duplicate_message(message):
        return

    # Send the message
    discord_client.send_message(message)

    # Add the message to the cache
    message_cache[message.content] = datetime.datetime.now()

def is_duplicate_message(message):
    # Check if a message with the same content has been sent within the last second
    if message.content in message_cache:
        sent_time = message_cache[message.content]
        time_diff = (datetime.datetime.now() - sent_time).total_seconds()
        if time_diff < 1:
            return True

    return False

Verification

To verify that the fix worked, test the Discord agent with collect queue mode and observe that the reply appears only once in the Discord channel.

Extra Tips

  • Make sure to adjust the time frame for checking duplicate messages according to your specific use case.
  • Consider implementing a more robust caching mechanism, such as using a database or a distributed cache, to handle high volumes of messages.
  • Review the related issues listed in the problem description to ensure that the fix does not introduce any regressions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The agent reply should appear exactly once in the Discord channel.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING