Letting AI agents check their own work: which checks we trust, and why
By ChabuLab. Published . 8 min read. Đọc bằng tiếng Việt
TL;DR
Nobody can read every diff a dozen agents write, so the agents prove their own work. Before coding they name what must stay true and pick a check that fits the risk. A check counts only after it has been seen failing, a change never edits the check that judges it, and green is followed by a separate hunt for faults, because green only covers what somebody thought to test. A fresh CI machine reruns the basics on every push. All of this catches a lot, but not everything: some faults in features and display still get through, so the owner's own look at the result, and the feedback that follows, stays part of the loop.
Why should the agent check its own work?
ChabuLab is one person and many AI coding agents. On a busy day a dozen of them change code in parallel, so a person reading every diff is not a plan. The first post explains how the work is split, and the safety post what limits the damage. This one is about the question in between: how do you keep shipping when you cannot look at most of what ships?
Our answer is that an agent must be able to prove its own change with no person involved, and that review is what is left over once the proof is in. That sounds like trust. In practice it is the opposite: agents are fast and they aim for green checks, so the rules below are mostly about making green mean something.
What does the loop look like?
What is written before any code?
The definition of done, as something you could observe. "The import works" can be argued about afterwards; "importing this 2,000-row file shows 2,000 rows and no duplicate after a second import" cannot. Writing it first also stops the agent from quietly redefining the task once the work gets hard.
What the change must keep true. A save must never lose the last edit. A puzzle must have exactly one solution. A page must not jump in height when a button is pressed. Each rule gets a check before or while the code is written.
Which check fits which change?
One kind of test does not fit every risk. The agent picks by what could go wrong:
- Saves, undo, retries, queues, anything with timing: a small model of the states, checked by a model checker (TLA+). Races hide in orderings nobody writes a test for; the checker tries every ordering within a bound.
- Geometry, parsers, game rules, data transforms: property or exhaustive tests over many generated inputs. A few hand-picked examples miss the edge that breaks.
- What a user does (open, type, save, switch): a project verify tool that starts the real app, drives it and reads the result. The test goes through the same door as the user.
- Refactors, framework migrations, rewrites: run the old and the new version on the same inputs and compare, with a written list of approved differences. "Behaviour stays the same" is checked, not assumed.
- Look, layout, motion, language: screenshots and short screen recordings at phone and desktop width, light and dark. Tests pass on ugly pages; only pictures show them.
Eleven of our projects now have their own verify tool: a small command-line program that launches the app, presses its buttons and returns evidence as data, plus a map of how to reach every feature. When a project that keeps changing has none, the agent builds one during its first real change instead of asking.
What makes a check worth trusting?
Most of the rules here exist because a check once lied.
- A check counts only after it has been seen failing. Put the bug back, or remove the guard, watch the check go red, then restore. A test written with the same mistake as the feature passes and proves nothing.
- Test what a user of the code can see, never its internals. Two quick probes: break the behaviour (return a wrong value, skip a save) and the test must fail; change the internals without changing results and it must still pass. A test that fails the second probe is pinned to the code's shape and will be "fixed" by being rewritten.
- A change never edits the check that judges it. No loosening a test, raising a size budget or skipping a step in the same change it is meant to judge, unless the change is about that check, and then it says so at the top of the report.
- No hiding flaky tests. No fixed sleeps, no retry-until-green, no raised timeouts: find the cause. We are adding a lint rule for this to our TypeScript projects. A trial run on ten of them found 74 places in 20 test files where a test swapped a real dependency for a hand-made fake, 17 raised timeouts and one fixed wait of just over a second.
- Models are tested against something outside their own formula. A simulation is checked against a published value, a conservation law or a limit. A test that recomputes the implementation repeats its mistakes.
- Three failed rounds means stop. If a check still fails after three attempts, the agent reports the output and what it tried instead of looping a fourth time, because the fourth loop is where checks get weakened.
Why is green not the end?
Green covers what somebody thought to check. One of our lessons shipped with 274 passing tests, a line-quality check and screenshots. Asked where it was wrong, a reader found six faults in minutes: one metal part drawn through another, a wrong physical phase baked into its own test, wire turns that merged at phone width.
So after the checks pass there is a separate step that asks only "what is wrong here?":
- A fresh model looks. The screenshots go to a new model that is told only what the picture is meant to show, not what the author believes it shows. Every fault it names is a claim: confirmed on a close crop, then fixed or rejected with a reason.
- The agent does its own fault pass at the size a reader sees, edges and labels enlarged, and writes down what it examined and what it found. A skipped step is reported at the top, not tucked into the limits.
- Pictures are looked at, not just taken. A screenshot of a loading spinner or a stale build is not proof. The agent opens every image and samples frames of every recording before claiming anything.
Passing checks is not the same as looking good. For anything a customer sees, the look is judged as its own gate.
Who checks the checker?
For most changes, no second agent: the proof is the review. Changes to saved user data, money, sign-in or concurrency get one outside reviewer on a different model, because the author's checks share the author's blind spots. The reviewer is held to the same rule: a finding counts only with a command that reproduces it on the real code. The safety post has the trial behind that rule.
Then a fresh machine on a CI service, one that starts empty for every run so nothing left over on a developer's computer can make a check pass. Every push to the main branch of more than twenty repositories runs install, format, lint, types, tests and build on a fresh hosted runner. On its first run it found real faults that had slipped past local work: a web app with 131 hard-coded colours against a limit of 122, two lint errors, a failing test. All of them reproduced locally. Most runs take under two minutes and stay inside the free monthly allowance.
What does the report look like?
- Evidence before summary. The command and its output, the screenshots shown inline, then the summary.
- What green does not prove, in one line after the checks pass.
- Every number is labelled: measured, a target, or a guess. An unlabelled number is a hidden guess.
- For changes that touch saved data or money: what it can reach, how to undo it and whether undo is even possible, and where a failure would show up.
How does this stay fast?
- While working, run only the checks for the part being changed; everything runs once before the commit.
- A new gate starts by watching, logging what it would block, and only enforces after its false alarms are fixed. An agent stuck behind a wrong gate stops shipping.
- A repeated mistake becomes a check, not a note. When a bug could have been caught by a lint rule, the rule goes in with the fix. When the owner has to correct the same thing twice, it becomes a test, a lint rule or a hook.
What are the limits?
- Checks only cover what someone thought of. The fault hunt narrows the gap; it does not close it.
- Most of these rules are requests. An agent can skip a step, and only a hook can stop it. What makes a skip visible is that the report must show its evidence.
- The fresh model has blind spots too, so its findings are claims to confirm, not verdicts.
- Faults still get through. For all the effort above, some faults in how a feature works or how it looks still reach the owner, who finds them by using the result. The six faults in the lesson above were found that way, by a person, after every check had passed. An agent follows rules written in advance; it cannot look at a page and sense that something is off the way a person does. So the owner's final look, and the feedback that turns into new rules, remains part of the loop.
- We have no controlled comparison with working without these rules, so we claim no speed-up or defect rate. What we can say is narrower: the checks above caught real faults before anyone saw them, such as the ones the CI machine found on its first run, and each fault a person still finds becomes a new check.
What to take from it
Make the agent write down what "done" looks like before it starts. Pick the check by the risk, not by habit. Refuse to count a check you have never seen fail. Then, after everything is green, ask one more time what is wrong, with fresh eyes. That last question finds faults the green checks hide. And keep looking at the result yourself: the checks shrink what a person has to find, they do not replace the person.