Repository navigation
Conversation
Fixes openclaw#55421 When Discord WS drops with code 1005 (No Status Received), Carbon emits "Max reconnect attempts (0) reached". This was crashing the gateway via uncaught exception because the `lifecycleStopping` flag hadn't been set yet (race between health-monitor abort and lifecycle teardown). reconnect-exhausted should always stop the lifecycle gracefully and let the channel health monitor handle reconnection. Never throw.
Greptile SummaryThis PR fixes a race condition in the Discord gateway lifecycle where a Changes:
One minor note: Confidence Score: 5/5Safe to merge — targeted one-line logic fix with direct test coverage, no behavioral regressions. The change is minimal and precisely addresses the described race condition. The test suite explicitly verifies both the graceful resolution and the error log. The only open item is a cosmetic log-level inconsistency (P2) that does not affect correctness or reliability. No files require special attention beyond the minor logging inconsistency in handleGatewayEvent.
|
| Filename | Overview |
|---|---|
| extensions/discord/src/monitor/provider.lifecycle.ts | Removes the lifecycleStopping && guard from the reconnect-exhausted check in drainPendingGatewayErrors, fixing a race condition where the health monitor could queue this event before lifecycleStopping was set, causing a crash. One minor inconsistency: handleGatewayEvent still guards the info-log path with lifecycleStopping, so the race-condition case still emits at error level despite a graceful exit. |
| extensions/discord/src/monitor/provider.lifecycle.test.ts | Test updated to expect graceful resolution instead of rejection; adds expectLifecycleCleanup assertions to verify full teardown, and explicitly checks that runtimeError is still called so the event is observable in production logs. |
Comments Outside Diff (1)
-
extensions/discord/src/monitor/provider.lifecycle.ts, line 70-75 (link)Inconsistent log level for race-condition path
handleGatewayEventstill has thelifecycleStopping &&guard, so when the race condition fires (lifecycleStopping=falsebutreconnect-exhaustedis queued), the event falls through to thedanger()error log on line 76 instead of the quieter info log here. The lifecycle now exits gracefully in that case (the whole point of this PR), but an error-level message is still emitted — which could create false production alarms.The test explicitly asserts
runtimeErroris called in this scenario, so it appears intentional for now, but it's worth considering whether thelifecycleStopping &&guard should also be dropped here (or an unconditional info-log added forreconnect-exhausted) so the log level reflects the actual severity (graceful stop, not crash).Prompt To Fix With AI
This is a comment left during a code review. Path: extensions/discord/src/monitor/provider.lifecycle.ts Line: 70-75 Comment: **Inconsistent log level for race-condition path** `handleGatewayEvent` still has the `lifecycleStopping &&` guard, so when the race condition fires (`lifecycleStopping=false` but `reconnect-exhausted` is queued), the event falls through to the `danger()` error log on line 76 instead of the quieter info log here. The lifecycle now exits gracefully in that case (the whole point of this PR), but an error-level message is still emitted — which could create false production alarms. The test explicitly asserts `runtimeError` is called in this scenario, so it appears intentional for now, but it's worth considering whether the `lifecycleStopping &&` guard should also be dropped here (or an unconditional info-log added for `reconnect-exhausted`) so the log level reflects the actual severity (graceful stop, not crash). How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/discord/src/monitor/provider.lifecycle.ts
Line: 70-75
Comment:
**Inconsistent log level for race-condition path**
`handleGatewayEvent` still has the `lifecycleStopping &&` guard, so when the race condition fires (`lifecycleStopping=false` but `reconnect-exhausted` is queued), the event falls through to the `danger()` error log on line 76 instead of the quieter info log here. The lifecycle now exits gracefully in that case (the whole point of this PR), but an error-level message is still emitted — which could create false production alarms.
The test explicitly asserts `runtimeError` is called in this scenario, so it appears intentional for now, but it's worth considering whether the `lifecycleStopping &&` guard should also be dropped here (or an unconditional info-log added for `reconnect-exhausted`) so the log level reflects the actual severity (graceful stop, not crash).
```suggestion
if (event.type === "reconnect-exhausted") {
params.runtime.log?.(
`discord: reconnect-exhausted (graceful stop): ${event.message}`,
);
return "stop";
}
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(discord): treat reconnect-exhausted ..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a058b3792f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (event.type === "disallowed-intents" || event.type === "reconnect-exhausted") { | ||
| return "stop"; |
There was a problem hiding this comment.
Do not swallow reconnect-exhausted during startup drain
Returning "stop" for reconnect-exhausted here can strand the lifecycle when that event is drained inside ensureStartupReady()’s beforePoll path: drainPending clears the queued event, ensureStartupReady() returns without throwing, the post-startup drain sees nothing, and waitForDiscordGatewayStop() can then block indefinitely if no further gateway event arrives. Before this change the same startup failure propagated as an error and triggered the normal restart path immediately; now a real reconnect exhaustion can leave the account stuck in a running-but-disconnected state until an external abort/health-monitor intervention.
Useful? React with 👍 / 👎.
Summary
reconnect-exhaustedevents indrainPendingGatewayErrors()now always return"stop"instead of conditionally throwing based onlifecycleStoppingonAbort()setsmaxAttempts=0and disconnects, butlifecycleStoppingisn't set until thefinallyblock — so the queuedreconnect-exhaustedevent would throw an uncaught exceptionChanges
In
extensions/discord/src/monitor/provider.lifecycle.ts:lifecycleStopping &&guard from thereconnect-exhaustedcheck indrainPendingGatewayErrors(), so reconnect-exhausted always gracefully stops the lifecycle instead of crashingIn
extensions/discord/src/monitor/provider.lifecycle.test.ts:Test plan
pnpm test -- extensions/discord/src/monitor/gateway-supervisor.test.ts extensions/discord/src/monitor/provider.lifecycle.test.ts— 25/25 pass