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.
This commit is contained in:
mahdiwafy 2026-07-07 23:48:15 +07:00 committed by Teknium
parent 2b38d5ad59
commit 8e163852d8

View file

@ -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,
}