From 8e163852d8939cf21fa145c5b1b800776ffb8b46 Mon Sep 17 00:00:00 2001 From: mahdiwafy Date: Tue, 7 Jul 2026 23:48:15 +0700 Subject: [PATCH] fix(delegate): include explicit timeout metadata in subagent results Add timeout_seconds, timed_out_after_seconds, and timeout_phase to timeout results so parent agents and users can distinguish timeouts before the first LLM call from timeouts after one or more API calls. Also attach diagnostic_path to the N>0 API-call timeout error message, matching the existing zero-API-call timeout path. Addresses part of #51690 and #17308. --- tools/delegate_tool.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/delegate_tool.py b/tools/delegate_tool.py index 67963b2cecc..50f58c1a0d2 100644 --- a/tools/delegate_tool.py +++ b/tools/delegate_tool.py @@ -2094,8 +2094,11 @@ def _run_single_child( _err = ( f"Subagent timed out after {child_timeout}s with " f"{child_api_calls} API call(s) completed — likely " - f"stuck on a slow API call or unresponsive network request." + f"stuck on a slow API call, tool call, or unresponsive " + f"network request." ) + if diagnostic_path: + _err += f" Diagnostic: {diagnostic_path}" else: _err = str(_timeout_exc) @@ -2107,6 +2110,13 @@ def _run_single_child( "exit_reason": "timeout" if is_timeout else "error", "api_calls": child_api_calls, "duration_seconds": duration, + "timeout_seconds": child_timeout if is_timeout else None, + "timed_out_after_seconds": duration if is_timeout else None, + "timeout_phase": ( + "before_first_llm_call" if is_timeout and child_api_calls == 0 + else "after_llm_calls" if is_timeout + else None + ), "_child_role": getattr(child, "_delegate_role", None), "diagnostic_path": diagnostic_path, }