Skip to content

refactor(telegram): migrate the thread-deadline primitive onto agent.deadline.run_bounded_async (#85125 2f) - #93826

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/85125-2f-telegram-deadline-migration
Aug 24, 2026
Merged

refactor(telegram): migrate the thread-deadline primitive onto agent.deadline.run_bounded_async (#85125 2f)#93826
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/85125-2f-telegram-deadline-migration

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

#85125 Phase 2f. The Telegram adapter's private _await_with_thread_deadline was the strongest deadline primitive in the tree — and the direct ancestor of agent.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 mapping BoundedResult.timed_out back to the asyncio.TimeoutError its 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 by agent/deadline.py now).

Preserved by construction (the shared layer implements all of it):

One 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

Part of #85125 (Phase 2f).

…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
kshitijk4poor merged commit e400e00 into NousResearch:main Aug 24, 2026
35 checks passed
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins platform/telegram Telegram bot adapter labels Aug 24, 2026
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)
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 P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants