openclaw - 💡(How to fix) Fix Bug: WhatsApp Gateway - Message Duplication and Loop After Credential Recovery [1 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#56849Fetched 2026-04-08 01:47:00
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

When WhatsApp credentials file (creds.json) becomes corrupted and is restored from backup, the gateway replays both inbound and outbound messages. This causes:

  1. Duplicate agent responses (from replayed inbound messages)
  2. Message loops (agent receives its own outbound replies as new messages)
  3. Token waste and user confusion

Error Message

2026-03-29T04:36:35.707Z warn web-session {"module":"web-session"} {"credsPath":"/Users/shi/.openclaw/credentials/whatsapp/default/creds.json"} restored corrupted WhatsApp creds.json from backup
...
2026-03-29T05:11:35.350Z warn web-session {"module":"web-session"} {"credsPath":"/Users/shi/.openclaw/credentials/whatsapp/default/creds.json"} restored corrupted WhatsApp creds.json from backup

Root Cause

Possible Root Cause

Code Example

2026-03-29T04:36:35.707Z warn web-session {"module":"web-session"} {"credsPath":"/Users/shi/.openclaw/credentials/whatsapp/default/creds.json"} restored corrupted WhatsApp creds.json from backup
...
2026-03-29T05:11:35.350Z warn web-session {"module":"web-session"} {"credsPath":"/Users/shi/.openclaw/credentials/whatsapp/default/creds.json"} restored corrupted WhatsApp creds.json from backup
RAW_BUFFERClick to expand / collapse

Bug: WhatsApp Gateway - Message Duplication and Loop After Credential Recovery

Summary

When WhatsApp credentials file (creds.json) becomes corrupted and is restored from backup, the gateway replays both inbound and outbound messages. This causes:

  1. Duplicate agent responses (from replayed inbound messages)
  2. Message loops (agent receives its own outbound replies as new messages)
  3. Token waste and user confusion

Environment

  • OpenClaw version: 2026.3.24 (cff6dc9)
  • OS: macOS 26.2 (arm64)
  • Node: v25.8.1
  • Gateway: local (ws://127.0.0.1:18789)
  • Channel: WhatsApp
  • Agent: main (glm-4.7)

Steps to Reproduce

  1. WhatsApp gateway encounters credentials corruption
  2. Gateway detects corruption and restores from backup
  3. Gateway reconnects to WhatsApp
  4. Agent receives duplicate messages

Expected Behavior

After credential recovery, the gateway should:

  • Resume normal operation
  • Not replay historical messages
  • Only process new inbound messages

Actual Behavior

After credential recovery, the gateway:

  • Replays previous inbound messages → agent generates duplicate responses
  • Replays outbound messages back to agent → agent sees "its own messages" as new inputs
  • Creates a message loop that wastes tokens

Logs

2026-03-29T04:36:35.707Z warn web-session {"module":"web-session"} {"credsPath":"/Users/shi/.openclaw/credentials/whatsapp/default/creds.json"} restored corrupted WhatsApp creds.json from backup
...
2026-03-29T05:11:35.350Z warn web-session {"module":"web-session"} {"credsPath":"/Users/shi/.openclaw/credentials/whatsapp/default/creds.json"} restored corrupted WhatsApp creds.json from backup

Evidence

Inbound message duplication:

  • Agent received same message multiple times
  • Each duplicate triggered a new response

Outbound message loop:

  • Agent's replies were received back as new messages
  • Example: Agent sent reply, then received the exact same reply as a new inbound message
  • Metadata shows sender_id matching the agent's own WhatsApp number

Impact

  1. User confusion: Seeing duplicate/looped messages
  2. Token waste: Double processing (inbound + outbound replay)
  3. Potential infinite loops: If replayed outbound messages trigger new responses
  4. Service disruption: Normal conversation flow broken

Severity

High: This bug can cause significant token waste and disrupt normal operation. In worst cases, it could create message loops that consume API quotas.

Possible Root Cause

The WhatsApp gateway's credential recovery process may:

  • Not properly track message acknowledgment state
  • Replay message history without filtering already-processed messages
  • Not distinguish between new messages and replayed history

Suggested Fix

  1. Track message IDs that have been processed
  2. Filter out already-processed messages during replay
  3. Only replay unprocessed messages after credential recovery
  4. Add message deduplication at the gateway level

Additional Notes

  • This happened twice within 35 minutes (04:36 and 05:11)
  • Credentials corruption may be caused by network instability, concurrent writes, or process crashes
  • May need to investigate why credentials are becoming corrupted in the first place

Reported by: Atlas (via SuperLaomiao) Date: 2026-03-29 Logs available: Yes

extent analysis

Fix Plan

To address the WhatsApp gateway issue, we will implement the following steps:

  • Track message IDs that have been processed
  • Filter out already-processed messages during replay
  • Only replay unprocessed messages after credential recovery
  • Add message deduplication at the gateway level

Here's an example of how this can be achieved in code:

// Initialize a set to store processed message IDs
const processedMessageIds = new Set();

// Function to process incoming messages
function processMessage(message) {
  const messageId = message.id;
  
  // Check if the message has already been processed
  if (processedMessageIds.has(messageId)) {
    // If processed, skip the message
    return;
  }
  
  // Mark the message as processed
  processedMessageIds.add(messageId);
  
  // Process the message
  // ...
}

// Function to replay messages after credential recovery
function replayMessages(messages) {
  messages.forEach((message) => {
    const messageId = message.id;
    
    // Check if the message has already been processed
    if (processedMessageIds.has(messageId)) {
      // If processed, skip the message
      return;
    }
    
    // Process the message
    processMessage(message);
  });
}

Verification

To verify that the fix worked, you can:

  • Test the WhatsApp gateway by simulating a credential recovery scenario
  • Check the logs to ensure that duplicate messages are not being processed
  • Verify that the agent is not receiving duplicate responses or message loops

Extra Tips

  • Consider implementing a more robust message tracking system, such as a database or a message queue, to store processed message IDs
  • Investigate the root cause of the credentials corruption to prevent it from happening in the future
  • Monitor the WhatsApp gateway for any issues related to message duplication or loops after implementing the fix.

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 and Loop After Credential Recovery [1 participants]