Skip to content

fix(telegram): retry transient file download failures - #246

Merged
grinev merged 5 commits into
grinev:mainfrom
hcsum:fix/telegram-file-download-retry
Sep 23, 2026
Merged

grinev merged 5 commits into
grinev:mainfrom
hcsum:fix/telegram-file-download-retry

Conversation

@hcsum

@hcsum hcsum commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Incoming Telegram media is downloaded with node-fetch, outside the grammY Bot API retry middleware. A single transient failure therefore aborts the whole media group before it reaches OpenCode.

The observed failure was an ECONNRESET before TLS was established. The same path also lacked retries for HTTP 429/5xx responses and failures while reading the response body. In addition, a FetchError can contain the full Telegram file URL—including the bot token—and was logged unchanged.

Fix

  • Run the complete file-download GET, including body consumption, through the shared retry helper.
  • Retry 429 using Retry-After, transient 500/502/503/504 responses, and common transient network errors with exponential backoff, up to three retries.
  • Keep broad network retries opt-in for this idempotent GET path; message-creation calls retain their duplicate-send protection.
  • Prefer structured network codes and HTTP status fields over message-text fallback when classifying errors.
  • Redact the bot token while preserving the error name, stack, and diagnostic fields such as code and status.

Tests

Regression coverage includes:

  • pre-TLS connection reset;
  • 429 with Retry-After;
  • transient 502 response;
  • interrupted response-body read;
  • status-like numbers inside a failed request URL;
  • bot-token redaction with diagnostic fields preserved.

The fault-proxy test helper now writes its call log before disconnecting the client, removing a CI-only race exposed while running the suite.

Verified with npm run lint, npm run typecheck, and npm test (161 files, 1857 tests). CI passes.

@hcsum hcsum changed the title fix(telegram): retry pre-TLS file download failures fix(telegram): retry transient file download failures Sep 22, 2026
@hcsum
hcsum marked this pull request as ready for review September 22, 2026 14:42
@grinev

grinev commented Sep 23, 2026

Copy link
Copy Markdown
Owner

@hcsum thanks for contribution!

@grinev
grinev merged commit 40b6af8 into grinev:main Sep 23, 2026
1 check passed
@hcsum
hcsum deleted the fix/telegram-file-download-retry branch September 23, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants