openclaw - 💡(How to fix) Fix [Bug]: WhatsApp gateway message duplication on reconnection [1 participants]

Official PRs (…)
ON THIS PAGE

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#61575Fetched 2026-04-08 02:57:07
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

When the WhatsApp gateway reconnects, it replays previously received messages into the agent session context. This causes:

  • Individual messages duplicated hundreds of times in session context
  • Heartbeat polls massively duplicated throughout the day
  • Session context fills entirely, agent is unusable for most of the day

Root Cause

When the WhatsApp gateway reconnects, it replays previously received messages into the agent session context. This causes:

  • Individual messages duplicated hundreds of times in session context
  • Heartbeat polls massively duplicated throughout the day
  • Session context fills entirely, agent is unusable for most of the day
RAW_BUFFERClick to expand / collapse

Description

When the WhatsApp gateway reconnects, it replays previously received messages into the agent session context. This causes:

  • Individual messages duplicated hundreds of times in session context
  • Heartbeat polls massively duplicated throughout the day
  • Session context fills entirely, agent is unusable for most of the day

Steps to Reproduce

  1. Have an active agent session with WhatsApp channel
  2. Trigger a gateway reconnection (network instability, timeout, etc.)
  3. Observe: previously received messages are replayed and injected N times into session context

Expected Behavior

Messages already processed (identified by message_id) should be deduplicated before injection into session context.

Actual Behavior

Same message_id injected hundreds of times. Session context saturated with duplicates. Agent effectively unresponsive.

Suggested Fix

Deduplication by message_id at the gateway/session injection layer before the agent processes incoming messages.

Environment

  • Channel: WhatsApp
  • Trigger: Gateway reconnection events
  • Symptom: Multiple WhatsApp gateway connected events in logs followed by message replay flood

extent analysis

TL;DR

Implement deduplication by message_id at the gateway/session injection layer to prevent replayed messages from flooding the session context.

Guidance

  • Identify the source of the message replay during gateway reconnection and ensure that messages are checked for duplicates based on their message_id before being injected into the session context.
  • Review the WhatsApp gateway's reconnection logic to understand why previously received messages are being replayed and determine if there's a way to prevent this replay or handle it more efficiently.
  • Consider implementing a mechanism to track processed message_ids to efficiently deduplicate incoming messages, potentially using a cache or a database to store recently processed message_ids.
  • Analyze the logs for patterns or specific conditions that lead to the massive duplication of heartbeat polls and session context saturation to refine the deduplication strategy.

Example

# Pseudocode example of deduplication based on message_id
processed_message_ids = set()

def process_message(message):
    if message['message_id'] not in processed_message_ids:
        # Process the message and add its id to the set
        processed_message_ids.add(message['message_id'])
        # Proceed with message processing
    else:
        # Message is a duplicate, skip processing
        pass

Notes

The effectiveness of the deduplication strategy depends on the implementation details of the WhatsApp gateway and the agent session context. It's crucial to test the solution thoroughly to ensure it correctly handles various scenarios, including different types of messages and gateway reconnection events.

Recommendation

Apply workaround: Implement deduplication by message_id at the gateway/session injection layer. This approach directly addresses the root cause of the issue by preventing duplicate messages from flooding the session context, thus mitigating the problem until a more permanent fix can be integrated.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Bug]: WhatsApp gateway message duplication on reconnection [1 participants]