Tracing a Run
Why This Matters
“TestPilot called it flaky last Tuesday. Why?” You will get that question. Without a trace of every request, tool call and decision, the honest answer is “no idea”, and a tool nobody can explain is a tool nobody trusts.
What to record
Per run, as structured events (one JSON object per line is fine):
| Event | Fields |
|---|---|
| Request to the model | agent, model, settings, input size, prompt version |
| Response | stop reason, usage, duration, the validated result or the validation error |
| Tool call | tool, input, result summary, duration, error type |
| Hand-off | from agent, to agent, the brief (or its hash) |
| Gate | which gate, allowed or blocked, why |
| Final verdict | category, confidence, evidence references, escalation |
One trace id
Generate one id per run and pass it to every agent, tool and log line:
const traceId = `run-1099-${Date.now()}`;
log({ traceId, agent: "root-cause-investigator", event: "tool_call", tool: "get_commit_diff", input });
Now one search gives you the whole story of a run, across all agents.
What never goes into a trace
- API keys, tokens, passwords
- personal data from test environments
- full screenshots (store a reference instead)
Mask before you write, not after.
Debugging a wrong verdict
With a trace, the Tuesday question takes five minutes:
- Find the final verdict for the test.
- Look at the evidence references: what did TestPilot actually see?
- Look at the tool calls: was the log missing? Did the history call fail?
- Look at the request: which prompt version, which model?
Most wrong verdicts turn out to be missing or misleading evidence, not a “stupid model”.
From trace to test
Every wrong verdict you trace becomes a golden case (lesson 17), with the evidence exactly as TestPilot saw it. That is how the golden set grows from real life, and how the same mistake never comes back unnoticed.
What the first real trace found
The first traced run of solution/lesson-60-reliability on run-1099, asked the lesson’s question about t-031:
It answers all three questions from the trace alone: t-031 was represented by t-029; the investigator read the commit diff and the log (each in a few milliseconds; the model turns took seconds); and the verdict relied on six pieces of evidence, each with its source.
It also showed two bugs, in TestPilot’s own checks:
- The quote check was wrong. The bug writer’s quotes, such as
GET /api/cart 200 {"subtotal":100.00,…}, were real, but flagged as unsupported twice. The bug writer receives the finding as JSON inside its brief, with escaped quotes and newlines, and the check compared those against plain text. The trace showed exactly which quotes and which attempt. - A flag that changed nothing. Despite the flags, the gate allowed the proposal: the check only covered the investigators, not the bug writer. And the report escalated the same root cause twice (groups g3 and g4).
Both are fixed on the branch, each with a test that reproduces it. Without the trace, the report alone looked fine: one proposal, two sensible escalations. That is the point of this lesson: a trace shows not only why the model decided something, but also whether your code did what you think it does.
Exercise
Add trace events with a trace id to TestPilot, run run-1099, and answer from the trace alone: which tools were called for t-031, how long did they take, and what did the final verdict rely on?
Compare with solution/lesson-60-reliability, which covers lessons 54–60 (see docs/exercises.md, module 7).
Show what a good answer looks like
A trace that is good enough answers all three questions without re-running anything:
- Tools for
t-031: the list oftool_callevents with that test id and the trace id, in order, for exampleget_test_history→read_log→get_commit_diff. - Durations: each event has a start time and a duration; the slow one stands out immediately.
- What the verdict relied on: the
evidencequotes in the final verdict, each traceable to the tool result it came from (lesson 58).
If you have to guess any of the three, add the missing field to your trace events.
