Skip to content

fix(telegram): classify PTB heartbeat transport errors - #62098

Merged
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/62060-telegram-network
Jul 10, 2026
Merged

fix(telegram): classify PTB heartbeat transport errors#62098
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/62060-telegram-network

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Telegram polling heartbeat failures wrapped by python-telegram-bot now enter the existing reconnect ladder, while semantic Bot API errors remain non-retryable.

Based on #62060 by @liuhao1024. The substantive production commit preserves the contributor's authorship.

What changed

  • Route heartbeat errors from both get_me() and the pending-update probe through the shared _looks_like_network_error() classifier.
  • Correct that classifier for PTB 22.6's hierarchy, where BadRequest inherits from NetworkError despite being a permanent request error.
  • Reuse the classifier for Telegram initialization retries and the polling callback, so all reconnect decisions share one policy.
  • Route heartbeat recovery through _schedule_polling_recovery() for existing-task dedupe and background-task lifecycle tracking.
  • Make gateway Telegram mocks reproduce PTB's real exception inheritance.
  • Add load-bearing behavior tests for transport and semantic errors across both heartbeat probe paths, plus shared-consumer guards.

Divergence from #62060

The original inline isinstance(NetworkError) classifier was not retained because it also matched PTB BadRequest. Its negative test used an unrealistic mock hierarchy and passed on unmodified main. This salvage fixes the shared classifier instead of adding a second policy.

Verification

  • 98 passed across Telegram reconnect, pending-update, and thread-fallback suites.
  • Real PTB 22.6 matrix on both heartbeat paths:
    • NetworkError, TimedOut -> one recovery
    • BadRequest, InvalidToken, Forbidden, RetryAfter -> no recovery
  • Mutation check: removing semantic exclusions fails 3 regression tests.
  • Ruff, compile, and diff checks pass.
  • Codex final review: no Critical or Warning findings.

Closes #62060
Closes #62047

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P1 High — major feature broken, no workaround sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround platform/telegram Telegram bot adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram polling heartbeat swallows python-telegram-bot NetworkError, so reconnect is never triggered

3 participants