Agent Zero AI framework
Preserve streamed child log content in parallel jobs
linklitifb8d771802ed
diff --git a/helpers/parallel_tools.py b/helpers/parallel_tools.pyindex ebb8e8315..b2eb67a32 100644--- a/helpers/parallel_tools.py+++ b/helpers/parallel_tools.py@@ -711,8 +711,8 @@ def _log_parallel_child_started(agent: "Agent", job: ParallelJob) -> None:def _update_parallel_child_log(job: ParallelJob) -> None:- if not job.log_item:- return+ if not job.log_item or job.log_item.content:+ return # streamed or tool-written content is user-visible; never replace itif job.state == "success":content = job.result if job.result else "(completed without textual output)"else:diff --git a/helpers/parallel_tools.py.dox.md b/helpers/parallel_tools.py.dox.mdindex 924c81025..b96778478 100644--- a/helpers/parallel_tools.py.dox.md+++ b/helpers/parallel_tools.py.dox.md@@ -36,6 +36,7 @@- Direct tool background context cleanup removes both the in-memory context and any transient chat folder left on disk.- Parent-visible child log items are created for each wrapped call so the WebUI can inspect concurrent children separately while the wrapper result remains model-history-only.- Child tool logs mirror normal tool-call visible args; job ids remain available through wrapper results and prompt extras rather than visible process-step args.+- Job completion fills child log content only when it is still empty; streamed or tool-written content is user-visible state and is never replaced by the job result or error string.- Wrapped tool child logs use each tool's native `get_log_object()` output when available, preserving special log rendering (for example: `code_execution_tool` uses `code_exe`, `wait` uses `progress`, MCP tools use `mcp`, and regular tools use `tool`).- Direct parallel worker execution reuses the parent-visible child log item so tool `before_execution()` cannot create a second generic worker log or lose the native badge type.- Direct tools may explicitly queue model-visible history for their parent. Terminal collection records the outer `parallel` result first, promotes queued messages in job order, and only then removes disposable worker state; background jobs retain queued history until they are collected.diff --git a/tests/test_parallel_tool.py b/tests/test_parallel_tool.pyindex 3a5c89ee1..f7ab7d6c7 100644--- a/tests/test_parallel_tool.py+++ b/tests/test_parallel_tool.py@@ -840,6 +840,30 @@ async def test_parallel_direct_tool_jobs_fallback_to_generic_tool_log_type(monkeassert agent.context.log.items[0].kvps == {"seconds": 1, "_tool_name": "wait"}+def test_parallel_child_log_keeps_streamed_user_content() -> None:+ agent = _FakeAgent()+ job = parallel_tools.ParallelJob(+ id="job-streamed",+ parent_context_id=agent.context.id,+ index=0,+ tool_name="code_execution_tool",+ tool_args={},+ kind="tool",+ )+ job.log_item = agent.context.log.log(+ type="code_exe",+ heading="icon://terminal code_execution_tool - terminal",+ content="streamed output visible to user",+ kvps={},+ )++ parallel_tools._finish_job(job, "success", result="agent-view result")+ assert job.log_item.content == "streamed output visible to user"++ parallel_tools._finish_job(job, "error", error="boom")+ assert job.log_item.content == "streamed output visible to user"++@pytest.mark.asyncioasync def test_parallel_code_execution_child_uses_code_exe_log_type(monkeypatch) -> None:class FakeDeferredTask: