Making machine-written code safe to ship
A quarter of the commits in this codebase were written by an agent working from plans I wrote. That's only defensible if everything around the agent assumes it will be wrong.
as any occurrences, new ones blocked by CIThe problem
Vedo is a bookkeeping product. Thirteen transaction types, sales tax that reaches tax authorities, invoices that a customer's own customers pay through Stripe. A wrong number here is not cosmetic.
I came into a codebase I had not written, part-time, as the only engineer on it. At that ratio the only way to move was to direct coding agents instead of typing everything myself. The repository had no CI and no tests when I arrived, and nobody had ever set branch protection on main. I wrote the pipeline and the test suite. Standing a gate up and making it binding are different jobs: for a stretch the lint step sat commented out behind my own note to re-enable it once the violations were cleaned up, coverage ran report-only, and the smoke test covering the transaction forms ran only after deploy. My own summary of the risk in that window: a careless prompt, then a lazy agent, then a band-aid commit, straight to main. Over two weeks in June I made every one of them blocking.
Everything below follows from that one exposure.
Making the codebase legible to an agent
When I arrived, four files carried roughly 28,700 lines between them: a routing file of over 17,000, a storage layer of nearly 5,000, one page over 4,000 and another near 2,800. Every feature touched server/routes.ts. It grew for another six weeks before I could turn to it, peaking at 19,861. An agent cannot safely edit a file it cannot hold in context, so the size was not an aesthetic problem. It was the reason agent edits kept colliding. I split it into 47 domain modules, a routes and controller pair per domain, and gave the storage layer the same treatment. The routing file ended at 59 lines. The banking page went from 6,919 lines to a 239-line shell over per-tab modules.
The tax math had the same shape. Ten transaction forms each carried their own copy. A parity harness ran every form's math against a single engine: 205 inputs agreed, 109 did not. The invoice form matched the engine every time and the deposit form diverged on twenty-six inputs, which is to say the same sale entered on a different screen produced different tax. Nor was it one bug repeated ten times: one form dropped a line's total to zero, another saved an unrounded float into the record, another returned no tax at all on a hundred-dollar line. There is one engine now and eight thin adapters, migrated under a rule that locked the existing behaviour first so the move could not smuggle in a change.
Request shapes were hand-validated on the server and hand-built on the client, independently, so the two drifted apart quietly. One declaration per endpoint now lives in shared/contracts and both sides consume it, with a CI check that fails on any endpoint without a caller, or any caller without an endpoint.
Encoding what an agent gets wrong
While finishing one of those extractions I found that the Currencies page could not add or edit an exchange rate at all. Three failures were stacked in a single handler. The client sent a field named effectiveDate and the server expected date, so creating a rate returned 400. The client called PUT where the route was PATCH, so editing returned 404. The handler then wrote to a database column that does not exist, so the date vanished silently behind a 200 OK.
All three were possible because one variable was typed any. The page had been broken since November 2025, three months before I started, and stayed broken for six months after. A compiler would have caught every one of them. One escape hatch turned three type errors into a feature that was broken in production, including a failure that reported success.
So I made that class of mistake unable to reach main. Thirty-three gate scripts run in pre-commit and CI, each one a ratchet against a baseline that may only shrink. as any went from 402 occurrences to an empty baseline. Unvalidated request bodies went from 200 occurrences to a deleted baseline file. Oversized files went from 95 to 52.
Two things I got wrong building them. Two scans were unpassable by design, because their self-checks were calibrated against the debt that existed on the day I wrote them, so they went red exactly when the code got clean. Coverage floors are durable; debt floors defeat themselves. And every gate now ships a negative control, a deliberate violation proving the gate actually goes red, because a gate that has never failed is decoration.
The same machinery carries design decisions. Twelve design rulings are encoded as executable scans in the build chain, not written into a style guide, because a style guide is advice and an agent does not take advice. Ten of the twelve baselines sit at hard zero today.
Assuming the agent is wrong
An agent reporting that it fixed something is not evidence that it did. I spot-checked 49 of its claimed fixes without reading the reports first. Seven proved false, across session handling, security headers, touch targets and ARIA attributes rather than money code, which is the point: a self-report is unreliable regardless of what it reports on. One headline finding, a suspected cross-tenant leak, turned out to be a false positive: the original probe had run as a platform superuser, an account that cannot distinguish a working authorization guard from a broken one.
What came out of that is an executor and critic pattern. An executor proves its own work, then up to three rounds of an adversarial critic try to break it, and the critic has to verify independently, not read the executor's report. Commits gate on suite exit codes, never on an agent saying it is done.
It earns its place. On 23 June I wrote a Stripe payment path that multiplied every amount by 100 to convert to minor units. Sixteen currencies have no minor unit. A ¥5,000 invoice would have been submitted as ¥500,000, always in the overcharge direction, while the webhook recorded ¥5,000, so the books and the bank would have disagreed by the difference. Adversarial review of those same two commits caught it before it merged. It never reached the production branch, which is where all of this work still sits.
The fix scales by each currency's real exponent and fails closed on three-decimal currencies, rejecting the payment at checkout instead of attempting a partial handling that could still mis-charge. I also rejected a home-currency-only guard, because it reads as protection while providing none.
It is not only money code that needs the second reviewer. An adversarial pass over my own icon migration found five blocking defects, three of them the same class: I had deleted a glyph that was the only thing inside its button. The clearest was a sidebar sign-out control whose text label renders only when the rail is expanded, so with the glyph gone the collapsed rail drew a button containing nothing at all. A per-glyph reading cannot catch that. It is a property of the surrounding button, and only something adversarial and whole-screen finds it. The glyph went back, the collapsed rail now carries the word in a screen-reader-only span so the control has a name in both states, and a test pins both. The same pass closed a sibling hole: the theme toggle in that rail had no accessible name either.
Assuming the tests are wrong
A user reported that typing 110 into a money field stored 10. It was not the input and not the form. An unsaved-changes hook marked the form dirty on the capture phase, so React re-rendered before the field that owned the keystroke had processed it, and the character was wiped. It affected the first keystroke in every field of all fourteen transaction forms, and only the first, because every later keystroke sets a flag that is already set. That's why it read as a flaky input rather than a deterministic bug.
A green unit suite could never have found it. Synthetic events do not reproduce it. The diagnosis needed a real browser, which is the reason I stopped treating a passing suite as evidence and started running the full chain locally, deferring nothing to CI.
Assuming the spec is wrong
A stakeholder requirement document for the Chart of Accounts carried a section headed "already correct, do not change these," listing debit and credit direction for all 22 account types and asking me to read it before starting so I would not fix something that was already right.
I checked it anyway, and that was where the defect was. There is no single source of normal-side classification in the product. A fourteen-type list lives in one place and an eight-type list in four others, including the client code that draws the debit and credit indicator on the exact cell the document was about. Six account types were being shown on the wrong side.
The clearest case: a depreciation account holding a perfectly normal balance was drawn as a credit and flagged as sitting on the unusual side, while the trial balance printed the same figure in its debit column. Two screens, one number, two labels. All six are now classified in one place.
I now falsify a spec against the running code before planning against it. On a separate bank-feed specification, six claims did not survive that check. One mattered: the spec described a layout breakpoint as roughly 600px too early, but it's a container query, not a viewport query, so the error runs the other way and the correct fix is a smaller number, not a bigger one. The lint rule the spec proposed to prevent regressions passes on the broken value, so building it as written would have raised the breakpoint further and then shipped a test certifying the defect.
The trade-off
None of this ships a feature. On a part-time contract that's real time not spent on visible work, and it only pays back if the codebase keeps getting worked in, which no contract guarantees. Two other routes were open. Fix everything now, which the file-size gate rejected on its first day by registering 95 existing files as legal debt instead of blocking on them. Or review harder, which the plan conceded cannot work, because gates cannot gate taste. I took the slower route because the alternative was rediscovering the same class of mistake at a worse time, in front of a customer or in a ledger. The constraint that shaped how fast it could go was mundane: the agent harness runs on the same laptop I work on, so fan-out is capped at two or three concurrent agents. A six-agent run once made the machine unusable and had to be killed mid-flight. Width is a courtesy decision as much as a throughput one.
Outcome
Server coverage moved from 39% to 64% and client coverage from 81% to 94%, both as hard floors that may only rise. The codebase went from no tests at all to 460 test files. Thirty-three ratchets hold every catalogued category of debt at or below its baseline. Every defect my own process introduced was caught before it reached the production branch, usually the same day.