ClawKit Logo
ClawKitReliability Toolkit

Fix: Discord Messages Lost After WebSocket Reconnect

Sequence Gap After 1006/1005 Disconnect

The gateway reconnects to Discord, but messages and @mentions sent during the disconnection window are never delivered. This happens when the session is not properly resumed and Discord stops replaying missed events.

Discord's Gateway uses sequence numbers (s field) to track every event. After a disconnect, you have a short window to resume the session with the last known s value. If OpenClaw starts a fresh session instead of resuming, Discord does not send the events from the gap โ€” those @mentions are gone.

Next Step

Fix now, then reduce repeat incidents

If this issue keeps coming back, validate your setup in Doctor first, then harden your config.

What You See in Logs

webchat disconnected code=1006 reason=n/a
webchat disconnected code=1005 reason=n/a
[discord] reconnected โ€” session resumed? false
[discord] starting fresh session (resume_gateway_url unavailable)

The key line is session resumed? false. When this appears, Discord treated the reconnect as a new session and the sequence gap is unrecoverable. Events from the disconnection window are lost.

Fix A: Enable Session Resume

OpenClaw supports Discord Gateway session resume. Make sure it's enabled in your config and that the resume URL is being stored between restarts:

openclaw.json โ€” Discord Resume Config
{
  "channels": {
    "discord": {
      "gateway": {
        "resumeOnReconnect": true,
        "storeSessionState": true
      }
    }
  }
}

After updating config, restart and check logs for confirmation:

Restart and watch logs
openclaw gateway restart && openclaw logs --follow | grep -i 'discord\\|resume\\|session'

You should see [discord] session resume available: true and after any reconnect: session resumed? true.

Fix B: Shorten the Reconnect Window

Discord only holds session state for approximately 60 seconds after a disconnect. If your gateway takes longer than that to reconnect, resume will fail even if it's enabled. Common causes of slow reconnects:

Long restart delay in systemd / PM2

Set RestartSec=2 in your service file, or set restart_delay: 1000 in PM2 config

Slow network recovery (VPN, container restart)

Use Docker --restart=unless-stopped and avoid cold-start delays

Health check waiting too long before reconnect

Reduce the gateway healthCheckInterval if available in your config

Fix C: Use Discord Gateway v10

Older gateway versions have weaker resume support. Gateway v10 has more reliable resume behavior and better handling of the RECONNECT opcode. Check which version OpenClaw is using and upgrade if needed:

openclaw.json โ€” Set Gateway v10
{
  "channels": {
    "discord": {
      "gateway": {
        "version": 10
      }
    }
  }
}

Monitor for Disconnects

To see when disconnects happen and whether resumes succeed:

Watch for disconnect events
openclaw logs --follow | grep -E '(1006|1005|disconnect|resume|reconnect)'

Frequent 1006 disconnects often indicate a network stability issue rather than a gateway config problem. If you see more than 2โ€“3 per day, check your host network or consider moving to a more stable hosting environment.

Still Missing Messages?

If messages are still being lost even after enabling resume, run the Doctor for a full channel diagnostic:

Run the Doctor

npx clawkit-doctor@latest

Checks Discord gateway connectivity, session resume config, and intent settings.

Did this guide solve your problem?