From 98fe6d0a8e36220801ada098a0598139e7129222 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Sun, 26 Jul 2026 22:43:48 -0700 Subject: [PATCH] fix(delegation): integrate lifecycle refactor with tool-history + daemon pool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-ups on the salvaged #63359: - _finalize_child_results carries tool_call_history on subagent_stop (the #62011/#72403 field landed after the PR branched; the shared pipeline must emit it for both delegate_task and plugin-launched children). Lifecycle test updated for the new payload field. - The lifecycle executor uses DaemonThreadPoolExecutor — a wedged or abandoned child must never block interpreter exit at atexit-join time (same rationale as _run_single_child's timeout executor and the async-delegation pool). - delegate_task's batch path keeps live-transcript wiring while routing child construction through the shared _build_child_preserving_parent_tools helper. --- agent/subagent_lifecycle.py | 7 ++++++- tests/agent/test_subagent_lifecycle.py | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/agent/subagent_lifecycle.py b/agent/subagent_lifecycle.py index 63603675bc..b85d84d9e1 100644 --- a/agent/subagent_lifecycle.py +++ b/agent/subagent_lifecycle.py @@ -156,7 +156,12 @@ class _Registry: _REGISTRY = _Registry() -_EXECUTOR = ThreadPoolExecutor(max_workers=8, thread_name_prefix="hermes-lifecycle") +# Daemon worker pool: a wedged/abandoned child must never block interpreter +# exit at atexit-join time (same rationale as _run_single_child's timeout +# executor and the async-delegation registry pool). +from tools.daemon_pool import DaemonThreadPoolExecutor as _DaemonExecutor + +_EXECUTOR = _DaemonExecutor(max_workers=8, thread_name_prefix="hermes-lifecycle") _SECRET = secrets.token_bytes(32) _ACTIVE_PARENT_AGENT: contextvars.ContextVar[Any] = contextvars.ContextVar( "hermes_subagent_lifecycle_parent", default=None diff --git a/tests/agent/test_subagent_lifecycle.py b/tests/agent/test_subagent_lifecycle.py index faa3ddabbf..38fd62d93a 100644 --- a/tests/agent/test_subagent_lifecycle.py +++ b/tests/agent/test_subagent_lifecycle.py @@ -202,6 +202,10 @@ def test_public_lifecycle_runs_host_aggregation(monkeypatch): child_role="leaf", child_summary="aggregated", child_status="completed", + # Redacted tool history rides the shared finalization pipeline + # (#62011/#72403); empty here because the fabricated result carries + # no tool_trace. + tool_call_history=[], duration_ms=250, ) assert parent.session_estimated_cost_usd == 3.5