Skip to content

fix(telegram): diagnose blocked-loop init hangs, unbind DoH discovery from system DNS - #64370

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/63345-salvage
Jul 14, 2026
Merged

fix(telegram): diagnose blocked-loop init hangs, unbind DoH discovery from system DNS#64370
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/63345-salvage

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Salvage of #63345 (CI blocked for first-time contributor). Addresses #63309 — gateway stuck at "Connecting to Telegram (attempt 1/8)..." for 9+ minutes with no retry line, no timeout message, process alive.

Changes

  • Loop-blocked watchdog in _await_with_thread_deadline: a second daemon timer fires 5s after the deadline. If the loop still hasn't processed the expiry callback, the watchdog (running on its own thread) logs a WARNING and calls faulthandler.dump_traceback(all_threads=True). A threading.Event closes the Timer.cancel() race.
  • discover_fallback_ips no longer gated by the system resolver: the system-DNS leg (bare socket.getaddrinfo with no timeout) is awaited best-effort with a _DOH_TIMEOUT cap instead of blocking startup indefinitely.

Attribution

Cherry-picked from @jbbottoms's #63345 with authorship preserved.

Validation

58 passed (telegram init deadline + telegram network). ruff + py_compile clean.

…em DNS

The NousResearch#63309 hang class — gateway stuck at 'Connecting to Telegram
(attempt 1/8)' with no retry, no timeout, for minutes — can only occur
when the event loop thread itself is blocked in a synchronous call:
_await_with_thread_deadline's timer fires off-loop, but its expiry
hand-off (call_soon_threadsafe) still needs the loop to run, and the
gateway's outer wait_for is a pure loop timer. When the loop is pinned,
every layer goes silent simultaneously and the process wedges with no
evidence of where.

Two changes:

1. Loop-blocked watchdog in _await_with_thread_deadline: a second
   daemon timer fires one grace period (5s) after the deadline; if the
   loop still hasn't processed the expiry, it logs a WARNING from the
   timer thread and faulthandler-dumps all thread stacks to stderr —
   converting the silent hang into a trace that names the exact
   blocking frame. A threading.Event set by the expiry callback (and on
   normal exit) keeps completed awaits from ever being misreported.

2. discover_fallback_ips: the system-resolver leg runs
   socket.getaddrinfo in a worker thread with no timeout, and
   asyncio.gather waited on it unboundedly — a wedged OS resolver
   stalled discovery for minutes between the two startup log lines. Its
   result only feeds a log message, so it no longer gates discovery:
   DoH legs (already client-bounded) are gathered alone and the system
   leg is awaited with a _DOH_TIMEOUT cap, best-effort.

Refs NousResearch#63309

Tests: 3 watchdog regressions (blocked-loop dump fires; responsive-loop
timeout does not; completed await does not) + 2 hung-resolver
regressions (DoH results returned promptly; worst-case seed fallback
stays bounded).
@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) July 14, 2026 11:39
@kshitijk4poor
kshitijk4poor merged commit e16743b into NousResearch:main Jul 14, 2026
31 checks passed
@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins platform/telegram Telegram bot adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages P1 High — major feature broken, no workaround labels Jul 14, 2026
@kshitijk4poor
kshitijk4poor deleted the fix/63345-salvage branch August 5, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P1 High — major feature broken, no workaround platform/telegram Telegram bot adapter 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.

3 participants