Repository navigation
Description
Bug
A transient Discord WebSocket disconnection (close code 1005) triggers an uncaught exception that crashes the entire gateway process. This kills all channels (Feishu, WhatsApp, etc.), not just Discord.
This happened twice in one morning during normal Feishu usage. Both times, the gateway had to be manually restarted.
Error
[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005
at SafeGatewayPlugin.handleReconnectionAttempt (file:///…/node_modules/@buape/carbon/src/plugins/gateway/GatewayPlugin.ts:400:5)
at SafeGatewayPlugin.handleClose (…/GatewayPlugin.ts:484:8)
at WebSocket.<anonymous> (…/GatewayPlugin.ts:376:9)
at WebSocket.emit (node:events:519:28)
…
ELIFECYCLE Command failed with exit code 1.
Analysis
Root cause chain
- Discord WebSocket closes with code 1005 (No Status Received — normal network fluctuation)
@buape/carbonGatewayPlugin attempts reconnect, butmaxAttemptsresolves to 0 despite being configured as 50 increateDiscordGatewayPlugin()(extensions/discord/src/monitor/gateway-plugin.ts)handleReconnectionAttemptimmediately gives up → emits an Error viathis.emitter.emit("error", ...)- The error propagates as an uncaught exception (no global
process.on('uncaughtException')handler in the gateway) - Entire gateway process exits → all channels (Feishu, Discord, WhatsApp, etc.) go down
Two issues
-
maxAttemptsmismatch: The code passes{ reconnect: { maxAttempts: 50 } }to the GatewayPlugin constructor, but at runtime the value is 0. This may be a@buape/[email protected]bug or a state mutation during the session. -
No fault isolation: A single channel's WebSocket failure should not crash the entire gateway. Currently there is no
uncaughtException/unhandledRejectionhandler, and no error boundary around individual channel plugins.
Expected behavior
- Discord WebSocket disconnection should retry with the configured 50 max attempts
- If Discord permanently fails, it should be marked as degraded — other channels should continue working
- The gateway process should not exit due to a single channel's connection failure
Environment
- OpenClaw: 2026.3.24
- Node.js: v22.22.1
@buape/carbon: 0.0.0-beta-20260216184201- OS: Linux 6.8.0-101-generic (x64)
- Channels: Feishu (primary) + Discord
Suggested fixes
- Immediate: Add a try/catch or error listener around
SafeGatewayPlugin's error emission so it doesn't become an uncaught exception - Short-term: Add global
process.on('uncaughtException')/process.on('unhandledRejection')handlers in the gateway entry point that log the error and attempt graceful recovery - Long-term: Isolate channel plugins so one channel's failure doesn't affect others (e.g., per-channel error boundaries, automatic restart of failed channels)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
fix(discord): catch gateway reconnect errors to prevent whole-gateway…
openperf commentedon Mar 26, 2026
Hi @kagura-agent, thanks for reporting this and for the analysis.
Your observation about maxAttempts resolving to 0 at runtime (despite being configured as 50) is spot on — that happens because onAbort() explicitly sets gateway.options.reconnect = { maxAttempts: 0 } before calling disconnect(). Once that mutation happens, any subsequent WebSocket close event hits the 0 >= 0 check and emits the fatal error.
The real problem is that when onAbort() calls disconnect(), the gateway supervisor is still in the active phase, so it routes that error to the lifecycle handler instead of suppressing it. The supervisor already knows how to swallow errors during teardown — it just wasn't being told to enter teardown before the disconnect call.
This is actually the same root cause as #54931 (health-monitor crash loop), just a different trigger path. In #54931 it's the health-monitor detecting a stale socket; here it's a transient network disconnection. Both end up in the same onAbort() → disconnect() → uncaught error chain.
PR #55000 fixes the shared root cause by calling detachLifecycle() before disconnect() in onAbort(), so the supervisor is in the teardown phase when the error fires. It also adds a safety net in the catch block for any edge cases. This should resolve both issues.
kagura-chen commentedon Mar 26, 2026
Thanks @openperf — that makes total sense. The onAbort() → disconnect() → uncaught error chain explains exactly what I saw in the logs. Good to know #55000 fixes both paths. 👍
Takhoffman commentedon Mar 29, 2026
Closing as fixed upstream. This crash family was addressed by upstream Discord lifecycle changes merged in #55991, and PR #55000 was closed after the upstream maintainer confirmed the fix landed there.
If you still hit the same
Max reconnect attempts (0)/ stale-socket gateway crash on the latest OpenClaw release, comment here with fresh logs and version details and we can reopen or spin a new issue.