From 18478b4919f15f88d1863a7a94d9c47108e28b3e Mon Sep 17 00:00:00 2001 From: andyst-dev <150129844+andyst-dev@users.noreply.github.com> Date: Fri, 31 Jul 2026 01:01:26 +0200 Subject: [PATCH] fix(telegram): clear stale polling sessions on conflict retry --- plugins/platforms/telegram/adapter.py | 2 +- tests/gateway/test_telegram_conflict.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/platforms/telegram/adapter.py b/plugins/platforms/telegram/adapter.py index d3f48a90481e6..5c3228bb6b0ef 100644 --- a/plugins/platforms/telegram/adapter.py +++ b/plugins/platforms/telegram/adapter.py @@ -3060,7 +3060,7 @@ async def _handle_polling_conflict(self, error: Exception) -> None: raise RuntimeError("Telegram application was torn down during conflict reconnect") await self._start_polling_once( app, - drop_pending_updates=False, + drop_pending_updates=True, error_callback=self._polling_error_callback_ref, ) logger.info( diff --git a/tests/gateway/test_telegram_conflict.py b/tests/gateway/test_telegram_conflict.py index 46ab719521a11..dd2697591da44 100644 --- a/tests/gateway/test_telegram_conflict.py +++ b/tests/gateway/test_telegram_conflict.py @@ -85,7 +85,7 @@ async def test_polling_conflict_retries_before_fatal(monkeypatch): captured = {} async def fake_start_polling(**kwargs): - captured["error_callback"] = kwargs["error_callback"] + captured.update(kwargs) # Cold connect requires real getUpdates readiness (#67498) — simulate # the first successful poll for the generation this call started, but # only on the initial connect: the conflict-retry generation must NOT @@ -131,6 +131,9 @@ async def fake_start_polling(**kwargs): await adapter._polling_error_task assert adapter.has_fatal_error is False, "First conflict should not be fatal" + assert captured["drop_pending_updates"] is True, ( + "Conflict recovery must ask Telegram to terminate stale getUpdates sessions" + ) assert adapter._polling_conflict_count == 1, ( "Count must remain until the retried generation makes getUpdates progress" )