refactor(delegate): child_run dedupe — shared close/attach/detach/stop helpers, _defer_close_after_timeout, _build_tool_trace, _num; single _fabricated_entry

This commit is contained in:
Teknium
2026-09-02 16:37:47 -07:00
parent c1f8fd4e40
commit 4711e8105d
8 changed files with 18 additions and 27 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -32,17 +32,15 @@ def _num(value: Any, default: int = 0) -> int:
return int(value) if isinstance(value, (int, float)) else default
def _fabricated_entry(
idx: int, status: str, error: str, child: Any, duration: float = 0
) -> Dict[str, Any]:
"""Result entry for a child that raised / never finished / was abandoned."""
def _fabricated_entry(idx: int, status: str, error: str, child: Any) -> Dict[str, Any]:
"""Result entry for a child whose Future raised or never finished."""
return {
"task_index": idx,
"status": status,
"summary": None,
"error": error,
"api_calls": 0,
"duration_seconds": duration,
"duration_seconds": 0,
"_child_role": getattr(child, "_delegate_role", None),
}
@@ -650,19 +648,24 @@ def _handle_child_wait_failure(
if is_timeout and diagnostic_path:
_err += f" Diagnostic: {diagnostic_path}"
_error_entry = _fabricated_entry(task_index, status, _err, child, duration)
_error_entry.update(
exit_reason=status,
api_calls=child_api_calls,
timeout_seconds=child_timeout if is_timeout else None,
timed_out_after_seconds=duration if is_timeout else None,
timeout_phase=(
_error_entry = {
"task_index": task_index,
"status": status,
"summary": None,
"error": _err,
"exit_reason": status,
"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
),
diagnostic_path=diagnostic_path,
)
"_child_role": getattr(child, "_delegate_role", None),
"diagnostic_path": diagnostic_path,
}
_append_missed_steer(_error_entry, _late_pending_steer)
worktree.attach(_error_entry)
close_deferred = is_timeout and not child_future.done()

View File

@@ -13,6 +13,7 @@ from concurrent.futures import FIRST_COMPLETED, wait as _cf_wait
from typing import Any, Dict, List, Optional
from agent.interrupt_compat import request_hard_interrupt
from tools.delegate_tool_child_run import _fabricated_entry
from tools.delegate_tool_progress import (
SUBAGENT_FAILURE_STATUSES,
_clean_error_text,
@@ -24,19 +25,6 @@ from tools.delegate_tool_progress import (
logger = logging.getLogger("tools.delegate_tool")
def _fabricated_entry(idx: int, status: str, error: str, child: Any) -> Dict[str, Any]:
"""Result entry for a child whose Future raised or never finished."""
return {
"task_index": idx,
"status": status,
"summary": None,
"error": error,
"api_calls": 0,
"duration_seconds": 0,
"_child_role": getattr(child, "_delegate_role", None),
}
def _future_entry(future: Any, idx: int, child: Any) -> Dict[str, Any]:
"""The finished Future's entry, or a fabricated error entry if it raised."""
try: