[eric] telemetry: the missing-CLI error card carries a flight envelope, and a test keeps every error family honest

This commit is contained in:
ciregenz
2026-08-07 07:25:57 -07:00
parent 511e2b0029
commit 42b14165d5
2 changed files with 43 additions and 0 deletions
@@ -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),
@@ -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]