Repository navigation
Description
Bug Summary
Discord periodically closes WebSocket connections with code 1005 (normal behavior — load balancing, session rotation). When this happens, SafeGatewayPlugin.handleReconnectionAttempt sees maxReconnectAttempts = 0 and throws an error instead of reconnecting. This bubbles up as an uncaught exception and kills the entire gateway process (all channels — Discord, Telegram, webchat).
Reproduction
Runs consistently — Discord drops the WS every few hours. Gateway crashes every time.
Crash Log
[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005
at SafeGatewayPlugin.handleReconnectionAttempt (file:///…/dist/provider-CAlWEl41.js:3318:47)
at SafeGatewayPlugin.handleClose (file:///…/dist/provider-CAlWEl41.js:3364:8)
at WebSocket.<anonymous> (file:///…/dist/provider-CAlWEl41.js:3307:9)
at WebSocket.emit (node:events:508:20)
at WebSocket.emitClose (…/ws/lib/websocket.js:273:10)
at TLSSocket.socketOnClose (…/ws/lib/websocket.js:1346:15)
Timeline (48h window on a single machine)
| Time | Event |
|---|---|
| Mar 25, 10:54 AM | health-monitor detects stale-socket → restart → 💥 crash |
| Mar 25, 11:10 PM | LaunchAgent restarts gateway |
| Mar 26, 12:10 AM | stale-socket → restart → 💥 crash |
| Mar 26, 10:23 AM | LaunchAgent restarts |
| Mar 26, 11:01 AM | WebSocket closed code 1005 logged |
| Mar 26, 11:58 AM | stale-socket → 💥 crash |
| Mar 26, 12:46 PM | 💥 crash (same pattern) |
| Mar 26, 3:46 PM | LaunchAgent restarts |
The health-monitor correctly detects stale-socket but the restart path triggers the same fatal error. Each crash takes out ALL channels for hours until LaunchAgent retries.
Also related: the [discord] gateway: WebSocket connection closed with code 1005 log line at 11:01 AM suggests Discord is the initiator.
Expected Behavior
- Discord WS close code 1005 should trigger a reconnect with exponential backoff (resume if possible)
maxReconnectAttemptsshould not be 0 by default- Even if reconnection ultimately fails, it should not crash the entire gateway — isolate the failure to the Discord provider
Environment
- OpenClaw
2026.3.24(cff6dc9) - macOS arm64, Node v25.5.0
- Two Discord bot accounts (default + kiwi), both affected
- LaunchAgent managed
Workaround
None currently. The gateway crashes and stays down until LaunchAgent restarts it (which can take hours).
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
jastee07 commentedon Mar 27, 2026
I hit the same issue and worked around it without disabling Discord entirely by disabling the Discord health-monitor restart path:
After applying that and restarting OpenClaw, Discord continued working for me.
In my case, the crash was happening during stale-socket recovery, where the process would die with:
Max reconnect attempts (0) reached after code 1005
So this looks like a temporary mitigation/workaround, not the real upstream fix but it let me keep using Discord in the meantime.
Drawback: this disables the automatic health-monitor restart behavior for Discord, so if Discord ends up in a stale/dead socket state, OpenClaw may not auto-recover that channel on its own. It avoids the crash, but it also removes that layer of automatic recovery.