Skip to content

Discord: WebSocket 1005/1006 disconnects with failing resume logic and unbounded backoff #13688

@carmandale

Description

@carmandale

Summary

Discord WebSocket connections repeatedly drop (codes 1005/1006), resume attempts fail, and exponential backoff grows without bound, leaving the bot offline for 30+ minutes. DMs are silently lost during downtime.

Environment

  • OpenClaw version: 2026.1.24-3
  • OS: macOS (Darwin 25.3.0, arm64)
  • Channel: Discord Bot API via channels.discord.js
  • Network: Residential broadband (stable, other channels working)

Expected Behavior

  • Discord gateway reconnects within 5-10 seconds of disconnect
  • Resume session or fresh IDENTIFY on resume failure
  • Messages queued/delivered after reconnection

Actual Behavior

  • WebSocket closes with 1005/1006 (abnormal closure)
  • Resume attempts fail repeatedly
  • Backoff escalates: 1s → 2s → 4s → 8s → 16s → ...
  • "connection stalled: no HELLO received within 30000ms"
  • Bot offline for 30+ minutes

Logs

2026-01-27T13:49:49.752Z [discord] gateway: WebSocket connection closed with code 1005
2026-01-27T13:50:19.238Z [discord] gateway: Attempting resume with backoff: 1000ms
2026-01-27T13:50:19.526Z [discord] gateway: WebSocket connection closed with code 1005
2026-01-27T14:02:43.531Z [discord] connection stalled: no HELLO received within 30000ms
2026-01-27T14:02:44.069Z [discord] gateway: WebSocket connection closed with code 1006

Configuration

{
  "channels": {
    "discord": {
      "enabled": true,
      "dm": { "policy": "open", "allowFrom": ["*"] }
    }
  }
}

No retry or gateway reconnect configuration options available for WebSocket-level issues.

Comparison: WhatsApp Has Gateway Reconnect Config

WhatsApp channel supports explicit reconnection tuning:

{
  "web": {
    "reconnect": {
      "initialMs": 2000,
      "maxMs": 120000,
      "factor": 1.4,
      "jitter": 0.2
    }
  }
}

Request: Add similar channels.discord.gateway.reconnect configuration.

Potential Root Causes

  1. Resume session expiration - Discord invalidates sessions after ~5 minutes of disconnect
  2. No bounded backoff - Exponential backoff exceeds session validity window
  3. No fallback to fresh IDENTIFY - Resume failures don't trigger new gateway session
  4. No keepalive tuning - Cannot configure HEARTBEAT interval or ACK timeout

Proposed Solutions

  1. Add gateway reconnect config (like WhatsApp)
  2. Cap exponential backoff at 15-30 seconds
  3. Fast-fail resume after 3 attempts → new IDENTIFY
  4. Add keepalive config (HEARTBEAT interval, timeout)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions