Repository navigation
Description
Bug type
Regression (worked before, now fails)
Summary
After upgrading from v2026.3.11 to v2026.3.24, the gateway crashes every ~35 minutes due to Discord's health-monitor detecting stale sockets and triggering a reconnection path that throws an uncaught exception. Zero crashes occurred across 5+ days on v2026.3.11. On v2026.3.24, 16 crashes occurred in a single day.
Steps to reproduce
- Install v2026.3.24 with Discord channel enabled (single guild, allowlist-only)
- Gateway runs normally for ~30-35 minutes
- Discord health-monitor detects a stale WebSocket (no events within staleSocketMinutes, default 30)
- Health-monitor calls stopChannel() → triggers onAbort()
- onAbort() sets gateway.options.reconnect = { maxAttempts: 0 } then calls gateway.disconnect()
- WebSocket closes with code 1005 ("No Status Received")
- handleClose(1005) → handleReconnectionAttempt() → checks reconnectAttempts(0) >= maxAttempts(0) → true
- Emits new Error("Max reconnect attempts (0) reached after code 1005")
- Error is uncaught → entire Node.js process crashes
- systemd restarts → cycle repeats every ~35 minutes
Expected behavior
Health-monitor should gracefully restart the Discord channel without crashing the gateway process.
Actual behavior
The onAbort handler sets maxAttempts: 0 before disconnecting. The WebSocket close handler then fires and immediately triggers the max-attempts error path (0 >= 0 is true), emitting an uncaught exception that crashes the entire Node.js process.
OpenClaw version
2026.3.24 (upgraded from 2026.3.11)
Operating system
Ubuntu 24.04 LTS (Linux 6.18.7 x64)
Install method
npm global
Model
anthropic/claude-opus-4-6 / anthropic/claude-sonnet-4-6
Provider / routing chain
openclaw -> anthropic (direct)
Additional provider/model setup details
Bug is in Discord WebSocket lifecycle management, not model-specific.
Logs, screenshots, and evidence
[health-monitor] [discord:default] health-monitor: restarting (reason: stale-socket)
[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005
at SafeGatewayPlugin.handleReconnectionAttempt (provider-CAlWEl41.js:3318:47)
at SafeGatewayPlugin.handleClose (provider-CAlWEl41.js:3364:8)
at WebSocket.<anonymous> (provider-CAlWEl41.js:3307:9)
Root cause in provider-CAlWEl41.js:
Line 6952 — onAbort sets: gateway.options.reconnect = { maxAttempts: 0 };
Lines 3316-3318 — Reconnection handler checks:
const { maxAttempts = 5 } = this.options.reconnect ?? {};
if (this.reconnectAttempts >= maxAttempts) {
this.emitter.emit("error", new Error(`Max reconnect attempts (${maxAttempts}) reached...`));
Crash frequency data:
• Mar 17-24 (v2026.3.11): 0 crashes across 5+ days
• Mar 25 (v2026.3.24): 16 crashes in one day, every ~35 minImpact and severity
High — Gateway crashes every ~35 minutes. All running subagent sessions are disrupted or killed. Subagent completion announce-back fails after restart ("Outbound not configured for channel: telegram"). Long-running subagent tasks (30-75 min) have near-zero chance of completing.
Additional information
Suggested fixes:
- (Preferred) Set a flag to suppress the close handler rather than manipulating maxAttempts — lifecycleStopping already exists on line 6944, add a check in handleClose
- Set maxAttempts to a sentinel value that handleReconnectionAttempt treats as "intentional shutdown, don't emit error"
- Catch the error in the health-monitor's restart flow so it doesn't propagate as uncaught
Workaround: Disable Discord (channels.discord.enabled: false).
Note: Also observed a secondary issue — with Discord channel disabled but Discord plugin still enabled (plugins.entries.discord.enabled: true), message-action-discovery still tries to resolve the Discord token SecretRef, causing a separate crash ("Unhandled promise rejection: channels.discord.token: unresolved SecretRef"). Both the channel AND plugin must be disabled as workaround.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
fix(discord): prevent gateway crash during health-monitor restart
fix(discord): suppress reconnect-exhausted crash during health-monito…
lolaopenclaw commentedon Mar 26, 2026
Confirming exact same behavior on our setup.
Environment:
Crash data:
Error: Max reconnect attempts (0) reached after code 1005SafeGatewayPlugin.handleReconnectionAttemptTimeline:
Impact:
Workaround attempted: None yet. Considering disabling Discord channel as temporary mitigation since Telegram is our primary channel.
Logs available if needed — happy to provide full journalctl output.
openperf commentedon Mar 26, 2026
Hey @kAIborg24, thanks for the detailed write-up — the step-by-step reproduction and crash frequency data made it really easy to pinpoint the root cause.
The core issue is a timing problem in onAbort(): it sets maxAttempts to 0 and calls gateway.disconnect(), but at that point the gateway supervisor is still in the active phase. So the synchronous "Max reconnect attempts (0)" error emitted by @buape/carbon during disconnect gets routed to the lifecycle handler instead of being suppressed — and that's what crashes the process.
The fix in PR #55000 is straightforward: call detachLifecycle() before disconnect() so the supervisor transitions to the teardown phase first. The supervisor already has the logic to swallow late errors during teardown — it just wasn't being triggered at the right time.
Worth noting: #54894 reports the exact same crash (Max reconnect attempts (0) reached after code 1005, same stack trace through SafeGatewayPlugin.handleReconnectionAttempt), just triggered via a different entry point (transient network disconnection rather than health-monitor restart). The underlying cause is identical — onAbort() had already mutated maxAttempts to 0 and the supervisor phase wasn't updated before disconnect. So #55000 addresses both issues with the same fix.
ForceConstant commentedon Mar 26, 2026
@openperf any way to workaround with this version until your PR is released?
bokiko commentedon Mar 27, 2026
Also hitting this on 2026.3.24 (cff6dc9) — 14 crashes on Mar 26, 5 so far today.
Environment: Mac Mini M4 Pro, Node v25.8.0, macOS 26.3.1, Homebrew install
Channels: 2 guild channels + DMs
Same stack trace —
handleReconnectionAttemptthrows whenmaxAttempts = 0after health-monitor teardown.Crash cadence is ~60-90 min. launchd restarts each time but the cycle repeats.
Waiting on PR #55000. Downgrade to 2026.3.11 is the current workaround.
openperf commentedon Mar 27, 2026
Quick update on #55000:
Following @steipete's thoughtful review guidance, I've added a targeted regression test covering the three paths he outlined:
The discord-specific CI job (
extension-fast-discord) is passing green. The remaining CI failures are unrelated upstream type errors insrc/agents/— nothing to do with this fix.PR is ready for final review whenever @steipete or other maintainers have a moment.
fix(discord): prevent gateway crash on abort by fixing supervisor tea…
breynol01 commentedon Mar 27, 2026
Confirmed reproduced on macOS 25.3.0 arm64, v2026.3.24, Discord channel.
Observed symptoms:
Validation of root cause: Confirmed in
provider-CAlWEl41.js:onAbortsetsgateway.options.reconnect = { maxAttempts: 0 }handleReconnectionAttemptchecksthis.reconnectAttempts >= maxAttempts→0 >= 0→ true → emits uncaught errorLocal workaround applied (pending upstream fix): patched
handleReconnectionAttemptto checkmaxAttempts === 0first and treat it as an intentional shutdown (silently callthis.monitor.destroy()+ return, no error emit).This aligns with suggested fix option 1 in the issue — adding a
lifecycleStoppingcheck inhandleClosewould be the cleaner upstream fix.openperf commentedon Mar 28, 2026
Sharing what I found from digging into this — hopefully it's useful for everyone here.
The core issue is a race condition during Discord channel teardown:
onAbortsetsmaxAttemptsto 0 and then callsdisconnect(), but Carbon throws the error synchronously, before the lifecycle has a chance to mark itself as shutting down. So the error flies out unhandled.This race condition actually existed before, but the gateway supervision refactor in
v2026.3.24changed the error propagation path in a way that the error is no longer caught locally — it goes straight to the globaluncaughtExceptionhandler, which is why the whole gateway process crashes now instead of just the channel restarting.I've put together a fix in PR #55000 that adjusts the listener registration order during teardown so the supervisor detaches before Carbon's synchronous error can propagate.
I also went through the issue tracker and this single root cause has generated 35+ duplicate issues in the past 48 hours alone (including #56057, #55873, #55618, #55554, #55367, #55350, #55346, #55340, #55301, #55296, #55274, #55260, #54894, #54851, #54752, among many others), so it looks like everyone here is running into the same thing.
If anything needs to be changed, I'm happy to follow up.
sudokrang commentedon Mar 28, 2026
Confirming same issue on v2026.3.24. Getting stale-socket restarts every ~35 minutes. Affects Discord AND Slack — both channels restart simultaneously. Log pattern:
[discord:default] health-monitor: restarting (reason: stale-socket)
[slack:default] health-monitor: restarting (reason: stale-socket)
Both channels affected, not just Discord. Gateway keeps running but channels reconnect repeatedly.
openperf commentedon Mar 29, 2026
@sudokrang Both channels restarting at the same time is the giveaway — Slack and Discord don't share any reconnect code, so a Discord stale-socket can't independently trigger a Slack restart. What's happening is the Discord abort path crashes the whole Node process (the uncaught exception in the issue description), and your process manager brings everything back up together. That's why it looks like both channels are affected when really it's just Discord taking the house down.
#55000 fixes the root cause — the supervisor enters teardown before disconnect() fires, so the synchronous error gets swallowed instead of escaping as an uncaught exception. Once merged, Discord will restart cleanly on its own without dragging Slack along for the ride.
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.