published · 6 min read

Give Your Agent Ratchets, Not Thresholds

Quality gates for long-running coding agents, and the two ways they go wrong.

A line drawing of a toothed ratchet wheel with a pawl resting against one tooth and an arrow showing its direction of turn.
Pawl and ratchet, unknown illustrator, from Ottův slovník naučný, 1908. Public domain.

An AI agent drafted this from my projects, and another agent checked the draft claim by claim against the code and the run records or briefs that were kept. The projects and opinions are mine.

Here's a way to stop a coding agent in its tracks: add a new test that the current code fails, and tell the agent to always keep the tests green. It can't commit anything: every change it makes still leaves the new test red, so nothing it does is allowed to land. When I did this to a long-running agent loop, it did the only sensible thing left, which was to stash the work and stop committing. The agent was following the rules correctly, and the rule was wrong.

Thresholds and ratchets

The loop was building Kubet Mono, a monospace font for code and terminals, over eight days. It had dozens of quality checks: distinguishable characters, even texture, sharp edges, coverage. I kept adding checks as I learned what mattered.

A threshold says "this number must be at least X". Add a threshold to code that's below X and you've blocked all progress until the whole gap is closed in a single step. A ratchet says "this number may never get worse than it is now", and it comes in two common forms. In a floor that only rises, the current score becomes the minimum and any improvement raises it. In a baseline that only shrinks, the current list of known failures is recorded, new failures are blocked, and fixing an old failure removes it from the list for good. qntm's 2021 essay Ratchets in software development describes the baseline kind: a script that runs at lint time and counts deprecated patterns across the codebase, so they can't spread. Tools ship both kinds: PHPStan's baseline and ESLint's bulk suppressions report a recorded error that's gone, Betterer tracks a value that may only improve, and Codecov's target: auto compares coverage against the base commit, with a threshold for drops. With a ratchet, the agent can land partial work immediately, fix forward one improvement at a time, and never slide back. In the font project those lived in a handful of files, starting with floors.json and QA_BASELINE.json. On its own the agent could only move them one way. Ratcheting the glyph QA gate alone didn't unfreeze the loop: its half-done work still failed other tests, so it held the work back again. Letting red WIP: checkpoints land as well did. The commit that made the glyph QA gate a ratchet, at 13:22 UTC on 23 October, is called Glyph QA gate as a ratchet, so the loop can commit while it fixes. That message says the gate had blocked checkpoint commits: no loop commit for an hour.

Two panels: fixes against a threshold are blocked and the level stays flat, while the same fixes against a ratchet land and the floor climbs step by step to X.
The same fixes against a threshold and a ratchet.

The wrong baseline

I wanted the font to look original, so a gate compared glyph shapes to 14 reference fonts (16 later) and flagged any pair with an overlap score (intersection over union) above 0.85. In practice it flagged o, v, z, I and the vertical bar, among others, shapes that many monospace fonts draw almost alike. Without deforming letters that should look normal, the agent couldn't pass that gate. It deadlocked four items, and the gate's successors kept tripping the 36-hour item 42, alongside a dozen other directives. It took several amendments to fix, and the main one compared Kubet against the genre instead of against an absolute number. If two independent reference fonts already overlap at, say, 0.95 on a shape, Kubet sitting at that level isn't a sign of copying.

A similar thing happened with compactness. Its floor had been recorded from an early build at width 560, my target range was 560 to 600, and the shipping build was 600. No width above 560 could pass. That needed a one-time reset, with both values written down.

Noise in the metric

Another floor tracked a judged score: half an AI rubric rating, half a blind test in which an AI judge from the same loop compared anonymous renders of Kubet against reference fonts. Early on it came from a single judge and about nine comparisons. Claude Code, acting as my proxy, estimated the standard error at around 0.08, which is a back-of-envelope figure and wasn't measured. An item missed the floor by 0.09, about the size of that noise. Now put a floor that only rises on that number. A run is a draw from a noisy distribution, and the floor keeps the best draw it has admitted, minus a 0.02 tolerance, a quarter of that noise. After a few runs it sits above the true value, and a genuine result fails more often than not. Manheim and Garrabrant describe the general effect as regressional Goodhart: selecting on a high value of a noisy proxy also selects for the noise, so the true value is predictably lower than the proxy. The fix was a better measurement first: nine blind rounds instead of three, a rubric scored by three independent judges with the median taken, a font build scored once, no rerolls. Then a one-time, recorded reset of the floor from 0.7729 to 0.4325, the new protocol's first value. The directive behind both is Owner directive 117: judged/blind admission on a meaningful sample, from 04:17 UTC on 28 October, and the gap it cites is a failing 0.683 against a ratcheted 0.7729. Directives with that name were often my proxy's work.

Dots along a wave around a dashed true value, with an amber floor that rises to just under the highest dot and stays there while most later dots fall below it.
The draws follow a fixed wave and aren't measured scores.

It still wasn't quiet enough. At the very end of the project the builder rebuilt the font for a v0.2 release with a metadata-only change. The outlines were identical, but the file hash was new, so the protocol required fresh judgements. This time the same letters scored 6 out of 27 overall instead of 9, which was below the floor, and the release was blocked. I didn't override it. The floor did what a ratchet on a noisy number does: v0.1.0's 9 of 27 had set it, minus the tolerance, and the same outlines drawing 6 failed it, and would have failed the reset value too. The new protocol had kept that floor ratcheting, which the lesson below warns against.

My proxy had already written the lesson down two and a half days earlier, after the judged floor's stall:

A ratchet is only safe on a low-noise metric with a genre-fair baseline. "Floors only rise" plus a noisy metric locks in the best lucky draw.

Who can change a gate

Every gate in that project was "never weaken". That's the right default for an agent, because the cheapest way to pass a check is to change the check. It also means a bad gate stays bad until a person notices, and the bad ones cost hours apiece before anyone realised the gate was the problem.

So I settled on three rules:

  1. Only the owner can amend a gate. The agent can propose; it can raise a floor. It lowers or resets a floor only when an owner amendment tells it to.
  2. Amendments record the old value, the new value and the reason. A reset is allowed; a silent reset isn't.
  3. When an item stalls on a gate, check the gate first. Measure what the reference set does on that metric before asking the agent to try harder.

Before you turn a check into a ratchet, ask whether the metric's run-to-run noise is smaller than the change you care about, and whether good reference examples would pass the baseline. If not, keep it as a report until it's fixed. If you keep the ratchet, size its tolerance from the measured run-to-run spread. Google's SRE teams use a different tool for a number that's allowed to move: an error budget starts from a target below 100% and lets releases continue while budget remains.

All eight days are in "I Let an Agent Loop Draw a Font for Eight Days".