# NousResearch/hermes-agent · Telegram gateway reconnect and shutdown reliability fixes

## Open now

- Nothing open on GitHub.

These issues and pull requests address bugs in the Telegram gateway around send_path_degraded not clearing after reconnect, network error recovery delegation, polling readiness timing, and missing user feedback during shutdown.

## TL;DR

- 4 member(s): 0 open issue(s), 1 closed issue(s), 0 open PR(s), 1 merged PR(s), 2 PR(s) closed without merging.
- A fix was merged to main in PR #54076. Verify it addresses your case.
- **Recommended:** read PR #54076 (and any competing PRs below) before filing. Confirm the merged change covers your symptom.

## Maintainer resolution verdict

- Internal-tracker verdict over this cluster's issue members: `resolved` · deciding PR(s): `pr-54076`. This is distinct from the fix status above. Weigh it yourself.

## How this cluster was grouped

- Link evidence (`STRUCTURAL_SPANNING`): every member is connected by structural evidence: shared changed files, or a closing/superseded reference.
- Pairwise link density `0.50`: the share of member pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36. `1.00` means every pair is linked.

## Closed / duplicate issues

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

## Prior & competing PRs

- **#54076: fix(telegram): clear send_path_degraded on successful reconnect (#35205)**. merged to main · fix tier `verified`
  - maintainer direction: category `merged`
  - files: `infographic/telegram-send-path-35205/infographic.png`, `plugins/platforms/telegram/adapter.py`, `tests/gateway/test_telegram_send_path_health.py`
  - fix hunks:
  - `plugins/platforms/telegram/adapter.py`

    ```diff
    @@ -1572,6 +1572,17 @@ async def _handle_polling_network_error(self, error: Exception) -> None:
                     self.name, attempt,
                 )
                 self._polling_network_error_count = 0
    +            # start_polling() succeeding IS the recovery signal: the long-poll
    +            # connection is live again, so clear the degraded flag immediately
    +            # rather than blocking all outbound sends for the full
    +            # HEARTBEAT_PROBE_DELAY window. The deferred probe below is a
    +            # defensive re-check — if it later detects a silent wedge (PTB
    +            # running=True but consumer task dead) it re-enters the ladder,
    +            # which re-sets _send_path_degraded. Without this clear here, a
    +            # clean reconnect leaves the flag stuck True until the 60s probe
    +            # (or forever, if the probe is never scheduled), blocking the send
    +            # path even though the bot has fully recovered. See #35205.
    +            self._send_path_degraded = False
                 # start_polling() returning is necessary but not sufficient:
                 # PTB's Updater can be left in a state where `running` is True
                 # but the underlying long-poll task is wedged on a stale httpx
    ```
  - `tests/gateway/test_telegram_send_path_health.py`

    ```diff
    @@ -66,24 +66,71 @@ async def test_send_short_circuits_when_path_degraded():
     
     @pytest.mark.asyncio
     async def test_reconnect_storm_sets_and_heartbeat_clears_flag(monkeypatch):
    -    """_handle_polling_network_error sets the flag; a successful heartbeat
    -    probe in _verify_polling_after_reconnect clears it."""
    +    """_handle_polling_network_error sets the flag while reconnecting; if the
    +    reconnect attempt itself raises (polling not yet healthy), the flag stays
    +    True until a later successful heartbeat probe in
    +    _verify_polling_after_reconnect clears it."""
         adapter = _make_adapter()
         adapter._app = MagicMock()
         adapter._app.updater = MagicMock()
         adapter._app.updater.running = True
         adapter._app.updater.stop = AsyncMock()
    -    adapter._app.updater.start_polling = AsyncMock()
    +    # First start_polling attempt fails — the reconnect handler must leave the
    +    # flag set (path still unhealthy) and not clear it prematurely.
    +    adapter._app.updater.start_polling = AsyncMock(side_effect=OSError("still down"))
         adapter._app.bot = MagicMock()
         adapter._app.bot.get_me = AsyncMock(return_value=MagicMock())
         adapter._polling_error_callback_ref = AsyncMock()
         monkeypatch.setattr(
             "plugins.platforms.telegram.adapter.Update", MagicMock(ALL_TYPES=[])
         )
    +    # Suppress the self-rescheduled retry so the test doesn't recurse.
    +    monkeypatch.setattr(
    +        "plugins.platforms.telegram.adapter.asyncio.ensure_future", MagicMock()
    +    )
     
    -    await adapter._handle_polling_network_error(OSError("Bad Gateway"))
    +    with patch("plugins.platforms.telegram.adapter.asyncio.sleep", new_callable=AsyncMock):
    +        await adapter._handle_polling_network_error(OSError("Bad Gateway"))
    +    # start_polling failed → path still degraded.
         assert adapter._send_path_degraded is True
     
    +    # Now the deferred probe runs against a recovered (running) updater and
    +    # a responsive bot — it clears the flag.
    +    adapter._app.updater.running = True
         with patch("plugins.platforms.telegram.adapter.asyncio.sleep", new_callable=AsyncMock):
             await adapter._verify_polling_after_reconnect()
         assert adapter._send_path_degraded is False
    +
    +
    [redacted:email]
    +async def test_successful_reconnect_clears_flag_without_probe(monkeypatch):
    +    """Regression for #35205: a successful start_polling() clears
    +    _send_path_degraded immediately, so outbound sends are not blocked for
    +    the full HEARTBEAT_PROBE_DELAY window (and never get stuck True if the
    +    deferred probe is never scheduled / never runs)."""
    +    adapter = _make_adapter()
    +    adapter._app = MagicMock()
    +    adapter._app.updater = MagicMock()
    +    adapter._app.updater.running = True
    +    adapter._app.updater.stop = AsyncMock()
    +    adapter._app.updater.start_polling = AsyncMock()
    +    adapter._app.bot = MagicMock()
    +    adapter._app.bot.get_me = AsyncMock(return_value=MagicMock())
    +    adapter._polling_error_callback_ref = AsyncMock()
    +    monkeypatch.setattr(
    +        "plugins.platforms.telegram.adapter.Update", MagicMock(ALL_TYPES=[])
    +    )
    +    # Don't let the deferred probe run — prove the clear happens in the
    +    # reconnect handler itself, not in _verify_polling_after_reconnect.
    +    monkeypatch.setattr(
    +        adapter, "_verify_polling_after_reconnect", AsyncMock()
    +    )
    +
    +    with patch("plugins.platforms.telegram.adapter.asyncio.sleep", new_callable=AsyncMock):
    +        await adapter._handle_polling_network_error(OSError("Bad Gateway"))
    +
    +    assert adapter._send_path_degraded is False
    +    assert adapter._polling_network_error_count == 0
    +    # And send() works again right away.
    +    result = await adapter.send("123", "hello")
    +    assert result.success is True
    ```
- **#35285: fix(telegram): clear send_path_degraded immediately on successful reconnect**. closed without merge
  - maintainer direction: category `implemented_elsewhere`; implication `superseded`; refs `2ecb6f7fe60f6a240d632bbd51bcbb25ad22c161`, `#35205`, `#54076`
- **#35286: fix(telegram): clear send_path_degraded immediately on successful reconnect**. closed without merge
  - maintainer direction: category `implemented_elsewhere`; implication `superseded`; refs `2ecb6f7fe60f6a240d632bbd51bcbb25ad22c161`, `#35205`, `#54076`

## Fix status

- Merged to main in PR #54076 (cited above). No release data is tracked. Verify downstream.
- Fix last verified (merged) `2026-06-28`.
- Subsystem: `gateway`
