From fb7c2204d47e54df8d13179ce3ff791b607dc1a2 Mon Sep 17 00:00:00 2001 From: Justo Stoll Date: Tue, 25 Aug 2026 11:59:13 +0200 Subject: [PATCH] Name the exception type in sub-agent failure messages; keep the traceback Some exceptions stringify EMPTY (httpx.ReadTimeout/ReadError, TimeoutError): a sub-agent killed mid-stream by a backend restart reported 'Sub-agent failed: ' with nothing after the colon, and no traceback was logged anywhere (observed live 2026-08-25). The handler now logger.exception()s and formats 'Type: message' (or bare 'Type' when the message is empty). (cherry picked from commit ff138a9a01a93714dc6d8d2bce3ee57ace03647d) --- .../calliope/agent/harness/orchestrator.py | 13 +++-- calliope-backend/tests/test_agent_harness.py | 50 +++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/calliope-backend/src/calliope/agent/harness/orchestrator.py b/calliope-backend/src/calliope/agent/harness/orchestrator.py index 16812cbc..d197fd25 100644 --- a/calliope-backend/src/calliope/agent/harness/orchestrator.py +++ b/calliope-backend/src/calliope/agent/harness/orchestrator.py @@ -296,7 +296,14 @@ async def orchestrate( } ) except Exception as exc: # noqa: BLE001 - results.append(f"[{role}] FAILED: {exc}") + # Some exceptions stringify EMPTY (httpx.ReadTimeout/ReadError, + # TimeoutError) — always name the type, and keep the traceback + # (observed live 2026-08-25: "Sub-agent failed: " with nothing + # after the colon, because a deploy restart killed the in-flight + # stream and the ReadError carried no message). + logger.exception("Sub-agent %s failed", role) + detail = f"{type(exc).__name__}: {exc}" if str(exc) else type(exc).__name__ + results.append(f"[{role}] FAILED: {detail}") session_log.append_event( session_id, session_log.TASK_END, @@ -309,7 +316,7 @@ async def orchestrate( session_id, session_log.ASSISTANT_MESSAGE, { - "content": f"Sub-agent failed: {exc}", + "content": f"Sub-agent failed: {detail}", "agent_name": f"{role}-agent", "status": "error", }, @@ -318,7 +325,7 @@ async def orchestrate( { "role": "assistant", "agent_name": f"{role}-agent", - "content": f"Sub-agent failed: {exc}", + "content": f"Sub-agent failed: {detail}", "status": "error", } ) diff --git a/calliope-backend/tests/test_agent_harness.py b/calliope-backend/tests/test_agent_harness.py index f36fcf54..c96386fc 100644 --- a/calliope-backend/tests/test_agent_harness.py +++ b/calliope-backend/tests/test_agent_harness.py @@ -685,3 +685,53 @@ def test_bulk_video_policy_phrases(): assert allows_bulk_video_enqueue("yes", 24) is False assert allows_bulk_video_enqueue("generate all scenes", 24) is True assert allows_bulk_video_enqueue("do every clip", 10) is True + + +def test_sub_agent_failure_names_empty_str_exception(client): + """An exception whose str() is EMPTY must still be identifiable in the + failure message and event log. Observed live 2026-08-25: 'Sub-agent + failed: ' with nothing after the colon — an httpx.ReadError('') raised + when a deploy restart killed the in-flight stream.""" + import httpx + import calliope.agent.harness.orchestrator as orch + from calliope.agent.harness import log as session_log + + r = client.post("/api/agent/sessions", json={"title": "crash-detail"}) + sid = r.json()["id"] + pid = _make_project(client) + + class _SwarmPlanClient: + async def chat(self, messages, temperature=0.2, **kw): + return json.dumps( + { + "mode": "swarm", + "note": "plan", + "tasks": [{"role": "assets", "goal": "update text assets"}], + } + ) + + async def close(self): + return None + + async def dying_sub_agent(ctx, sub_history, allowed, *, agent_name, on_message=None, **kw): + raise httpx.ReadError("") + + orig_client = orch.LLMClient + orig_sub = orch._run_sub_agent + orch.LLMClient = lambda: _SwarmPlanClient() + orch._run_sub_agent = dying_sub_agent + try: + ctx = ToolContext(session_id=sid, project_id=pid) + asyncio.run(orchestrate(ctx, [], session_id=sid)) + finally: + orch.LLMClient = orig_client + orch._run_sub_agent = orig_sub + + events = session_log.read_events(sid) + fails = [ + e.data for e in events + if e.type == session_log.ASSISTANT_MESSAGE + and str(e.data.get("content", "")).startswith("Sub-agent failed:") + ] + assert fails, "no failure message recorded" + assert "ReadError" in fails[0]["content"]