Home · Case study

What happens when the machine dies halfway through an AI-written change?

That question is most of what separates an agent demo from an agent you can put in a delivery pipeline. Here is how I answered it, and how I proved the answer.

The problem

An agent that edits code is a long-running process with side effects. It writes files, commits, compiles, runs tests. If it is interrupted — a restart, a deploy, a container evicted — the naive implementation either loses everything it was doing or, far worse, comes back and does the destructive half of its work a second time.

A demo never meets this. A delivery pipeline meets it constantly.

The design decision

I built the workflow as an explicit state machine on LangGraph, with every transition checkpointed into PostgreSQL, and the human approval modelled as an interrupt rather than a blocking prompt. The part that took the real thinking was idempotency: on resume, how does the process know whether it already performed its side effect?

The answer could not be “look at a flag we wrote”, because the crash can land between doing the work and recording that we did it. It had to be derivable from the work itself.

So the workspace path is a pure function of the workflow id, and the commit carries the approval's binding hash in its subject line. On resume, the process reads the real git history and asks whether that commit is already its own. That is a question the filesystem can answer truthfully no matter when the process died.

How I proved it

I wrote a drill that starts the real workflow in a child process and kills it — actually kills it, at a marker placed after the git commit and before the checkpoint. A fresh process then resumes and has to reach the right conclusion. Twenty-two assertions across four scenarios: killed after the commit, killed at a node boundary, interrupted before approval, and a deliberately corrupted checkpoint row.

Three real defects came out of that drill, and none of them would have been found by unit tests alone:

Workspace identity
The workspace path was not derivable after a mid-node kill, so a resumed process could not find its own work. It became a pure function of the workflow id.
Checkpoint durability
LangGraph's default asynchronous durability lost a boundary checkpoint under a real kill. Every invocation now commits its checkpoint synchronously.
Corrupt state
The checkpoint store trusted its decoder instead of raising on a malformed row. It now fails closed and reports the workflow as corrupt rather than resuming from nonsense.

What it does in production

Approval
Bound by hash to the exact path and content approved. The approve function is not present in the model's tool schema, so there is no code path for it to approve its own change.
Authority
The model proposes. A deterministic risk policy and the write boundary decide. Every model result is labelled advisory in code, not by convention.
Restart evidence
A workflow was left waiting for approval, the container was restarted for real, and the fresh container reported the same checkpoint still waiting. It was then approved over HTTP and the pipeline ran to completion.
Audit
Every state transition and every human decision is an append-only row in the event ledger.
Honest limits This is my own platform, which I built and operate. It is not an employer production system, and the traffic on it is mine. Three limits are worth stating plainly:
← Back to the home page