Skip to content

Commit 65dc78f

Browse files
rootroot
authored andcommitted
fix: Telegram health-monitor stale-socket restart every ~35min on 2026.3.2 (post-#10795 fix)
1 parent 48b3c4a commit 65dc78f

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/gateway/channel-health-monitor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export function startChannelHealthMonitor(deps: ChannelHealthMonitorDeps): Chann
122122
continue;
123123
}
124124
const healthPolicy: ChannelHealthPolicy = {
125+
channelId,
125126
now,
126127
staleEventThresholdMs: timing.staleEventThresholdMs,
127128
channelConnectGraceMs: timing.channelConnectGraceMs,

src/gateway/channel-health-policy.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type ChannelHealthEvaluation = {
2828
};
2929

3030
export type ChannelHealthPolicy = {
31+
channelId?: string;
3132
now: number;
3233
staleEventThresholdMs: number;
3334
channelConnectGraceMs: number;
@@ -97,6 +98,11 @@ export function evaluateChannelHealth(
9798
if (snapshot.connected === false) {
9899
return { healthy: false, reason: "disconnected" };
99100
}
101+
// Skip stale-socket check for Telegram (long-polling mode). Each polling request
102+
// acts as a heartbeat, so the half-dead WebSocket scenario this check is designed
103+
// to catch does not apply to Telegram's long-polling architecture.
104+
if (policy.channelId !== "telegram") {
105+
100106
if (snapshot.lastEventAt != null || snapshot.lastStartAt != null) {
101107
const upSince = snapshot.lastStartAt ?? 0;
102108
const upDuration = policy.now - upSince;
@@ -108,6 +114,7 @@ export function evaluateChannelHealth(
108114
}
109115
}
110116
}
117+
}
111118
return { healthy: true, reason: "healthy" };
112119
}
113120

src/gateway/server/readiness.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,18 @@ export function createReadinessChecker(deps: {
5050

5151
const snapshot = channelManager.getRuntimeSnapshot();
5252
const failing: string[] = [];
53-
const policy: ChannelHealthPolicy = {
54-
now,
55-
staleEventThresholdMs: DEFAULT_CHANNEL_STALE_EVENT_THRESHOLD_MS,
56-
channelConnectGraceMs: DEFAULT_CHANNEL_CONNECT_GRACE_MS,
57-
};
5853

5954
for (const [channelId, accounts] of Object.entries(snapshot.channelAccounts)) {
6055
if (!accounts) {
6156
continue;
6257
}
6358
for (const accountSnapshot of Object.values(accounts)) {
59+
const policy: ChannelHealthPolicy = {
60+
now,
61+
staleEventThresholdMs: DEFAULT_CHANNEL_STALE_EVENT_THRESHOLD_MS,
62+
channelConnectGraceMs: DEFAULT_CHANNEL_CONNECT_GRACE_MS,
63+
channelId,
64+
};
6465
if (!accountSnapshot) {
6566
continue;
6667
}

0 commit comments

Comments
 (0)