fix: async subagent background=True drops user interrupts to queue (#46864) - #46950
Closed
argus-metis wants to merge 2 commits into
Closed
fix: async subagent background=True drops user interrupts to queue (#46864)#46950argus-metis wants to merge 2 commits into
argus-metis wants to merge 2 commits into
Conversation
…ousResearch#46864) Root cause: _dispatch_delegate_task in run_agent.py silently dropped the 'background' parameter, so delegate_task(background=True) never received the flag. The downstream delegate_task() has full async background support (removes child from _active_children, dispatches via async_delegation) but never knew the caller requested it. Additionally: - _build_child_agent unconditionally registered ALL children in _active_children, creating a race where background children were briefly visible before the caller removed them. Registration is now done by the sync caller only. - The gateway's _agent_has_active_subagents() gains a defense-in-depth _executing_tools check so even if a background child is somehow in _active_children, it won't demote user interrupts when the parent's tool loop has already returned.
Contributor
|
Thanks for tracing the original background-delegation failure path. This is an automated hermes-sweeper review; current
|
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.
Summary
Fixes #46864 —
delegate_task(background=True)silently blocked user messages by dropping them toqueuemode instead of allowing interrupts.Root Cause
Three interacting issues:
run_agent.py—_dispatch_delegate_task()didn't pass thebackgroundparameter through todelegate_task(). The downstream function has full async support (removes child from_active_children, dispatches viaasync_delegation) but never received the flag.tools/delegate_tool.py—_build_child_agent()unconditionally registered ALL children inparent_agent._active_childrenfor interrupt propagation. For background children, this created a race window where the child appeared briefly before the async path removed it — causing_agent_has_active_subagents()to see a non-empty list and demote user interrupts to queue.gateway/run.py—_agent_has_active_subagents()had no way to distinguish background children (async, parent's tool loop has returned) from sync children (parent blocked mid-tool-loop). Both looked identical: non-empty_active_children.Changes
run_agent.py(+1 line)Pass
backgroundfrom function args through_dispatch_delegate_task()todelegate_task().tools/delegate_tool.py(+41/-8)_build_child_agent()and into the sync-only call sites (delegate_task()single and batch branches).gateway/run.py(+15 lines)_executing_toolscheck: when the parent's tool loop has returned and_executing_toolsis False, any remaining_active_childrenmust be background subagents. The gateway does NOT demote user interrupts to queue.getattr(..., True)so attribute-missing stubs preserve the existing interrupt path.Tests (+17 lines)
test_returns_false_when_parent_not_executing_tools: Background children with_executing_tools=Falsemust NOT trigger demotion.test_returns_false_when_executing_tools_attr_missing: Missing attribute defaults to True (backward compat).Background
Builds on the async background delegation infrastructure from #40946 (
feat(delegation): async background subagents via delegate_task(background=true)).Checklist
fix:commit follows conventional commit format