Skip to content

fix(telegram): clear send_path_degraded immediately on successful reconnect - #35286

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/telegram-send-path-degraded-after-reconnect
Closed

fix(telegram): clear send_path_degraded immediately on successful reconnect#35286
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/telegram-send-path-degraded-after-reconnect

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Clears _send_path_degraded immediately after a successful start_polling() reconnect, instead of deferring it to the 60-second heartbeat probe. This prevents all outbound send() calls from being blocked for 60 seconds after the Telegram gateway recovers from a network interruption.

Related Issue

Fixes #35205

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/platforms/telegram.py: Clear _send_path_degraded = False immediately after successful start_polling() in _handle_polling_network_error(), alongside the existing _polling_network_error_count = 0 reset. Added comment explaining the rationale.
  • tests/gateway/test_telegram_send_path_health.py: Updated test_reconnect_storm_sets_and_heartbeat_clears_flagtest_reconnect_clears_degraded_flag_on_successful_start_polling to verify the flag is cleared immediately. Added test_degraded_flag_stays_true_when_start_polling_fails to verify the flag remains True when reconnect fails (negative case).

How to Test

  1. Run pytest tests/gateway/test_telegram_send_path_health.py -v — all 4 tests should pass
  2. Run pytest tests/gateway/test_telegram_network_reconnect.py -v — all 15 tests should pass (no regressions)
  3. Manual: trigger a Telegram network error (e.g., disconnect WiFi), reconnect, and verify outbound messages are delivered immediately without the 60-second delay

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Code Intelligence

  • Analyzed: gateway/platforms/telegram.py TelegramAdapter._handle_polling_network_error (called by polling error callback, triggers reconnect ladder)
  • Blast radius: LOW — single flag reset in a well-isolated error recovery path; send() retry logic handles stale pool case
  • Related patterns: _verify_polling_after_reconnect() heartbeat probe still runs as secondary safety net; _drain_polling_connections() resets polling pool but not general request pool (documented limitation)

…onnect

After a network error, _send_path_degraded was only cleared by the
60-second heartbeat probe in _verify_polling_after_reconnect(). During
that window, all outbound send() calls short-circuited as failures,
even though polling had already resumed successfully.

Clear the flag immediately after start_polling() succeeds. If the
send-side httpx pool is also stale, send()'s own retry and
error_callback will re-enter the reconnect ladder.

Fixes NousResearch#35205
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter labels May 30, 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 fix is already implemented on current main.

Evidence:

Thanks for the original fix and tests here — the same behavior has since landed on main, so this PR is redundant now.

@teknium1 teknium1 closed this Jun 29, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 29, 2026
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.

Telegram gateway: send_path_degraded stays true after successful reconnect, blocking all outbound messages

3 participants