Skip to content

fix(telegram): route conflict-retry start_polling failure into network reconnect ladder - #25285

Closed
shanewas wants to merge 2 commits into
NousResearch:mainfrom
shanewas:fix/telegram-conflict-retry-25221
Closed

fix(telegram): route conflict-retry start_polling failure into network reconnect ladder#25285
shanewas wants to merge 2 commits into
NousResearch:mainfrom
shanewas:fix/telegram-conflict-retry-25221

Conversation

@shanewas

Copy link
Copy Markdown

Summary

Fixes #25221 — Telegram gateway stays alive with dead polling after the conflict-retry start_polling call fails.

The Bug

In _handle_polling_conflict(), when the retry start_polling call (line 896) raises an exception, the handler only logged the error and returned silently — no reconnect was scheduled, no further retry was triggered. This left the gateway process alive but with dead Telegram polling, requiring a manual restart.

The Fix

The fix mirrors what _handle_polling_network_error already does for network failures (lines 814-823): when start_polling fails in the conflict-retry path, schedule a background task that calls _handle_polling_network_error(retry_err). This routes the failure through the exponential-backoff reconnect ladder so the adapter recovers automatically instead of going silent.

Changed file: gateway/platforms/telegram.py (lines 904-916)

except Exception as retry_err:
    logger.warning("[%s] Telegram polling retry failed: %s", self.name, retry_err)
    # start_polling failed — polling is dead and no further error
    # callbacks will fire, so schedule the network reconnect handler
    # ourselves, routing the retry failure through the exponential-
    # backoff reconnect ladder so the adapter doesn't go silent.
    if not self.has_fatal_error:
        task = asyncio.ensure_future(
            self._handle_polling_network_error(retry_err)
        )
        self._background_tasks.add(task)
        task.add_done_callback(self._background_tasks.discard)
    return

Tests

tests/gateway/test_telegram_polling_conflict_retry.py — 4 regression tests:

  • test_conflict_retry_start_polling_failure_schedules_network_reconnect — core fix validation
  • test_conflict_retry_start_polling_failure_does_not_set_fatal_immediately — confirms transient path
  • test_conflict_retry_start_polling_failure_leaves_adapter_alive — adapter stays running
  • test_successful_conflict_retry_resets_conflict_count — conflict count resets on success

All 4 pass. Run: pytest tests/gateway/test_telegram_polling_conflict_retry.py -v

…k reconnect ladder

Fixes #25221

When the retry start_polling() call inside _handle_polling_conflict()
raises, the exception was only logged before returning silently — no
reconnect was scheduled, leaving the gateway alive but with dead polling.

The fix mirrors _handle_polling_network_error (lines 814-823): schedule
a background task calling _handle_polling_network_error(retry_err) so
the failure is routed through the exponential-backoff reconnect ladder.

Tests: tests/gateway/test_telegram_polling_conflict_retry.py (4 tests)
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter labels May 13, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #25232. Both PRs apply the identical fix to gateway/platforms/telegram.py (route start_polling() failure in _handle_polling_conflict() into _handle_polling_network_error via asyncio.ensure_future). #25232 was opened first. This PR adds more test coverage in a separate test file which could be cherry-picked.

@shanewas

Copy link
Copy Markdown
Author

Closing as duplicate of #25232 (opened first, same fix). Will cherry-pick the test coverage from this PR into #25232.

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 P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram gateway can stay alive with dead polling after conflict retry start_polling failure

2 participants