Skip to content

Commit 02e3061

Browse files
authored
fix(discord): stop queued reconnect exhaustion crash (#55991)
1 parent 496a1a3 commit 02e3061

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Docs: https://docs.openclaw.ai
7676
- Talk/macOS: stop direct system-voice failures from replaying system speech, use app-locale fallback for shared watchdog timing, and add regression coverage for the macOS fallback route and language-aware timeout policy. (#53511) thanks @hongsw.
7777
- Discord/gateway cleanup: keep late Carbon reconnect-exhausted errors suppressed through startup/dispose cleanup so Discord monitor shutdown no longer crashes on late gateway close events. (#55373) Thanks @Takhoffman.
7878
- Discord/gateway shutdown: treat expected reconnect-exhausted events during intentional lifecycle stop as clean shutdowns so startup-abort cleanup no longer surfaces false gateway failures. (#55324) Thanks @joelnishanth.
79+
- Discord/gateway shutdown: suppress reconnect-exhausted events that were already buffered before teardown flips `lifecycleStopping`, so stale-socket Discord restarts no longer crash the whole gateway. Fixes #55403 and #55421. Thanks @lml2468 and @vincentkoc.
7980
- GitHub Copilot/auth refresh: treat large `expires_at` values as seconds epochs and clamp far-future runtime auth refresh timers so Copilot token refresh cannot fall into a `setTimeout` overflow hot loop. (#55360) Thanks @michael-abdo.
8081
- Agents/status: use the persisted runtime session model in `session_status` when no explicit override exists, and honor per-agent `thinkingDefault` in both `session_status` and `/status`. (#55425) Thanks @scoootscooob, @xaeon2026, and @ysfbsf.
8182
- Heartbeat/runner: guarantee the interval timer is re-armed after heartbeat runs and unexpected runner errors so scheduled heartbeats do not silently stop after an interrupted cycle. (#52270) Thanks @MiloStack.

‎extensions/discord/src/monitor/provider.lifecycle.test.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ describe("runDiscordGatewayLifecycle", () => {
813813
}
814814
});
815815

816-
it("does not suppress reconnect-exhausted already queued before shutdown", async () => {
816+
it("suppresses reconnect-exhausted already queued before shutdown", async () => {
817817
const { runDiscordGatewayLifecycle } = await import("./provider.lifecycle.js");
818818
const pendingGatewayEvents: DiscordGatewayEvent[] = [];
819819
const abortController = new AbortController();
@@ -836,8 +836,8 @@ describe("runDiscordGatewayLifecycle", () => {
836836

837837
// Start lifecycle; it yields at execApprovalsHandler.start(). We then
838838
// queue a reconnect-exhausted event and abort. The lifecycle resumes and
839-
// drains the queued fatal event before shutdown teardown flips
840-
// lifecycleStopping, so the event still rejects the run.
839+
// drains the queued event before shutdown teardown flips lifecycleStopping,
840+
// so drainPending must treat it as a graceful stop.
841841
const lifecyclePromise = runDiscordGatewayLifecycle(lifecycleParams);
842842

843843
pendingGatewayEvents.push(
@@ -848,9 +848,7 @@ describe("runDiscordGatewayLifecycle", () => {
848848
);
849849
abortController.abort();
850850

851-
await expect(lifecyclePromise).rejects.toThrow(
852-
"Max reconnect attempts (0) reached after code 1005",
853-
);
851+
await expect(lifecyclePromise).resolves.toBeUndefined();
854852
expect(runtimeLog).not.toHaveBeenCalledWith(
855853
expect.stringContaining("ignoring expected reconnect-exhausted during shutdown"),
856854
);

‎extensions/discord/src/monitor/provider.lifecycle.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,10 @@ export async function runDiscordGatewayLifecycle(params: {
8282
if (decision !== "stop") {
8383
return "continue";
8484
}
85-
// Don't throw for expected shutdown events — intentional disconnect
86-
// (reconnect-exhausted with maxAttempts=0) and disallowed-intents are
87-
// both handled without crashing the provider.
88-
if (
89-
event.type === "disallowed-intents" ||
90-
(lifecycleStopping && event.type === "reconnect-exhausted")
91-
) {
85+
// Don't throw for expected shutdown events. `reconnect-exhausted` can be
86+
// queued before teardown flips `lifecycleStopping`, so treat it as a
87+
// graceful stop here and let the health monitor own reconnect behavior.
88+
if (event.type === "disallowed-intents" || event.type === "reconnect-exhausted") {
9289
return "stop";
9390
}
9491
throw event.err;

0 commit comments

Comments
 (0)