Skip to content

The agent that grows with you

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

Teknium4711e8105d84
diff --git a/MagicMock/mock._session_db.db_path/139369483040144 b/MagicMock/mock._session_db.db_path/139369483040144
new file mode 100644
index 00000000000..522c23eb0dd
Binary files /dev/null and b/MagicMock/mock._session_db.db_path/139369483040144 differ
diff --git a/MagicMock/mock._session_db.db_path/139369483040144.fts_rebuild.lock b/MagicMock/mock._session_db.db_path/139369483040144.fts_rebuild.lock
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/MagicMock/mock._session_db.db_path/139369483040144.quarantine.lock b/MagicMock/mock._session_db.db_path/139369483040144.quarantine.lock
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/MagicMock/mock._session_db.db_path/139369502342928 b/MagicMock/mock._session_db.db_path/139369502342928
new file mode 100644
index 00000000000..79ef2806e07
Binary files /dev/null and b/MagicMock/mock._session_db.db_path/139369502342928 differ
diff --git a/MagicMock/mock._session_db.db_path/139369502342928.fts_rebuild.lock b/MagicMock/mock._session_db.db_path/139369502342928.fts_rebuild.lock
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/MagicMock/mock._session_db.db_path/139369502342928.quarantine.lock b/MagicMock/mock._session_db.db_path/139369502342928.quarantine.lock
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tools/delegate_tool_child_run.py b/tools/delegate_tool_child_run.py
index a7d0030186b..ca9e2307dc5 100644
--- a/tools/delegate_tool_child_run.py
+++ b/tools/delegate_tool_child_run.py
@@ -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()
diff --git a/tools/delegate_tool_dispatch.py b/tools/delegate_tool_dispatch.py
index ef8a3c4edf1..0aa6b738f7f 100644
--- a/tools/delegate_tool_dispatch.py
+++ b/tools/delegate_tool_dispatch.py
@@ -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: