fix(delegation): timeout stuck async child runners (rebased from #60234)#71096
Open
DavidMetcalfe wants to merge 1 commit into
Open
fix(delegation): timeout stuck async child runners (rebased from #60234)#71096DavidMetcalfe wants to merge 1 commit into
DavidMetcalfe wants to merge 1 commit into
Conversation
Async background delegation can leave gateway sessions holding only a dispatched handle when the detached runner wedges before it can return and enqueue a completion. Enforce the configured child timeout in the async registry so the parent observes a terminal timeout event and the async slot is released. Constraint: Issue NousResearch#60203 reports long-lived gateway processes with background child delegates that never produce completion events despite child_timeout_seconds being configured. Rejected: Relying only on _run_single_child timeout handling | it cannot finalize the async registry when the outer runner thread itself never reaches normal completion. Confidence: high Scope-risk: narrow Directive: Keep background delegation completion owned by the async registry whenever detached workers can outlive the caller's immediate control. Tested: .venv/bin/python -m pytest tests/tools/test_async_delegation.py tests/tools/test_delegate_subagent_timeout_diagnostic.py tests/tools/test_delegate.py -q Tested: .venv/bin/python -m ruff check tools/async_delegation.py tools/delegate_tool.py tests/tools/test_async_delegation.py Tested: git diff --check Not-tested: Multi-day real gateway degradation; covered with deterministic stuck-runner registry tests.
This was referenced Jul 25, 2026
Collaborator
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.
What does this PR do?
Fixes a stuck lifecycle path for
delegate_task(background=true): if the detached async delegation runner wedges before it returns and enqueues a completion event, gateway sessions can keep seeing only the original dispatched handle while the async slot remains occupied.This PR makes the async delegation registry enforce the existing
delegation.child_timeout_secondssetting for detached runners. When a still-running async delegation exceeds that timeout, the registry now emits one terminaltimeoutcompletion event, releases the async slot, drops the interrupt closure, and best-effort interrupts the detached child. Late worker returns are ignored so the parent cannot receive duplicate completion events.This is a rebase of @izumi0uu's PR #60234 onto current
main(commit5a3e153cherry-picked with authorship preserved). The original PR passed all CI checks and cross-vendor review (Gemini 3.6 Flash + GPT-OSS) but had merge conflicts with upstream changes. This rebase resolves those conflicts and preserves the full fix.Related Issue
Fixes #60203
Type of Change
Changes Made
tools/async_delegation.py: add per-dispatch timeout watchdogs for single and batch async delegations.tools/async_delegation.py: refactor_finalizeinto_begin_finalization+_push_completion_event+_finish_finalizationfor atomic running→finalizing transitions that both worker and watchdog paths share.tools/async_delegation.py: make normal finalizers no-op after timeout/interruption so a late runner cannot enqueue a second completion event.tools/delegate_tool.py: pass the configured child timeout into the background async registry path.tests/tools/test_async_delegation.py: cover stuck single runners, stuck batch runners, timeout durability through persistence block, process restart recovery, and the delegate-tool timeout handoff.How to Test
Merge conflicts resolved
tools/async_delegation.py:dispatch_async_delegation_batchgaineddelegation_idparam upstream; kept bothdelegation_idandtimeout_seconds.tools/delegate_tool.py: upstream addeddelegation_id=live_deleg_idkwarg; kept both kwargs.Review
delegate_tool._run_single_child, not introduced by this PR.Notes
Open question: The reporter's signature (multi-day gateway uptime, all-provider hang at first API call) differs from issue #61778 (mid-session Codex-specific 0-event hang). This PR addresses the delegation lifecycle gap (child_timeout_seconds not enforced for background runners) which covers the #60203 symptom regardless of which specific provider/event-loop degradation caused the runner to wedge. The root cause of the per-thread event-loop degradation in long-lived daemon threads remains uninvestigated and may warrant a separate diagnostic issue.