Repository navigation
fix(telegram): prevent update loss and rebuild loops during polling recovery - #11637
aloneangel45 wants to merge 3 commits into
Conversation
…ecovery Signed-off-by: aloneangel45 <aloneangel45@users.noreply.github.com>
Linked issuesChecked at commit abaf330 #11636 [Bug] Telegram 长轮询在代理抖动时反复重建 client,重建期间 mark-all-fetched-updates 导致消息丢失(4.30.2) · 2 of 4 met
|
There was a problem hiding this comment.
Hey - I've found 10 issues
Sourcery assessment
Needs a human reviewer. 10 findings to address first, and if application shutdown fails after some queued updates have already been handled, the deferred acknowledgement is skipped and Telegram can deliver those updates again. Handlers may send duplicate replies outside the team; reverting cannot retract messages already sent.
Blocking findings: astrbot/core/platform/sources/telegram/tg_adapter.py:311, astrbot/core/platform/sources/telegram/tg_adapter.py:341, astrbot/core/platform/sources/telegram/tg_adapter.py:341, astrbot/core/platform/sources/telegram/tg_adapter.py:235, astrbot/core/platform/sources/telegram/tg_adapter.py:249, and 5 more
| update_queue = getattr(self.application, "update_queue", None) | ||
| if update_queue is None or update_queue.empty(): | ||
| with suppress(Exception): | ||
| await deferred_ack_cb() |
There was a problem hiding this comment.
🟡 Medium · Acknowledges while polling remains active
When updater.stop() fails while its polling task can still fetch updates, and the update queue is empty when checked, updater.stop() exceptions are suppressed without recording that the poller stopped, so a successful application.stop() and momentarily empty queue still allow deferred_ack_cb() to run. A still-active poller can fetch updates after the queue check and have them acknowledged before dispatch, losing those updates.
Only run the deferred acknowledgement after confirming updater.stop() completed successfully and the poller is no longer active.
|
Addressed the review feedback in
Verified locally with |
…k logging Signed-off-by: aloneangel45 <aloneangel45@users.noreply.github.com>
…metadata feedback
|
Addressed the remaining review feedback in
|
Summary
un() now apply exponential backoff (_next_restart_delay(), capped at max(delay, 60.0)) instead of hammering rebuilds at a fixed interval, and reset once polling runs cleanly past _polling_failure_window.
Fixes #11636
Verification
uff format --check astrbot/core/platform/sources/telegram/tg_adapter.py tests/test_telegram_adapter.py (passed)
uff check astrbot/core/platform/sources/telegram/tg_adapter.py tests/test_telegram_adapter.py (passed)
Summary by Sourcery
Prevent Telegram polling recovery from losing queued updates and reduce repeated rebuilds during persistent failures.
Bug Fixes:
Enhancements:
Tests:
Chores: