From 687d0b4208ce965f865a1816de678341af4ecb36 Mon Sep 17 00:00:00 2001 From: Tom Alison <6170+talison@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:07:49 -0700 Subject: [PATCH] fix: promote consecutiveStallRestarts to class field The counter was declared as a local variable inside #runPollingCycle(), resetting to 0 on every cycle restart. This made the escalation to process.exit(1) after MAX_CONSECUTIVE_POLL_RESTARTS dead code since the counter never accumulated across restarts. Promote to a private class field (#consecutiveStallRestarts) matching the pattern used by #restartAttempts, so stall restarts accumulate correctly and the process-exit escalation works as intended. --- extensions/telegram/src/polling-session.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions/telegram/src/polling-session.ts b/extensions/telegram/src/polling-session.ts index 1f5c9c0dd97..e8b059bbee5 100644 --- a/extensions/telegram/src/polling-session.ts +++ b/extensions/telegram/src/polling-session.ts @@ -52,6 +52,7 @@ type TelegramPollingSessionOpts = { export class TelegramPollingSession { #restartAttempts = 0; + #consecutiveStallRestarts = 0; #webhookCleared = false; #forceRestarted = false; #activeRunner: ReturnType | undefined; @@ -183,13 +184,12 @@ export class TelegramPollingSession { await this.#confirmPersistedOffset(bot); let lastGetUpdatesAt = Date.now(); - let consecutiveStallRestarts = 0; bot.api.config.use(async (prev, method, payload, signal) => { const result = await prev(method, payload, signal); if (method === "getUpdates") { lastGetUpdatesAt = Date.now(); this.#restartAttempts = 0; - consecutiveStallRestarts = 0; + this.#consecutiveStallRestarts = 0; } return result; }); @@ -232,16 +232,16 @@ export class TelegramPollingSession { } const elapsed = Date.now() - lastGetUpdatesAt; if (elapsed > POLL_STALL_THRESHOLD_MS && runner.isRunning()) { - consecutiveStallRestarts += 1; + this.#consecutiveStallRestarts += 1; stalledRestart = true; - if (consecutiveStallRestarts >= MAX_CONSECUTIVE_POLL_RESTARTS) { + if (this.#consecutiveStallRestarts >= MAX_CONSECUTIVE_POLL_RESTARTS) { this.opts.log( - `[telegram] Polling recovery exhausted after ${consecutiveStallRestarts} consecutive stall restarts without successful getUpdates; escalating to process exit.`, + `[telegram] Polling recovery exhausted after ${this.#consecutiveStallRestarts} consecutive stall restarts without successful getUpdates; escalating to process exit.`, ); process.exit(1); } this.opts.log( - `[telegram] Polling stall detected (no getUpdates for ${formatDurationPrecise(elapsed)}); forcing restart (attempt ${consecutiveStallRestarts}/${MAX_CONSECUTIVE_POLL_RESTARTS}).`, + `[telegram] Polling stall detected (no getUpdates for ${formatDurationPrecise(elapsed)}); forcing restart (attempt ${this.#consecutiveStallRestarts}/${MAX_CONSECUTIVE_POLL_RESTARTS}).`, ); void stopRunner(); void stopBot();