From 066d589b8aaa8ae5f6cf1a16af7409f5af51e769 Mon Sep 17 00:00:00 2001 From: SidQin-cyber Date: Fri, 6 Mar 2026 00:26:20 +0800 Subject: [PATCH] fix(gateway): distinguish disconnected from stuck in health-monitor restart reason resolveChannelRestartReason did not handle the "disconnected" evaluation reason explicitly, so it fell through to "stuck". This conflates a clean WebSocket drop (e.g. Discord 1006) with a genuinely stuck channel, making logs misleading and preventing future policy differentiation. Add "disconnected" to ChannelRestartReason and handle it before the catch-all "stuck" return. Closes #36404 --- src/gateway/channel-health-policy.test.ts | 13 +++++++++++++ src/gateway/channel-health-policy.ts | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/gateway/channel-health-policy.test.ts b/src/gateway/channel-health-policy.test.ts index 1509bccc4ba..906ea559bde 100644 --- a/src/gateway/channel-health-policy.test.ts +++ b/src/gateway/channel-health-policy.test.ts @@ -234,4 +234,17 @@ describe("resolveChannelRestartReason", () => { ); expect(reason).toBe("gave-up"); }); + + it("maps disconnected to disconnected instead of stuck", () => { + const reason = resolveChannelRestartReason( + { + running: true, + connected: false, + enabled: true, + configured: true, + }, + { healthy: false, reason: "disconnected" }, + ); + expect(reason).toBe("disconnected"); + }); }); diff --git a/src/gateway/channel-health-policy.ts b/src/gateway/channel-health-policy.ts index b3bc74bfc4d..27d7cd1f7b2 100644 --- a/src/gateway/channel-health-policy.ts +++ b/src/gateway/channel-health-policy.ts @@ -36,7 +36,7 @@ export type ChannelHealthPolicy = { channelConnectGraceMs: number; }; -export type ChannelRestartReason = "gave-up" | "stopped" | "stale-socket" | "stuck"; +export type ChannelRestartReason = "gave-up" | "stopped" | "stale-socket" | "stuck" | "disconnected"; function isManagedAccount(snapshot: ChannelHealthSnapshot): boolean { return snapshot.enabled !== false && snapshot.configured !== false; @@ -133,5 +133,8 @@ export function resolveChannelRestartReason( if (evaluation.reason === "not-running") { return snapshot.reconnectAttempts && snapshot.reconnectAttempts >= 10 ? "gave-up" : "stopped"; } + if (evaluation.reason === "disconnected") { + return "disconnected"; + } return "stuck"; }