Skip to content

Fix #40691: Reset polling error task guard after successful conflict retry - #40986

Closed
iamlukethedev wants to merge 1 commit into
NousResearch:mainfrom
iamlukethedev:fix/40691-telegram-polling-freeze
Closed

Fix #40691: Reset polling error task guard after successful conflict retry#40986
iamlukethedev wants to merge 1 commit into
NousResearch:mainfrom
iamlukethedev:fix/40691-telegram-polling-freeze

Conversation

@iamlukethedev

Copy link
Copy Markdown
Contributor

Issue: #40691 — Telegram gateway freezes after polling conflict recovery.

After recovering from a HTTP 409 polling conflict, the gateway remains running but stops processing all Telegram messages (both interactive DMs and passive group chat routing).

Root Cause: After successfully restarting polling in _handle_polling_conflict, the _polling_error_task guard was not reset to None. This caused the error callback guard on line 1704 to silently drop subsequent errors, leaving the gateway frozen.

Solution: Reset _polling_error_task = None after successful polling restart. This allows the error callback to process new errors immediately.

Changes:

  • 1 line fix in gateway/platforms/telegram.py (line 1131)
  • 4 comprehensive regression tests validating callback task guard behavior
  • All existing 6 conflict tests pass

Test Coverage:

  • Error callback task guard allows multiple errors when task is reset
  • Error callback task guard correctly blocks concurrent errors
  • Conflict recovery pattern properly resets task guard
  • Stored callback references remain valid after polling restart

…ul conflict retry

Issue NousResearch#40691: Telegram gateway freezes after recovering from a polling conflict
(HTTP 409). After successful retry, the gateway appears to be running but stops
processing all Telegram messages (both DMs and passive group chat routing).

Root Cause: After successfully restarting polling in _handle_polling_conflict,
the _polling_error_task guard was not reset to None. This caused the error
callback guard (line 1704: if self._polling_error_task and not self._polling_error_task.done())
to silently drop subsequent errors, leaving the gateway frozen but apparently running.

Solution: Reset _polling_error_task to None after successful polling restart
(line 1131). This allows the error callback to process new errors immediately.

The fix is minimal and surgical:
- After start_polling() succeeds (line 1121-1125)
- Reset the task guard to None (new line: self._polling_error_task = None)
- This allows subsequent errors to invoke the callback (guards on line 1704 passes)

Added 4 comprehensive tests demonstrating:
- Callback task guard allows multiple errors when task is None
- Callback task guard blocks concurrent errors (expected behavior)
- Conflict recovery pattern includes task guard reset
- Callback references remain valid after polling restart

All existing conflict tests pass (6 tests).
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P1 High — major feature broken, no workaround labels Jun 7, 2026
@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jun 21, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Automated hermes-sweeper review: this PR’s target behavior appears implemented on current main through later Telegram polling recovery work.

Evidence:

  • plugins/platforms/telegram/adapter.py:2035 now owns the current _handle_polling_conflict path; on retry failure it schedules the next attempt instead of returning silently, and on success it restarts polling and resets the conflict counter.
  • plugins/platforms/telegram/adapter.py:2723 shows the current callback guard only drops errors while _polling_error_task is still running; a completed successful recovery task does not suppress later errors.
  • plugins/platforms/telegram/adapter.py:1837 and plugins/platforms/telegram/adapter.py:1866 add the heartbeat / pending_update_count wedged-consumer detection that covers the reported “polling resumed but updates stop flowing” state.
  • Commit d5ba374c0 (fix(telegram): detect wedged getUpdates consumer via pending_update_count) and f03823014 (fix(telegram): kill 409 polling conflict loop by disarming PTB retry synchronously) landed after this PR and supersede the one-line recovery fix.
  • The linked issue [BUG] Telegram Gateway freezes after polling conflict recovery — passive routing stops working #40691 was closed by a maintainer as substantially fixed on current main after those changes.

Thanks for the focused fix and regression-test direction. The underlying bug class has since been handled on main, so this stale PR can be closed as implemented.

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

Labels

comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround platform/telegram Telegram bot adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:implemented-on-main Sweeper: behavior already present on current main 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.

3 participants