Skip to content

fix(telegram): clear stale polling sessions on conflict retry - #75073

Closed
andyst-dev wants to merge 1 commit into
NousResearch:mainfrom
andyst-dev:fix/telegram-polling-conflict
Closed

fix(telegram): clear stale polling sessions on conflict retry#75073
andyst-dev wants to merge 1 commit into
NousResearch:mainfrom
andyst-dev:fix/telegram-polling-conflict

Conversation

@andyst-dev

Copy link
Copy Markdown
Contributor

Summary

  • restart Telegram polling conflict recovery with drop_pending_updates=True
  • keep normal reconnects preserving pending updates unchanged
  • add regression coverage that conflict recovery terminates stale getUpdates sessions

Fixes #75017

Tests

  • scripts/run_tests.sh tests/gateway/test_telegram_conflict.py -q
  • python3 -m py_compile plugins/platforms/telegram/adapter.py tests/gateway/test_telegram_conflict.py
  • git diff --check

@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins platform/telegram Telegram bot adapter P3 Low — cosmetic, nice to have sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 30, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the focused regression attempt. The conflict-recovery call is still present on current main, but this change is unsafe as written.

Problems

  • plugins/platforms/telegram/adapter.py:3060 changes recovery to drop_pending_updates=True. PTB 22.6 documents that flag as cleaning pending updates, and its bootstrap forwards it to delete_webhook. Hermes explicitly preserves that queue for reconnects because dropping it silently loses messages (plugins/platforms/telegram/adapter.py:3584-3590; tests/gateway/test_platform_reconnect.py:165-169).
  • The new assertion only verifies that the mocked start_polling receives the flag (tests/gateway/test_telegram_conflict.py:88,134); it does not establish that the flag terminates a competing getUpdates session.

Suggested changes

  • Retain queue preservation and identify a recovery mechanism that can be demonstrated to clear the conflict without deleting queued updates.
  • Cover that mechanism with an integration-level test of the PTB bootstrap/API behavior.

Automated hermes-sweeper review.

@@ -3060,7 +3060,7 @@ async def _handle_polling_conflict(self, error: Exception) -> None:
raise RuntimeError("Telegram application was torn down during conflict reconnect")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTB 22.6 defines this flag as dropping pending Telegram updates and forwards it to delete_webhook; it does not establish stale-session termination. This conflicts with the adapter's explicit reconnect contract at adapter.py:3584-3590, which preserves queued messages to avoid silent loss. Please keep preservation unless a supported recovery operation can prove both session cleanup and no message loss.

@teknium1 teknium1 added sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform area/sessions Session lifecycle, resume, persistence, history labels Jul 30, 2026
@andyst-dev

Copy link
Copy Markdown
Contributor Author

Withdrawing this cut after review: using drop_pending_updates=True in conflict recovery can also delete queued Telegram updates, so it is not safe enough for the reconnect/message-delivery contract. I'll look for a queue-preserving recovery path instead of keeping this unsafe variant open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform 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.

Telegram polling conflict: self-perpetuating retry loop from drop_pending_updates=False

3 participants