Repository navigation
Description
Bug type
Crash (process/app exits or hangs)
Summary
When the Discord WebSocket drops with code 1006 (abnormal closure), the internal @buape/carbon GatewayPlugin throws an uncaught exception (Max reconnect attempts (0) reached after code 1006) that crashes the entire OpenClaw gateway process, requiring manual restart.
Steps to reproduce
- Run OpenClaw gateway on Windows with Discord channel configured (3 bot accounts).
- Wait for a transient network interruption or Discord server hiccup that closes the WebSocket with code 1006 (abnormal closure).
- Observe: gateway attempts one resume with 1000ms backoff, fails, and throws an uncaught exception.
- Gateway process exits. No auto-recovery. Manual restart required.
This occurred at 00:19:41 MDT on 2026-03-24 after an unattended overnight run.
Expected behavior
Gateway should catch the Discord WebSocket drop, attempt reconnection with exponential backoff (as it does for other transient errors), and resume normal operation without crashing the process. A transient network blip should not take down the entire gateway.
Actual behavior
Gateway process crashes with an uncaught exception. The error originates in GatewayPlugin.handleReconnectionAttempt inside @buape/carbon. Full stack trace from gateway log:
Uncaught exception: Error: Max reconnect attempts (0) reached after code 1006
at GatewayPlugin.handleReconnectionAttempt (.../GatewayPlugin.js:305:40)
at GatewayPlugin.handleClose (.../GatewayPlugin.js:350:14)
at WebSocket.<anonymous> (.../GatewayPlugin.js:294:18)
at WebSocket.emit (node:events:508:28)
at WebSocket.emitClose (.../ws/lib/websocket.js:263:12)
at emitErrorAndClose (.../ws/lib/websocket.js:1047:13)
at process.processTicksAndRejections (node:internal/process/task_queues:89:21)
Gateway does not restart itself. No auto-recovery mechanism. Requires manual intervention.
OpenClaw version
2026.3.12
Operating system
Windows 10 (10.0.19045 x64) — LAPTOP-UJ92CE78, Node.js v24.13.1
Install method
npm global (npm install -g openclaw)
Model
anthropic/claude-sonnet-4-6
Provider / routing chain
openclaw -> anthropic (direct, no proxy)
Additional provider/model setup details
No response
Logs, screenshots, and evidence
Relevant log sequence (from openclaw-2026-03-23.log, times in MDT):
00:19:25 discord gateway: WebSocket connection closed with code 1006
00:19:27 discord gateway: Attempting resume with backoff: 1000ms after code 1006
00:19:30 health-monitor: restarting (reason: disconnected) [discord:default]
00:19:32 health-monitor: restarting (reason: disconnected) [discord:petra]
00:19:41 [openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1006
at GatewayPlugin.handleReconnectionAttempt (GatewayPlugin.js:305:40)
at GatewayPlugin.handleClose (GatewayPlugin.js:350:14)
... (full stack in actual log)
Log file ends here. Gateway is dead. Next log entry is the manual restart at 05:12 MDT (~5 hours later).Impact and severity
- Affected: Any OpenClaw deployment running Discord channel(s) on an unattended host
- Severity: Critical — entire gateway process dies, all agents go offline
- Frequency: Triggered by any transient Discord WS drop (code 1006); in this case occurred once overnight in ~3 weeks of uptime
- Consequence: All agents unreachable, all cron jobs missed, no auto-recovery — requires manual restart. On a headless/unattended setup (e.g. home server, VPS), this can mean hours of downtime before someone notices.
Additional information
- 3 Discord bot accounts configured (multi-account setup: default, petra, bean)
- The
channels.discord.retryconfig schema only covers outbound API call retries, not WebSocket reconnect behavior — there is no user-configurable setting to increasemaxReconnectAttemptsbeyond 0 - The health-monitor correctly detected the disconnection and attempted to restart, but the uncaught exception from
@buape/carbonkilled the process before it could recover - Code 1006 is a WebSocket abnormal closure (no clean close frame) — common for transient network drops, NAT timeouts, Discord server restarts. It should be treated as a recoverable error, not a fatal one.
Activity
Hollychou924 commentedon Mar 24, 2026
shiftymix commentedon Mar 24, 2026
@Hollychou924 thank you — this is an excellent breakdown. Your analysis matches what we observed: the health-monitor detected the disconnection but the uncaught exception from
@buape/carbonkilled the process before it could act.Note: your comment was auto-hidden as spam by GitHub's bot — flagging so the maintainers know to unhide it, as it contains the most detailed root cause analysis on this issue.
On the fix options: Option B (beforeClose hook intercepting 1006 before exhaustion) is the right long-term fix. Option C (expose
maxReconnectAttemptsas config) is useful too but doesn't prevent the crash if all retries fail.Immediate mitigation implemented (Windows): We're running on Windows 10 so systemd isn't an option, but pm2 works cross-platform. Setting it up now as the process manager with
--restart-delay 10000. This won't fix the root cause but cuts the recovery window from "hours until someone notices" to ~10 seconds.shiftymix commentedon Mar 24, 2026
Downstream consequence of this crash documented in #53781: when the gateway dies mid-tool-execution, the session JSONL is left with an orphaned
tool_useblock and no correspondingtool_result. On restart, every LLM request for that session is permanently rejected by the Anthropic API. Agent is stuck until manually cleared and re-briefed — no self-recovery path exists today.Suggested companion fix in #53781: scan for unpaired
tool_useblocks on session load and inject synthetic errortool_resultblocks before replaying history to the LLM.joelnishanth commentedon Mar 24, 2026
Working on a fix for this. Will have a PR up shortly.
— Joel Nishanth · offlyn.AI
fix(discord): catch thrown errors from gateway WebSocket close handler
joelnishanth commentedon Mar 24, 2026
Fix tracked in #53854. The root cause is Carbon's GatewayPlugin throwing an exception during WebSocket close handling (rather than emitting it), which bypasses OpenClaw's lifecycle error handlers. The fix wraps the WebSocket's emit method to catch thrown errors and convert them to emitted error events.
— Joel Nishanth · offlyn.AI
steipete commentedon Mar 25, 2026
Closing as fixed by #54182, merged on March 25, 2026. This was the same Discord WebSocket 1006 uncaught-exception crash path.