fix(telegram): retry polling on transient network errors#976
Open
snemesh wants to merge 1 commit intoanthropics:mainfrom
Open
fix(telegram): retry polling on transient network errors#976snemesh wants to merge 1 commit intoanthropics:mainfrom
snemesh wants to merge 1 commit intoanthropics:mainfrom
Conversation
The polling loop currently exits permanently on any error that isn't a 409 Conflict. A single network hiccup (ECONNRESET, ETIMEDOUT, DNS failure, Telegram 5xx) kills the bot — messages stop arriving and the user has to restart Claude Code to recover. This adds retry-with-backoff for transient errors while preserving immediate exit on permanent failures (401 Unauthorized, invalid token). The backoff counter resets after a successful connection via onStart, so intermittent flakes don't accumulate penalty. Fixes anthropics#963
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Telegram plugin's polling loop exits permanently on any error that isn't a 409 Conflict (line 991-992 in
server.ts). A single transient network issue —ECONNRESET,ETIMEDOUT, DNS failure, or a Telegram 5xx — silently kills the bot. Messages stop arriving and the user must restart Claude Code to recover.This is the root cause behind several open issues:
Fix
isTransientError()helper that classifies errors as retryable: Node.js network codes (ECONNRESET,ECONNREFUSED,ETIMEDOUT,ENETUNREACH,EAI_AGAIN,EPIPE), fetch/TLS failures, and Telegram 5xx server errors.onStartcallback, so intermittent flakes don't accumulate penalty across reconnections.shuttingDownguard to avoid retrying during graceful shutdown.Changes
external_plugins/telegram/server.ts— 43 insertions, 12 deletionsTest plan
bun buildpasses (1.1MB bundle, 0 errors)isTransientError()correctly classifies 19/19 error types (ECONNRESET, ETIMEDOUT, EAI_AGAIN, fetch failed, 5xx → retry; 401, 400, 403, 409, unknown → exit)bun server.ts, process suspended withSIGSTOPfor 35s to force Telegram to drop the long-poll connection, resumed withSIGCONT— bot recovered via retry loop and resumed pollingUnit test output (19/19 passed)
Integration test output (7/7 passed)
Fixes #963