feat: add subagent timeout and parent-child isolation - #26630
Conversation
|
Related: #13770 (merged — hard timeout + stale detection for subagents). This PR adds a new |
|
Thanks @alt-glitch! Acknowledged — #13770 (by iamagenius00) already added the hard timeout + stale detection inline in _run_single_child(). This PR doesn't duplicate that; it extracts a reusable wrap_child_execution() wrapper with:
A natural follow-up would be to refactor _run_single_child()'s inline timeout logic to use wrap_child_execution(), replacing ~40 lines of inline ThreadPoolExecutor code with a single call. Happy to do that in a separate PR if the direction seems right. |
|
Thanks for the focused timeout/error-model proposal. The current patch does not yet affect live delegation. Problems
Suggested changes
Automated hermes-sweeper review. |
e4fa8c2 to
96810ce
Compare
|
@teknium1 Addressed all three review points:
|
96810ce to
9c811cf
Compare
What does this PR do?
Adds structured timeout enforcement and crash isolation for subagent delegation. Currently, child agent exceptions can propagate to the parent, and there's no structured error type system for delegation failures.
wrap_child_execution()— Hard timeout per child viaThreadPoolExecutor. Catches ALL exceptions (except KeyboardInterrupt/SystemExit). Never crashes the parent. Returns structuredChildResulton success, timeout, or crash.ChildResultdataclass — Structured result withsuccess,status,error,error_type,api_calls,duration_seconds,child_role,resultfields..to_dict()and.to_json()serialization.ChildErrorTypeenum — Typed error taxonomy:timeout,crash,interrupted,internal_error,depth_limit,paused. Enables programmatic error handling by callers.format_child_error()— User-facing error messages with actionable config suggestions ("Increase delegation.child_timeout_seconds in config.yaml").KeyboardInterruptandSystemExitare always re-raised, never swallowed. Executor shutdown infinallyblock.Changes Made
tools/child_isolation.py— 155 lines:wrap_child_execution(),ChildResult,ChildErrorType,format_child_error()tests/tools/test_child_isolation.py— 10 tests covering success, timeout, crash (RuntimeError + ValueError), result serialization, error formattingHow to Test
from tools.child_isolation import wrap_child_execution; r = wrap_child_execution(0, lambda: {"status": "ok"}, 30.0)r = wrap_child_execution(0, lambda: __import__("time").sleep(10), 0.1)— verify timeoutr = wrap_child_execution(0, lambda: 1/0, 30.0)— verify crash isolation (parent unaffected)pytest tests/tools/test_child_isolation.py -v— 10 tests passChecklist