The model never marks its own work: checking AI-written code
AI can write a change in seconds. Deciding the change is right is a different job, and I give that job to real tools and a person. Here is the loop, and what it caught while I rebuilt this site.
An AI coding assistant will write a change faster than I can describe it. The change usually reads well. It has sensible names, a tidy structure and a confident summary at the end. None of that tells me it works.
So I keep one rule: the model never marks its own work. Whatever writes the change does not get to decide it is finished. Real tools check it, failures go back with the evidence attached, and a person has the last word.
This post is the loop I use, why each check is there, and three things it caught while an AI assistant helped me rebuild this site.
Why the model can’t grade itself
When you ask a model whether its code works, it answers from the same place the code came from. If it misunderstood something while writing, it misunderstands it the same way while reviewing. Asking again in a new prompt doesn’t fix that, and a polite “I’ve verified this” in the summary is not verification. It is a sentence.
Tools are different. A type checker doesn’t care how plausible the code looks. A test either passes or it doesn’t. A browser either draws the page or it doesn’t. Each check answers a question the model can’t answer about itself.
The loop
Every AI-written change goes through the same steps:
- The change is written. By the model, from a task with enough context to do it properly.
- The checks run. Formatting, types, tests, security and accessibility, in that order. Cheap and fast first.
- Failures go back with the output. The full error, unedited, plus the command that produced it. Then the model tries again.
- Attempts are capped. After a few failed rounds, the change stops and comes to me. A model that keeps failing the same check usually has the wrong idea, and more attempts make the diff worse.
- A person reviews what passed. Passing checks gets a change into review, nothing more.
The checks themselves are ordinary. That is the point: they are the same tools a team already trusts for human-written code.
import { execSync } from "node:child_process";
// Cheap checks first, so a formatting slip fails in seconds, not minutes.const checks = [ ["format", "prettier --check ."], ["types", "tsc --noEmit"], ["tests", "vitest run"], ["security", "semgrep scan --config auto --error"], ["accessibility", "axe http://localhost:4321 --exit"],] as const;
for (const [name, command] of checks) { try { execSync(command, { stdio: "pipe" }); console.log(`pass ${name}`); } catch (error) { const output = (error as { stdout?: Buffer }).stdout?.toString() ?? ""; console.log(`fail ${name}\n${output}`); process.exit(1); }}When a check fails, what goes back to the model matters as much as the check. I send the command and its raw output. A failing test, for example, comes back like this:
fail testssrc/lib/posts.test.ts > getPosts > hides drafts expected [ 'draft-post', 'live-post' ] to deeply equal [ 'live-post' ]Not “the tests failed, please fix them”. A summary throws away the one line the model needs. The raw output tells it exactly which expectation broke and where.
What each check is for
- Formatting keeps the diff readable. A reviewer should see what changed, not a reshuffled file.
- Types catch the confident mistakes: a property that doesn’t exist, a function called with the wrong shape, a value that can be empty and isn’t handled.
- Tests check behaviour I’ve already decided on. If the model “improves” something a test pins down, I find out immediately.
- Security scanning catches the patterns a model reproduces because it has seen them a thousand times: a secret written into config, user input passed straight into a query or a shell command.
- Accessibility checks catch what is invisible in a code diff: a button with no name, text with too little contrast, an image with no description.
What it caught while rebuilding this site
I rebuilt this site with an AI coding assistant writing most of the code. The rule held the whole way through, and it earned its keep. Three examples, all from building the version you’re reading.
A class name that took over a layout
The assistant wrote a callout component for posts, a box for notes and warnings. It named the note style note. The type check passed. The build passed. The code looked fine.
But .note was already the class for a row in the writing list, a three-column grid. In the browser, the note callout quietly became a three-column grid too: the label in one column, the text squeezed into another. Only measuring the element in a real browser showed it: one callout had grid-template-columns: 140px 439.75px 0px, its twin had a single column.
Types can’t see CSS. Tests that only check the HTML can’t either. This is the case for having a browser in the loop, even a headless one that takes a screenshot and measures a few elements.
Scrolling that compiled and did nothing
For the homepage story, the assistant first tried to make each scroll move the scene by exactly one step. It used a gesture library to listen for the mouse wheel. Everything compiled, and nothing happened. The page sat still.
A script that drove a real browser with real wheel ticks, one at a time, and logged where the page ended up after each one made it obvious:
8 {"y":900,"count":"4,812"}9 {"y":900,"count":"4,812"}10 {"y":900,"count":"4,812"}The callback never fired. Reading the code would not have found that. Running it did.
A timer that started below zero
The design system has live previews that play the homepage animation on a clock. One threw an error on load: Cannot read properties of undefined (reading '0'). The browser hands the first animation frame a timestamp that can be slightly earlier than the moment the clock started, so the elapsed time began negative, and a negative step became index -1.
The fix was one Math.max(0, ...). Finding it took loading the preview in a browser and reading the console. The model had written the code and called it done.
What stays with a person
Checks tell me a change isn’t broken. They don’t tell me it’s good.
The scrolling story above has a second half. After the one-step-per-scroll version worked, it passed every check I had. It also felt wrong. Taking over the scroll made the page lurch whenever a section started or ended. No tool flagged that, and no tool would. I looked at it, said it wasn’t smooth, and the approach was replaced with native scrolling that settles on each step when you stop.
That’s the part I keep for myself:
- Should this exist at all? A model will build what it’s asked for. Whether it was the right thing to ask for is a separate question.
- Does it feel right? Smoothness, pace, whether a page is pleasant to read. These are judgements, and they’re the user’s experience.
- Is it honest? Whether the words on the page are true. A model will happily write a convincing number nobody measured.
If you want to start
You don’t need anything new. Take the checks your team already runs on human-written code and put them between the model and the merge:
- Run them on every AI-written change, cheapest first.
- Send failures back with the raw output, never a summary.
- Cap the retries, then hand the change to a person.
- Add a real browser for anything visual.
- Keep a person on the decisions a tool can’t make.
Review comments are checks too, and I wrote up how I turn PR review comments into rules an AI coding assistant checks. If you use more than one assistant, one source of truth for AI coding tool instructions keeps the rules the same in all of them.
The model is a fast, tireless first draft. Treat it like one, and let something that can’t be talked round decide when the draft is done.