← Back to writing
Case study · Agent Flight Recorder

The tool call said completed. The tests never ran.

Completed is not succeeded

A coding agent ran one shell command. The log recorded it as completed. Below is the end of what that command printed, unedited apart from redacting a home path.

  File "/opt/anaconda3/lib/python3.12/unittest/loader.py", line 308, in discover
    raise ImportError('Start directory is not importable: %r' % start_dir)
ImportError: Start directory is not importable: '~/code/afr-sandbox/tests'
Added #1: Buy milk
Added #2: Walk dog
Completed #1: Buy milk
  1 [x] Buy milk
  2 [ ] Walk dog
Removed #2: Walk dog
Error: No task with id 9.
exit 1

There are two errors in it. One is a real problem. The other is the agent testing its own app on purpose. Which is which, and how would you know from the log alone?

The setup

I am building Agent Flight Recorder (AFR), a prototype that records what a coding agent did in a session and points to the decisions that mattered. Every claim it makes must cite a logged event. It is observe-only: it never blocks the agent.

This was a real session in my sandbox, run through Omnigent 0.22.0 with Claude Code 2.1.325. The request was a small Python command-line todo app, with saved tasks and "automated tests".

In one tool call, the agent wrote six files, ran the test suite with python3 -m unittest discover -s tests -t . 2>&1 | tail -4, then tried the app by hand. The last command in that call was echo "exit $?".

The answer

The ImportError is the real problem. In Python 3.12, unittest raises exactly this error before it starts looking for tests (source). So no test ran in this invocation.

Error: No task with id 9. and exit 1 are the deliberate ones. They come from the last two commands in the call:

python3 -m todo done 9; echo "exit $?"

The agent asked its app to complete a task that does not exist, then printed the app's exit code itself. Its summary at the end of the session says it "tried a bad id, which gave an error and exit code 1". So exit 1 is not a recorded exit status. It is text the agent printed.

The harmless error looks worse: it ends with an explicit exit 1. The real failure has no exit code at all, and tail -4 cut off the top of its traceback. A search for Error finds both messages. To tell them apart, a reviewer needs to know which command produced each one and what that command was supposed to do.

Line in the outputWhat it wasMarked as a failure anywhere?
ImportError: Start directory is not importableReal: no tests ranNo
Error: No task with id 9. / exit 1Intended: a negative test of the appNo
The tool call as a wholeReturned normallyRecorded as completed

Why no field could tell

I traced the call through every record AFR reads. None of them holds an exit status for the individual commands.

RecordWhat it holds for this call
Session transcript (omni session export)The output text above. No Exit code prefix: in these versions Claude Code adds one only when the whole tool call exits non-zero, and the last command was echo.
Policy log (Omnigent hook)A structured result: stdout with everything (because of 2>&1), an empty stderr, no exit-code field.
AFR's event streamoutcome: completed, basis "result returned, no known error marker".

Three ordinary shell habits did it. 2>&1 merged the error into normal output. | tail -4 kept the last four lines and dropped the start of the traceback. echo "exit $?" made the call end with success.

The only record of the failure is free text. Reading it correctly takes knowledge the log does not carry: what unittest does when it raises this error, and what each command was meant to do.

What my recorder did

AFR recorded the call as completed. That is correct at the level it claims: the tool call returned normally. It says nothing about whether the work inside it succeeded.

AFR does not guess failures from output text. That is deliberate. A rule that matched "Error" would flag both messages and could not say which one mattered.

My selector, the part that picks which calls matter, did worse. The version I had then missed this call entirely: the files written with heredocs made the command unparseable.

Later versions pick it. That looks like a fix, and an evaluation that only counts correct picks would score it as one. But the reason they give is an rm -f on a scratch file. When I labelled the session, before any selector ran, I marked this call for two other reasons: it created the application and its tests, and it contained the failed test discovery. Right call, wrong reason.

So an evaluation has to ask two things: did the selector pick the call, and does the reason it gives hold up? A pick for the wrong reason says little about the next session.

The agent noticed the problem itself. Its next message: "The CLI works. The test discovery failed because tests/ has no __init__.py, so I'll add one." In the next call it added that file and ran the tests again. The traceback is the evidence that discovery failed. The agent's message adds a diagnosis, and a recorder can cite that only as the agent's claim.

What I'll change in AFR

The fix is not a smarter pattern. It is a clearer vocabulary. The design separates three levels of evidence:

LevelEvidenceIn this session
Confirmed exit statusA recorded non-zero exit status, or a blocked callNone. The exit 1 is printed text, not a recorded status
Reported errorA known test runner or interpreter reports an error, with no exit status per commandThe ImportError
UnknownNeither success nor failure is establishedMost completed calls

A report of an error is not proof that the operation failed. The report is observed. The failure is inferred. The explanation should say "unittest reported an ImportError", not "the tests failed".

Even a confirmed exit status is not a verdict. A non-zero exit can be exactly what a negative test expects. So the rule I want AFR to follow: record the command, its observed result, and the expected result when known, and state which of those supports the verdict. The expected result usually comes from the agent's own words, so it is cited as the agent's claim.

None of this is built yet. First I collect labelled examples, positive and negative. A detector that catches the ImportError but also flags Error: No task with id 9. is not progress.

The selector is not good yet either. The numbers so far are in the method notes.

Completed is not succeeded

My AFR demo asks: the tests passed, would you merge it? This session is the harder version of that question. The traceback tells us that test discovery stopped before any tests ran in this invocation. AFR recorded the shell call as completed. A reviewer had to read the output to see what happened inside it.

"Completed" means the tool returned. It does not mean the work succeeded. A recorder that blurs the two is not neutral. It is optimistic.

Method notes

  • One real session in my own sandbox, recorded on 16 November 2026. The output is quoted from AFR's redacted event stream.
  • Versions: Omnigent 0.22.0, Claude Code 2.1.325, Python 3.12. The Exit code convention and the policy log's fields are what I observed in these versions; they may change.
  • Selector results so far: on the next session I labelled blind, it picked 2 calls. 1 was a call I had marked important, and it missed 2. That is one session and 5 decided calls, too few to estimate accuracy.
  • AFR is a prototype in development. It does not produce explanations or reports yet; this write-up is mine, from its records.