Bound direct subagent waits#311
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.
| 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)); | ||
| } | ||
| }; |
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
|
Thanks! This repo no longer accepts external PRs, but the underlying problem is real - it's now tracked in #365 (with credit to this PR). Closing. |
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.