Skip to content

AI in practice

Series article

From the engine room #3: A finish line the runner can't move

A red test written by one session, locked by code and made green by another. That is how the one running can't move the finish line.

Thomas Petersen · 23.11.2026 · 11 min read

Part 2 ended with a story refined into at most five tasks. Each task has a spec marker and a list of the files it is expected to touch. This is the step where the code gets written. It is probably the most important mechanism in the whole system, and it started with us measuring what we got for the money.

Built like a human team

Sessions per phase in the first version, and how many tasks got zero, one or more fixes.

The first version of the runner was built the way I had seen good development teams work in my years as a Scrum Master. Each task went through four phases, each with its own session: one implemented, one reviewed, one tested, and one fixed what those two found. It felt thorough.

In September we measured just over 2,000 tasks, using the task logs and the runner's token report. There were more review sessions than implementations, because a task could get several review rounds, and each round was a new session that read the whole diff from the start. Review and test together used about 40% of the consumption. That is time and money, and those were the two things we measured the runner on.

The number that settled it was a different one: 86% of tasks went through without a single fix from review. For most tasks, the review was a session that read the code and approved it.

When there finally was a fix, the largest category was convention-miss. The code did the right thing the wrong way: a different pattern from the rest of the codebase, logic in the wrong place or names in a different style. The agents understood the what. They missed the how. And a review afterwards is the worst possible moment to catch it. The code is written, the direction is chosen, and a fix is a new session that has to understand both the task and the first session's choices and then redo them.

What is scarce for us

Phase models are built for a team of humans. They optimise for developer time being scarce, knowledge sitting in people's heads and rework being expensive. A review is expensive, but cheaper than a bug in production.

For us it is the other way round. Code is cheap. The sessions remember nothing between runs. Discarding an attempt and starting over costs only tokens. What is scarce is reliable verification and my attention. An LLM reviewing another LLM's work is neither. It is one more opinion.

