Skip to content

fix(gateway): recover Telegram polling after conflicts (#40691) - #40827

Closed
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/40691-telegram-conflict-recovery
Closed

fix(gateway): recover Telegram polling after conflicts (#40691)#40827
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/40691-telegram-conflict-recovery

Conversation

@Tranquil-Flow

Copy link
Copy Markdown
Contributor

What

Fixes #40691 by hardening Telegram polling conflict recovery so the gateway does not remain alive-but-wedged after a 409 conflict.

Changes:

  • restart conflict polling with drop_pending_updates=True to clear stale getUpdates state
  • schedule _verify_polling_after_reconnect() after successful conflict retry, matching the network-reconnect path so a wedged updater is detected and recovered
  • add focused regression coverage in the existing Telegram reconnect tests for both layers

Why

The issue reports that after conflict recovery the gateway logs "polling resumed" but stops processing both DMs and passive group routing until a full restart. The existing conflict retry could resume from stale pending updates and had no post-reconnect probe, so a dead consumer could sit silently while the process still reported healthy.

Verification

  • RED check on upstream/main: revised regression tests failed before the production change:
    • test_conflict_retry_drops_pending_updates_and_preserves_callback
    • test_conflict_retry_schedules_heartbeat_probe_on_success
  • GREEN after fix:
    • /Users/evinova-self/.hermes/hermes-agent/venv/bin/python3 -m pytest tests/gateway/test_telegram_network_reconnect.py tests/gateway/test_telegram_conflict.py -v -o "addopts=" --tb=short
    • Result: 23 passed in 0.42s
  • Branch verified exactly one commit ahead of upstream/main: 0 1

Competitor analysis

Open PR #40744 changes drop_pending_updates only. It does not add the post-reconnect verification probe, has no focused regression tests, and includes an unrelated tools/lazy_deps.py change. This PR covers both reported recovery layers with focused tests and a smaller final diff.

Auto-published by Moonsong via Path B automated pipeline.

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround platform/telegram Telegram bot adapter comp/gateway Gateway runner, session dispatch, delivery labels Jun 6, 2026
@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades 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 has been superseded on current main by a stronger Telegram polling recovery path.

Evidence:

  • plugins/platforms/telegram/adapter.py:2035 now has the live _handle_polling_conflict() path in the plugin Telegram adapter. It stops/drains/restarts polling, resets the conflict counter on success, and reschedules failed retries instead of leaving the adapter alive-but-wedged.
  • plugins/platforms/telegram/adapter.py:1972 and plugins/platforms/telegram/adapter.py:2723 add and wire _disarm_ptb_retry_loop() so PTB's own getUpdates retry loop is stopped synchronously before Hermes schedules conflict recovery. That landed in f03823014b01b7b85a6777040e1bb02a68cf8877.
  • plugins/platforms/telegram/adapter.py:1866 adds pending-update wedge detection: if Telegram reports queued updates while Hermes believes polling is running, recovery re-enters the existing reconnect ladder. That landed in d5ba374c038a99db99e3036d938271e70a6930fd.
  • 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, specifically citing the conflict recovery state machine, heartbeat loop, and pending_update_count wedge detector.

The specific drop_pending_updates=True conflict-retry tweak from this PR was not adopted, but the reported failure mode it was fixing is covered by the newer mainline implementation. Thanks for the focused reproduction and tests; they lined up with the recovery hardening that landed.

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-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades 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.

[BUG] Telegram Gateway freezes after polling conflict recovery — passive routing stops working

3 participants