fix(telegram): route PTB NetworkError/TimedOut from polling heartbeat into reconnect path (#62047) - #63007
Conversation
… into reconnect path (NousResearch#62047)
|
Thanks for the focused Telegram regression analysis. This is already implemented on current
Closing as redundant with the implementation already on main. |
Duplicate of #62098 (merged 2026-07-10, canonical salvage that closed #62047). That PR already shipped the same PTB |
|
Thanks! this was in flight before I saw #62098 had landed; good to see it converged on the same classification design (BadRequest/InvalidToken exclusions, routing through One bug still open is #62098: |
What does this PR do?
Fixes #62047 — the polling heartbeat's probe handler only routed
asyncio.TimeoutError/OSErrorinto the reconnect path. In PTB 22.x,telegram.error.NetworkErrorandTimedOutinherit fromTelegramError(notOSError), so real connectivity failures fell through to a genericexcept Exceptionand were silently ignored — the gateway kept reporting Telegram as connected while the heartbeat never initiated recovery.Related Issue
Closes #62047
Type of Change
Changes Made
plugins/platforms/telegram/adapter.pyExceptionand classifies via the existing_looks_like_network_error()helper, so PTBNetworkError/TimedOutenter the same recovery ladder asTimeoutError/OSError. Non-connectivity errors keep the old behavior (deferred to PTB's own handlers)._is_request_validation_error()guard: PTB'sBadRequestsubclassesNetworkError, so classification by base class alone would send HTTP 400 request-validation failures into the reconnect ladder — where a successfulstart_pollingresets the retry counter and the churn never escalates to fatal. BadRequest stays non-retryable._redact_telegram_error_text()(PTB transport errors can embed the bot-token request URL), matching every sibling logging site._probe_pending_updates' webhook-info handler keeps its original deliberate deferral (a failed probe is the get_me() path's job to confirm; first-failure teardown of a healthy poller would regress Telegram gateway connects and polls successfully but incoming DMs produce zero log output and no response (WSL2, v0.16.0, PTB 22.6) #42909's debounce design) — PTB connectivity errors now get that same deferral instead of leaking upward as unclassified exceptions.tests/gateway/test_telegram_network_reconnect.py,test_telegram_pending_update_probe.py)NetworkError/TimedOut(parametrized); no reconnect onInvalidToken; no reconnect onBadRequestdespite it being aNetworkErrorsubclass; webhook-info probe defers connectivity errors and propagates non-connectivity errors.TelegramError-derived, notOSError-derived): the pre-existing gateway-conftest mock derivesNetworkErrorfromOSError, which the unfixed code already caught — tests written against it pass with or without this fix. Verified these tests fail on unfixedmain.telegram.error(the new top-level import made the standalone fallback a guaranteedModuleNotFoundError).How to Test
43 passed. Also verified the regression tests fail against unfixed
main(reverted adapter, reran: 3 failures, all new tests).Notes for reviewers
tests/gateway/conftest.py) still modelsNetworkErroras anOSErrorsubclass, diverging from real PTB. This PR works around it locally; aligning the shared mock with PTB's real hierarchy would benefit the whole gateway suite but touches many tests, so it's left out of this fix._verify_polling_after_reconnecthas the mirror-image gap (routes everyget_me()failure, includingInvalidToken, into recovery, and bypasses the_polling_error_taskdedup guard). Deliberately out of scope; can file separately if useful.Checklist