It was not Scrum that was wrong. The framework survived: the backlog, refinement, the Definition of Done, one review per story and the retrospective, which for us also covers the runner itself (#10). What went were the habits from teams of people, where every change goes through review and test by someone else. They pay off when the person writing the code remembers what the review said last time. A session does not.

v2: the quality comes from the finish line

We cut down to two sessions per task, spec and implementation, and one review per story.

A task's run in v2: spec, red, lock, implementation and gate, with discard, new attempt, dispute and block.

The spec session writes only tests from the task's acceptance criteria, plus stubs for the new public surface, methods and types that throw "not implemented". It runs on the cheaper model unless the story is marked as risky.

Red. The runner measures for itself. Red means that build and typecheck are green and that at least one spec test fails against the stubs. The requirement for a green build is deliberate. A test with a typo in a selector also fails, and in the first version that kind of thing could pass for red. Now the test has to compile and fail for the right reason: because the code is missing.

The lock. When red has been verified, the runner commits spec and stubs as one commit and writes its sha into the task. That sha is the anchor for the lock: the implementation's diff against the spec files, measured from that commit, must be empty. The stubs are not locked. They have to be filled in, after all. An attempt that is to be discarded is reset to the point where the attempt itself started, and a dispute starts from there too. That is not always the spec commit: sibling tasks' work can lie in between, and a reset must not take that with it.

The implementation is a new session. It gets the spec, the stubs and a handoff (#4) and has to make the tests green without touching them. It has build and test available itself and must run until green.

The gate after the implementation is deterministic. The spec tests must be green, the lock must be intact, and a validation plan must be green. The plan is built from the files the diff touches and consists of builds and tests from a fixed list. How it is built is the subject of #8. No AI judges whether the result is good enough.

Discard instead of fix

The spec commit as anchor: the lock is measured from it, a red attempt is saved as a patch and reset to its start, and the next attempt starts from there.

If the gate is red, there is no fix loop. The attempt's diff is saved as a patch in the task's log, the worktree is reset to the start of the attempt, and a fresh session on the strongest model starts with the gate's error output and the previous attempt's handoff. It can see what was tried, but it does not start from it.

If the second attempt also fails, the task is blocked, and then another mechanism takes over (#7).

It sounds wasteful to throw code away. But the alternative, letting a session fix its own code, is where agents work themselves into a corner: one fix on top of another while the context fills up. A fresh session with the failure in front of it is cheaper than a tired session with the whole history behind it.

In our example, access per data type, ten attempts were discarded across 113 tasks. Only one of them because the gate was red. The other nine were discarded because the implementation believed the test was wrong.

When the test is wrong

The two tests that contradicted each other, and why the comparison by reference never removed a group.

Sometimes the test is wrong. Then the implementation can raise a dispute against the spec. It has to point to the test it believes is wrong, explain why and prove it. The runner discards the attempt, and a fresh spec session settles the matter. Either it fixes the test, and then red is measured again and the lock moves. Or it upholds the test with a justification. There is one dispute per task, and it counts as one of the two attempts, so it cannot be used to buy time.

An example from the deliverable. The spec had two tests of the same rule. One said that a user with one permission from each group may edit. The other was meant to prove that each group is necessary, by removing one group at a time and checking that the user then may not edit. The implementation got the first one green and the second one red, and raised a dispute.

The proof was precise. The test found "the other groups" by comparing with reference equality, but the helper method built new arrays on every call. So nothing was ever equal to anything, no group was removed, and the test asked exactly the same question as the first test, just with the opposite expected answer. It could never go green. The dispute quoted the measured failure, explained why it was the second test and not the implementation that was wrong, and proposed the fix: compare by index or by value. The spec session fixed the test.

Another one: a UI test where the test's helper function gave every field the value "none", while the same test marked a different value as selected. The component follows a documented rule that a value always wins, so it showed exactly what it should, and the test expected something else. 39 tests green, one red, and the dispute pointed at the fixture, not at the code.

All nine disputes in the deliverable ended with a corrected spec. Those are the nine discarded attempts mentioned above. That is no coincidence. On 1 November we counted all disputes in the state repo: 135. In 132 of them, the spec session fixed the test. Three were upheld. When an implementation raises a dispute with proof, it is almost always right.

The outcome of all disputes in the state repo, and why the attempts in the example were discarded.

We measured and said no

The shadow run's six disputes: how much of the attempt's code survived, and how long the new session took.

That number led to an obvious proposal. If the implementation is almost always right, why discard its attempt? We measured how much of the discarded attempt's code survived in the task's final commit. The median was 100%. The proposal was that the runner itself would put the attempt back after the corrected spec and only start a new session if the gate was then red.

We built a shadow run that tried this alongside the real process without changing anything. After six disputes it was removed again, and the proposal was rejected. All six attempts went green, but only three were actually done. Reuse could at most have saved 24 of 71 minutes, all on very small tasks. And in two of the six, the new session produced a different solution from the attempt, with work that the locked tests did not require. Reuse would have lost that work. The shadow run also cost a build and a test run per dispute.

It is a small story, but it shows the pattern: a good number is not a decision. The measurement said that the code survived. It did not say that it was the best code.

The edges

The rule is simple. The edges are not, and each of them is a task that got stuck:

  • The lock hit too broadly. Today it locks per C# type instead of per file. In a type or a script that existed before the spec, only what the spec itself wrote is locked. And what the story branch has taken in from its base is not the task's change.
  • Red that was already there. A test suite that was already red on the base could never go green in a task. The gate now re-runs a red command on the task's starting state and tolerates the failures that were also there.
  • Criteria that are already met. If the spec session finds that the code already does what the criteria require, it says so, and the tests are committed as a guard instead of a red spec. The session has to make that claim itself, because a test that is merely too weak must still be rejected.
  • Tasks without testable behaviour. Documentation, configuration, generated code and visual details can skip the spec, but only from a closed list, and the runner checks afterwards that the diff touches only what the exception allows.
  • Dispute on the last attempt. It used to block the task, and no session was allowed to fix the locked spec afterwards. Since 29 October it goes to the spec session, just like a dispute on the first attempt.

One review per story

The only LLM review left is the story review. One session reads the whole story's diff, has to mention every changed file and has to assess whether the spec tests actually test the criteria, because that is the only independent check of the spec author. Findings become new tasks with the same flow: spec, implementation, gate. That comes in #5.

The largest root cause from the measurement got its own rule. If a finding is a general convention-miss, the new task's spec must be an architecture test for the whole codebase with a baseline that may only shrink. Then the convention becomes a test the moment it is fixed. More on that pattern in #10.

Replace, don't add

One decision mattered more than the others: v2 was to replace v1, not sit beside it. There was to be no parallel path and no flag to switch the old one back on. And the runner was to end up with less code than before.

A test holds the runner's size against a budget file. The v2 branch first built the new, then deleted the review, test and fix phases, and the budget was lowered in the same merge. The rollback rule was written before we switched: if the median cost per story does not fall, or the number of red builds after merge rises, we go back.

The retrospective measured afterwards whether it paid off. On 8 November the median cost of a story was 15.10 USD against 28.71 USD before v2, 47% less.

The first days

It did not go smoothly. After the first twelve hours the report showed that 1.3% of tasks were blocked. The real number was 16.3%, because sessions that could see that the gate would never go green blocked themselves, and the report did not count those.

Three of the first seven blocks were the gate's fault, not the task's. An item in the validation plan had prose after the command and was run as a command. And the red test suite on the base, mentioned above, was one of them.

The decision

More AI checks are not better control. A check that almost always says yes, and that is one LLM's judgement of another LLM's work, gives reassurance but not certainty. The certainty comes from a finish line the runner can't move: a red test written by someone else, locked by code and run by code. And when the finish line itself is wrong, there is one way to move it: with proof, to another session that decides.

The next part is about what passes between the sessions when they never talk to each other (#4).

Numbers as of 19 November 2026.

—
The code is written by AI. So is the text. The decisions are mine.

Thomas Petersen

CTO of Performance Metrics. More than 20 years in backend development, ten of them as a consultant. Decides what the runner builds and lets AI write the code.

LinkedIn

← All posts