Bound direct subagent waits#311
Open
ritamgh wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds a configurable timeout to subagent execution so that long-running calls fail fast with a guidance-rich, recoverable error message.
Changes:
- Introduced
timeout_secsinSubagentInputand exposed it in the tool JSON schema. - Wrapped subagent execution in
tokio::time::timeout, returning a specific timeout message on expiry. - Added a helper to format timeout errors and a unit test validating the message contents.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+232
to
+258
| let final_text = match tokio::time::timeout( | ||
| Duration::from_secs(timeout_secs), | ||
| agent.run_once_capture(¶ms.prompt), | ||
| ) | ||
| .await | ||
| { | ||
| Ok(result) => result.map_err(|err| { | ||
| logging::warn(&format!( | ||
| "[tool:subagent] subagent failed description={} type={} session_id={} model={} error={}", | ||
| params.description, | ||
| params.subagent_type, | ||
| sub_session_id, | ||
| resolved_model, | ||
| err | ||
| )); | ||
| err | ||
| })?, | ||
| Err(_) => { | ||
| listener.abort(); | ||
| let message = subagent_timeout_error(¶ms.description, &sub_session_id, timeout_secs); | ||
| logging::warn(&format!( | ||
| "[tool:subagent] {} type={} model={}", | ||
| message, params.subagent_type, resolved_model | ||
| )); | ||
| return Err(anyhow::anyhow!(message)); | ||
| } | ||
| }; |
Author
There was a problem hiding this comment.
Good point. The goal of this PR is to bound the parent agent’s direct wait and return the child session_id for recovery. Dropping the future is sufficient for that wait-bound behavior here. A harder JoinHandle::abort/cleanup path would be a larger follow-up if we find subagent work continues past cancellation.
6f9ca6d to
a7a74f0
Compare
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
Direct
subagenttool calls could block the parent agent indefinitely when the child session never produced a final captured answer. This adds a bounded wait with a recoverable timeout.Changes
timeout_secsto thesubagenttool schema.swarmfor durable long-running work.Validation
Result: 7 passed.