Skip to content

Discord: Slow DiscordMessageListener (300s+) causes WebSocket 1006 drops and gateway crash #42178

Description

@jjc7951

Bug Report

OpenClaw version: 2026.3.2
OS: macOS 26.3.0 (arm64, Mac mini M4)
Gateway mode: local

Description

When an agent session takes a long time to process a Discord message (e.g., complex tool calls, heavy context loading), the DiscordMessageListener blocks for 300+ seconds. This causes Discord's gateway to drop the WebSocket connection (code 1006), which triggers cascading failures:

  1. Slow listener detected (329.5s for MESSAGE_CREATE)
  2. WebSocket closes with code 1006
  3. Resume attempts fail or succeed briefly before repeating
  4. Health monitor detects "stuck" state and restarts the provider
  5. Restart sometimes fails with fetch failed errors
  6. Gateway becomes unresponsive until manual restart

Log Evidence

12:41:43 [discord] Slow listener detected: DiscordMessageListener took 329.5 seconds for event MESSAGE_CREATE
13:06:07 [discord] gateway: WebSocket connection closed with code 1006
13:06:07 [discord] gateway: Attempting resume with backoff: 1000ms after code 1006
...
[health-monitor] [discord:default] health-monitor: restarting (reason: stuck)
[discord] channel resolve failed; using config entries. fetch failed
[discord] discord: failed to deploy native commands: fetch failed
[openclaw] Unhandled promise rejection: Error: Failed to get gateway information from Discord

Root Cause Hypothesis

The message listener appears to be synchronous/blocking — it waits for the full agent response before returning control to the gateway event loop. Discord requires a heartbeat ACK within ~41.25 seconds (their heartbeat interval). A 329-second block guarantees missed heartbeats → connection drop.

Suggested Fix

Process Discord messages asynchronously — acknowledge the gateway event immediately, then handle the agent response in a separate async context. The listener should never block the heartbeat loop.

Workaround

We currently treat Discord as output-only (alerts, digests) and route all real conversations through webchat, which avoids long processing times on the Discord gateway.

Related

Additional Context

This consistently reproduces when the agent has heavy context (large MEMORY.md, multiple tool calls, image processing). Shorter responses (~5-10s) do not trigger the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions