refactor(telegram): migrate the thread-deadline primitive onto agent.deadline.run_bounded_async (#85125 2f) - #93826
Merged
kshitijk4poor merged 1 commit intoAug 24, 2026
Conversation
…adline.run_bounded_async (NousResearch#85125 2f) The adapter's private thread-deadline helper was the ancestor of the unified deadline layer's run_bounded_async (NousResearch#85147 was extracted from it, plus the caller-cancellation leak fix the original still lacked). Consolidate: the helper body becomes a thin wrapper mapping BoundedResult.timed_out back to the asyncio.TimeoutError its 9 call sites (the PTB retry ladder) expect. ~90 duplicated lines die, along with the adapter-local copies of the abandon-cleanup runner and the blocked-loop faulthandler diagnostics (both live in agent/deadline.py). Everything the call sites rely on is preserved by the unified layer: - thread-timer deadline that survives a blocked event loop (NousResearch#63309) - abandonment of cancellation-shielded tasks (PTB/httpcore anyio init) - detached best-effort on_abandon cleanup (no httpx pool leak per retry) - off-loop stack dump when the loop never processes the expiry Plus one behavior IMPROVEMENT inherited from the shared copy: a caller cancelling the wrapper no longer leaks the inner task unobserved (the telegram original had that leak; the extraction fixed it). test_telegram_init_deadline.py: the NousResearch#63309 diagnostics probe now pins the shared layer's dump hook (label "telegram-init") — same contract, new seam. Wedge + cleanup-crash tests pass unchanged.
kshitijk4poor
enabled auto-merge
August 24, 2026 11:37
Closed
1 task
prmartinow
pushed a commit
to prmartinow/hermes-agent
that referenced
this pull request
Aug 26, 2026
…-telegram-deadline-migration refactor(telegram): migrate the thread-deadline primitive onto agent.deadline.run_bounded_async (NousResearch#85125 2f)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#85125 Phase 2f. The Telegram adapter's private
_await_with_thread_deadlinewas the strongest deadline primitive in the tree — and the direct ancestor ofagent.deadline.run_bounded_async(#85147 extracted it, adding the caller-cancellation leak fix the original never got). This migrates the adapter onto the shared primitive: the helper body becomes a thin wrapper mappingBoundedResult.timed_outback to theasyncio.TimeoutErrorits 9 call sites (the PTB retry ladder) expect. ~90 duplicated lines deleted, along with the adapter-local abandon-cleanup runner and blocked-loop faulthandler diagnostics (both owned byagent/deadline.pynow).Preserved by construction (the shared layer implements all of it):
on_abandoncleanup — no httpx pool leak per retry attemptOne inherited behavior improvement: a caller cancelling the wrapper no longer leaks the inner task unobserved (the telegram original had that leak; the shared copy fixed it at extraction).
Verification
tests/gateway/test_telegram_init_deadline.py(the Telegram gateway hangs at 'Connecting to Telegram (attempt 1/8)' after upgrade; network is reachable #63309 pin suite): 3 passed × 3 runs. The blocked-loop diagnostics probe now pins the shared layer's dump hook (labeltelegram-init) — same contract, new seam; the wedge and cleanup-crash tests pass unchanged.Part of #85125 (Phase 2f).