Making AI-Written Code Reliable with an Evidence Loop
Coding agents can now write features, tests, and reviews with little human involvement, so the key question for engineering teams is how to prove the code is correct and keep it that way. This article describes an evidence loop built on independent grading, end-to-end and property-based tests, regression and contract tests, project rule files with post-generation checks, and practices for keeping tests stable and fast. It also explains how this setup lets one engineer oversee more agents in parallel, and where to start.
When coding agents move from completing a few lines of code to independently finishing requirements, writing tests, and reviewing changes, the central question for development teams is no longer “Can AI write code?” It is “How do we prove it wrote the code correctly, and keep it writing correctly?” Internal practice at some teams shows that, under a mature process, about 90% of code can be written and reviewed by coding agents. That result does not come from models being inherently reliable. It comes from an executable, verifiable, and reusable evidence loop behind the process.
An evidence loop does not depend on the model saying “I’m done.” Every generation passes through a cycle: generate, execute, grade, feed back, codify rules, and regenerate. Grading criteria should be as independent, repeatable, and observable as possible. Ideally, an independent grading tool or test program checks outputs against explicit standards. In internal tests on structured file generation, adding independent grading raised the task success rate by about 10 percentage points, and the gain grew with task difficulty. The reason is straightforward. On harder tasks, models are more likely to make confident mistakes in details. Executable evidence turns those errors from subjective debate into objective results.
1. From Watching Code to Managing Standards
In the traditional model, one person supervising one or two coding agents is already a practical limit, because every line needs human review. The evidence loop changes what gets supervised. Engineers no longer read model output line by line. They design grading criteria, maintain test environments, review failure evidence, and codify rules. As a result, the number of agents one engineer can oversee could rise from single digits to dozens or even hundreds. Parallel work depends on each agent being graded automatically, with failures that point to specific evidence.
Generating tests, benchmarks, and technical specifications used to be expensive. Engineers had to design scenarios, write assertions, and maintain data by hand. Now a coding agent can produce a first draft of a test suite in seconds, and engineers review whether the tests are valid. Once generated, these tests become programs that run automatically, and repeated runs do not keep consuming large amounts of model tokens. Tests shift from one-time manual work to reusable infrastructure. This shift is what makes parallel scaling possible.
2. End-to-End Tests: The Grading Standard Hardest to Bypass
If the team can invest in only one kind of test, start with end-to-end tests. They simulate real user actions, such as adding an item to the cart, going to checkout, entering shipping details, and reaching the payment success page. End-to-end tests check the full functional path. A feature either works or it does not, and it is hard to fake a local part of the flow or take a shortcut that passes.
A unit test timeout often reports only “timed out after 30 seconds” and rarely shows where the process got stuck. An end-to-end test can keep screenshots, page state snapshots, execution traces, and key logs. These show why the checkout button is disabled or at which step the payment request failed. For a coding agent, this evidence serves as both the grading result and guidance for the fix.
To make end-to-end tests effective, teams can give coding agents permission to operate the real test environment. They can test web pages through browser automation interfaces, test apps through mobile automation environments, test desktop software through desktop automation, or start backend services locally. A feature map should list real user action paths, keyboard shortcuts, state changes, and expected behavior. It works as both a construction guide for the agent and a grading standard. These permissions must stay inside an isolated test environment to prevent contamination of real data and accidental operations.
Scenario: cart checkoutOpen product pageAdd item to cartGo to cartClick checkoutEnter valid shipping informationSelect payment methodClick payAssert page shows "Payment successful"Assert order status is "Paid"Evidence: screenshots, page state snapshots, key logs, execution trace
End-to-end tests run slowly and depend on many environment components, so they should not cover every detail. A better approach keeps a small set of high-value critical paths, such as sign-up and login, search, ordering, payment, refunds, and permission checks, and pushes finer detail down to lower test layers.
3. Property-Based Tests: Using Invariants to Catch Edge Cases Humans and AI Both Miss
Many tests only cover flaws that humans think of. Property-based tests target extreme inputs that both humans and coding agents tend to overlook. The method starts by writing down a rule that must never be broken, called an invariant. The property-based testing framework then generates thousands of random inputs and tries hard to make the program fail. Random boundary conditions carry no subjective bias, so they are well suited to catching implementations that look reasonable but break the rule.
Common invariants include: serialized data must deserialize back to its complete original form; an account balance must never become negative; running the same migration or cleaning logic once or twice must produce identical results; and an optimized new implementation must produce exactly the same output as the old, unoptimized version for the same input. These rules are especially valuable in refactoring, migration, billing, accounting, and data cleaning.
Rule: account balance is never negativeRepeat N times:original_balance = random_amount(0, 10000)withdrawal = random_amount(0, 20000)result = withdraw(original_balance, withdrawal)assert result.balance >= 0assert result.balance + result.withdrawn == original_balance
Property-based tests cannot replace end-to-end tests, but they extend coverage at low cost. End-to-end tests confirm that main paths work for real users. Property-based tests confirm that core rules hold under random inputs. Combined, the grading system has both a user perspective and a rule perspective.
4. Regression and Contract Tests: Locking Fixed Issues and Boundaries
Beyond end-to-end and property-based tests, regression tests lock in defects that have already been fixed, so a coding agent does not reintroduce the same problem in later tasks. Contract tests check service boundaries and confirm that interface fields, types, error codes, and timeout behavior match the agreed specification. These tests may not be the first investment, but they cover two gaps: historical problems and collaboration boundaries.
When an AI keeps making the same mistake, such as printing sensitive user data to logs, developers should not just remind it in the next prompt. They should write the explicit rule into the project rule file or add a post-generation check hook. The rule file gives advance notice, and the hook blocks violations after generation. Together they turn individual errors into system memory.
# Project rule file (example)1. Logs must not contain sensitive user fields: phone numbers, ID numbers, full addresses, tokens.2. All external calls must set a timeout and limit retry counts.3. Serialized data must deserialize back to its original form. Field types and meanings must not drift.4. Re-running the same migration task must produce identical results.
function post_generation_check(diff):if diff contains log output of sensitive user fields:return reject, and cite rule 1if diff adds an external call without a configured timeout:return reject, and cite rule 2return pass
5. Avoid Two Failure Modes: Unstable and Slow Tests
The first failure mode is flaky tests. If the same test sometimes passes and sometimes fails, a coding agent learns to retry until it passes rather than fixing the code. Countermeasures include limiting the number of reruns, tagging and isolating unstable tests, fixing random seeds and test data, using environment snapshots, setting explicit timeouts and wait conditions, and requiring every failure to include root-cause evidence. Retries should only confirm intermittent environment problems. They must never serve as a shortcut to a passing grade.
The second failure mode is slow tests. The slower the tests, the less often AI can run them in batches, the harder it is to locate problems, and the more parallel agents get stuck in the test queue. Optimizations include layered testing, with end-to-end coverage of main paths and details pushed down; test sharding and parallel execution; caching dependencies and build artifacts; narrowing end-to-end scenarios to specific areas; preserving the environment quickly on failure; and moving slow tests to asynchronous or overnight batches. The goal is not to maximize the number of tests. It is to return high-value grading results within an acceptable time.
6. Rollout Order: Close the Loop First, Then Scale
The rollout can follow these steps. First, pick one real user critical path and set up end-to-end grading with evidence collection. Second, add property-based tests for core business rules, especially for amounts, permissions, idempotency, serialization, and migration consistency. Third, write frequent errors into the project rule file and add post-generation check hooks. Fourth, establish failure classification and test stability governance. Fifth, gradually increase the number of parallel agents. Scale only pays off once grading criteria are executable, failure evidence is locatable, and repeated errors can be blocked.
Dependable AI-written code depends on errors being found quickly, located precisely, and blocked systematically. It does not depend on models never making mistakes. End-to-end tests provide hard grading from the user’s perspective, and property-based tests provide broad
