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)
This commit is contained in:
@@ -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",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user