fix(telegram): detect wedged send path after reconnect storms (#31165)#31441
Merged
Conversation
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
unresolved-import |
1 |
unresolved-attribute |
1 |
First entries
tests/gateway/test_telegram_send_path_health.py:12: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`
tests/gateway/test_telegram_send_path_health.py:65: [unresolved-attribute] unresolved-attribute: Attribute `send_message` is not defined on `None` in union `Unknown | None`
✅ Fixed issues: none
Unchanged: 4834 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
…#31165) After sustained Bad Gateway / TimedOut reconnect cycles, the PTB httpx client can enter a state where bot.send_message() returns a valid Message (real message_id) but the message never reaches the recipient. TelegramAdapter.send returns SendResult(success=True) and cron's live-adapter branch marks the run delivered while the message is silently dropped. Add a _send_path_degraded flag. _handle_polling_network_error sets it on reconnect storms; the existing _verify_polling_after_reconnect heartbeat probe clears it once getMe() confirms the Bot client is healthy. While the flag is set, send() short-circuits with SendResult(success=False, retryable=True) so cron falls through to the standalone delivery path (fresh HTTP session). Closes #31165. Co-authored-by: teknium1 <127238744+teknium1@users.noreply.github.com>
bb4fd7e to
c0441cb
Compare
Collaborator
This was referenced May 24, 2026
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.
Summary
Cron
deliver: telegram:CHAT_IDno longer silently drops messages after sustained Telegram reconnect storms. After Bad Gateway / TimedOut bursts, the PTB httpx pool could enter a state wherebot.send_message()returned a validMessage(realmessage_id) but never transmitted;TelegramAdapter.sendreported success and cron's live-adapter branch marked the run delivered.Closes #31165.
How
Add
_send_path_degradedtoTelegramAdapter:_handle_polling_network_error(any reconnect attempt)._verify_polling_after_reconnectheartbeat probe, oncegetMe()confirms the Bot client is healthy.send()short-circuits withSendResult(success=False, retryable=True)so cron's live-adapter branch falls through to the standalone HTTP path (fresh session).The heartbeat probe already runs 60s after each reconnect with a 10s timeout — we reuse it as the source of truth instead of duplicating a
getMe()probe on every send.Changes
gateway/platforms/telegram.py: 14 LOC. Field init + set on reconnect + clear on heartbeat + 4-line short-circuit insend().getattr()read so test fixtures usingobject.__new__(TelegramAdapter)survive.tests/gateway/test_telegram_send_path_health.py: 3 focused tests — healthy path delivers, degraded path short-circuits without callingsend_message, storm-sets/heartbeat-clears the flag.Validation
tests/gateway/test_telegram_send_path_health.py(3 new)tests/gateway/test_telegram_*.py(11 files, 288 tests — all 10object.__new__(TelegramAdapter)fixtures)tests/cron/(14 files, 373 tests)Authored by @dskwe; reshaped onto current main with the minimum touch (14 LOC vs. original 39) — reuses the existing reconnect heartbeat instead of adding a per-send
getMe()probe.Infographic