Repository navigation
Conversation
Greptile SummaryThis PR fixes a gateway crash caused by incorrect supervisor phase transition ordering during abort. When Confidence Score: 5/5Safe to merge — the fix is minimal, correct, and CI is passing. The two-line root-cause fix (calling detachLifecycle() before disconnect()) directly addresses the described crash by transitioning the supervisor to teardown phase before the synchronous error is emitted. The secondary !lifecycleStopping guard in the catch block is a valid defence-in-depth. The detachLifecycle() implementation is idempotent so the double-call with the finally block is harmless. All edge cases (early abort, null gateway, concurrent teardown) are handled correctly by existing guards. No regressions identified. No files require special attention.
|
| Filename | Overview |
|---|---|
| extensions/discord/src/monitor/provider.lifecycle.ts | Adds detachLifecycle() call before gateway.disconnect() in onAbort() to fix supervisor teardown ordering, and adds !lifecycleStopping guard in catch block as a defence-in-depth against errors during intentional shutdown. |
Reviews (1): Last reviewed commit: "fix(discord): prevent gateway crash on a..." | Re-trigger Greptile
|
Root cause and fix direction look right. One gap before merge: please add a targeted regression test for the actual abort crash path. What I want covered:
Current abort coverage in Optional follow-up: the widened |
6d3f7f0 to
ee189bb
Compare
Thanks for the clear guidance, @steipete — it made the test much easier to get right. I've added a dedicated regression test (
I also replaced the fragile Re the widened |
…rdown ordering Transition the gateway supervisor to the teardown phase before calling gateway.disconnect() during an intentional abort (health-monitor restart, manual stop, etc.). This ensures that the synchronous "Max reconnect attempts (0)" error emitted by @buape/carbon is safely suppressed by the supervisor instead of being routed to the lifecycle handler and surfacing as an uncaught exception that crashes the entire gateway process. As an additional safety net, the catch block now swallows errors when the lifecycle is already stopping, preventing any edge-case re-throw during intentional shutdown. Closes openclaw#54931 Closes openclaw#54894
ee189bb to
e1f87a6
Compare
|
Also addressed the CWE-772 flagged by aisle-research-bot — the Fixed by extracting it into a named reference ( |
|
Will be glad to have this fixed. Thanks. 👍 |
|
Just wanted to add some context on the scope of this. I spent some time going through the issue tracker and it turns out this race condition has been hitting a lot of people since In short, the Discord gateway supervision refactor in I found 35+ duplicate issues from just the last 48 hours that all trace back to the same root cause: Open (16): Closed (19): One small thought: it might be worth adding Would appreciate it if the maintainers could review this when they have a chance. Happy to make any changes needed — just let me know. |
|
This is the most complete fix for the stale-socket restart crash. The other attempts (#55699, #55991) patched the symptom at the lifecycle layer, but the underlying issue is the supervisor phase transition ordering in Root cause summary: This PR's fix: #55991 (merged) addresses the crash symptom via |
|
Now that #55991 is merged, just wanted to note that this PR remains complementary — #55991 suppresses reconnect-exhausted unconditionally in drainPendingGatewayErrors(), while this PR #55000 scopes the fix to the abort path only by transitioning the supervisor to "teardown" before disconnect(). This avoids masking reconnect failures outside the intentional shutdown window. |
|
Thank you for the hard work on this. Your efforts are being noticed. I spoke with the upstream maintainer and this was fixed there. That means I will close this for the time being. If you are still experiencing this issue on the latest release then please drop a note in #clawtributors channel and I will reopen this PR. |
Summary
A transient Discord WebSocket disconnection (e.g. close code 1005) or an intentional health-monitor restart can trigger an uncaught
Max reconnect attempts (0)exception that crashes the entire gateway process. This kills all channels (Feishu, WhatsApp, Telegram, etc.), not just Discord.This PR fixes the root cause of these gateway crashes by correcting the supervisor phase transition ordering during an abort.
Fixes #54931
Fixes #54894
Root Cause
The gateway crash happens due to an error routing mismatch during teardown:
onAbort()setsmaxAttemptsto 0 and callsgateway.disconnect().disconnect()synchronously triggers@buape/carbon'shandleClose→handleReconnectionAttempt, which emits aMax reconnect attempts (0)error on the gateway emitter.gateway-supervisoris still in the active phase at this point, so it routes the error to the lifecycle handler instead of suppressing it.The supervisor already has the correct teardown suppression logic (it logs and swallows late errors during the teardown phase). The bug is simply that
onAbort()never transitions the supervisor to the teardown phase before disconnecting.Changes
1. Fix teardown ordering in
onAbort()Call
params.gatewaySupervisor.detachLifecycle()beforegateway.disconnect(). This ensures the supervisor enters the teardown phase and correctly suppresses the synchronous error emitted during disconnect.2. Add
lifecycleStoppingsafety netIn the
catchblock, whenlifecycleStoppingis alreadytrue, we no longer re-throw errors. This acts as a defense-in-depth guard for any edge case where an error might still escape during an intentional shutdown.Test Results
extension-fast (extension-fast-discord, discord)CI check passes.