From 42b14165d53281efc6c3d01be41a18f1cb19f77e Mon Sep 17 00:00:00 2001 From: ciregenz Date: Fri, 7 Aug 2026 07:25:57 -0700 Subject: [PATCH] [eric] telemetry: the missing-CLI error card carries a flight envelope, and a test keeps every error family honest --- .../agents/manager/run/handle_run_error.py | 1 + .../test_every_error_carries_an_envelope.py | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 backend/tests/test_every_error_carries_an_envelope.py diff --git a/backend/apps/agents/manager/run/handle_run_error.py b/backend/apps/agents/manager/run/handle_run_error.py index a1f61d01..3ebac036 100644 --- a/backend/apps/agents/manager/run/handle_run_error.py +++ b/backend/apps/agents/manager/run/handle_run_error.py @@ -131,6 +131,7 @@ async def handle_run_error(e: Exception, session: AgentSession, session_id: str, submit_diagnostic({ "kind": "cli_binary_missing", "where": "manager.run.handle_run_error", + "flight": flight_recorder.build_envelope(session_id, "cli_binary_missing", "missing", session.model, "stream" if turn.current_turn_emitted else "spawn", -1), "session_id": session_id, "model": session.model, "error_preview": redact_for_telemetry(str(e), limit=400), diff --git a/backend/tests/test_every_error_carries_an_envelope.py b/backend/tests/test_every_error_carries_an_envelope.py new file mode 100644 index 00000000..4af5e187 --- /dev/null +++ b/backend/tests/test_every_error_carries_an_envelope.py @@ -0,0 +1,42 @@ +"""Clause: every surfaced error carries the full flight envelope. + +`cli_binary_missing` shipped without one and nobody noticed, because the only way to see it is to +force a failure class that cannot be forced on a dev box (the SDK falls back to the system `claude`, +then to ~/.claude/local/claude). An audit of the source is the sensor that does not need the repro.""" + +import re + +from backend.apps.agents.manager.run import handle_run_error as p_handler_mod +from backend.apps.agents import agent_manager as p_manager_mod + +P_SOURCES = { + "handle_run_error": p_handler_mod, + "agent_manager": p_manager_mod, +} + + +def p_diagnostic_blocks(src: str): + return re.findall(r'submit_diagnostic\(\{(.*?)\}\)', src, re.S) + + +def test_every_error_diagnostic_carries_a_flight_envelope(): + import inspect + missing = [] + for name, mod in P_SOURCES.items(): + for block in p_diagnostic_blocks(inspect.getsource(mod)): + kind = re.search(r'"kind":\s*"([a-z_]+)"', block) + kind = kind.group(1) if kind else "?" + # `recovered` rows are near-miss ledger entries, built by record_recovery, not error cards. + if kind == "recovered": + continue + if '"flight"' not in block: + missing.append(f"{name}:{kind}") + assert not missing, f"error diagnostics with no envelope: {missing}" + + +def test_the_cli_missing_class_specifically_is_covered(): + import inspect + src = inspect.getsource(p_handler_mod) + block = [b for b in p_diagnostic_blocks(src) if '"cli_binary_missing"' in b] + assert block, "the cli_binary_missing diagnostic disappeared" + assert '"flight"' in block[0]