Skip to content

fix(gateway): guard NoneType in Telegram reconnect after network error (#55992) - #120

Open
hashbender wants to merge 1 commit into
mainfrom
mirror/pr-56028
Open

fix(gateway): guard NoneType in Telegram reconnect after network error (#55992)#120
hashbender wants to merge 1 commit into
mainfrom
mirror/pr-56028

Conversation

@hashbender

Copy link
Copy Markdown
Owner

Problem

After sustained network errors, the Telegram adapter's _handle_polling_network_error reconnect handler sleeps with exponential backoff (5s–60s) before calling start_polling(). During that sleep window the supervisor may tear down the adapter — disconnect() sets self._app = None (line 3028).

The existing stop() call at line 1777 was already guarded:

if self._app and self._app.updater and self._app.updater.running:
    await self._app.updater.stop()

But start_polling() at line 1785 was not guarded:

await self._app.updater.start_polling(...)  # AttributeError if self._app is None

This crashes with 'NoneType' object has no attribute 'updater', silently killing the reconnect loop. The gateway process stays alive (state file says "running" + "connected") but never processes another Telegram message.

Fix

Add a None guard for both self._app and self._app.updater before the start_polling() call, matching the pattern already used for stop(). If the app was destroyed during the reconnect delay, log a warning and abort cleanly.

Reproduction

  1. Gateway happily polling Telegram
  2. Network hiccup — httpx.ConnectError multiple times
  3. After 10 consecutive failures, adapter enters reconnect loop
  4. During the backoff sleep, supervisor restarts the adapter (self._app = None)
  5. Reconnect handler wakes up and crashes on self._app.updater.start_polling()
  6. Gateway appears healthy (state file says "running") but is completely silent

Testing

  • python3 -m py_compile plugins/platforms/telegram/adapter.py — syntax OK
  • Verified the guard pattern matches the existing stop() guard at line 1777

Fixes NousResearch#55992


Mirror-of: NousResearch#56028
NousResearch#56028

@tenki-reviewer

tenki-reviewer Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Complete
No issues found!

Risk: 🟢 Low (12/100) — no findings · 12 LOC across 1 file


Single-file PR modifies the Telegram adapter's reconnection logic in plugins/platforms/telegram/adapter.py. The change replaces direct _app.stop() calls with a supervised stop sequence and adds a fatal error escalation path. No findings meet the confidence threshold.

Files Reviewed (1 files)
plugins/platforms/telegram/adapter.py

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram polling silently dies after network error + self-restart

1 participant