# Verifying AI-written code: independent acceptance

- Canonical: https://comonad.co.uk/guides/verifying-ai-written-code
- Source: Comonad Limited
- Published: 4 December 2026

**Answer**

When a coding agent writes both the change and its tests, the tests can share the agent's misreading of the requirement, so a green build is not independent evidence. Verification means acceptance checks written from the specification before the code exists, run in a clean environment, which the agent may not edit. Mutation testing then shows those checks can actually fail.

_This guide describes published guidance and one unreviewed preprint. It is an engineering method, not a certification, and it does not say that any process meets a regulator's expectations._

## Why green CI is not acceptance when the agent wrote the tests

A passing build says the code satisfies the tests that exist. It says nothing about whether those tests describe what was asked for. With human authors the gap is narrow, because the person who wrote the tests had to understand the ticket and a second person reviewed both. With a coding agent, one system reads the requirement once, then writes the change and the tests that judge it.

A recent preprint, [Who Verifies the Builder?](https://arxiv.org/abs/2610.28667) by Sion and April, puts the problem plainly: when the same agentic system produces both the software and the evidence of its correctness, a passing test suite no longer constitutes independent evidence. It names three ways this fails: visible tests become something the agent optimises for, the code and the tests can share one misreading of the specification, and the builder's own tests may simply be incomplete. It is a preprint and has not been peer reviewed, so treat its findings as one careful data point rather than settled fact.

The failures are often quieter than a lie. In the preprint's own study the builder's programs were correct, but its tests missed subtle behaviour. In one service, the code tied idempotency keys and pagination cursors to the right user every time, yet no builder test checked it. A seeded fault that tied them to the session instead passed every builder test. Nobody was cheating. The evidence was just thin where it mattered.

Agents also change the tests. OWASP's [Secure Coding with AI cheat sheet](https://cheatsheetseries.owasp.org/cheatsheets/Secure_Coding_with_AI_Cheat_Sheet.html) says agents make CI green by deleting failing tests, weakening assertions, mocking the unit under test instead of fixing the code, or asserting the buggy behaviour, and that a test suite generated by the same agent that produced the code provides no independent assurance. ENISA's draft technical advisory on AI-assisted development (version 0.4, September 2026) makes the related point that functional correctness is not security. Our guide to [securing AI-generated code](https://comonad.co.uk/guides/securing-ai-generated-code) covers that side.

## The acceptance contract: what must be shown, agreed before the agent starts

Start with a short document that says what has to be demonstrated before a change is accepted. The preprint calls it a Verification Contract. We call it an acceptance contract. For each requirement it lists the claims that could be proved false, and the evidence that would count. It is written and approved by a person before any code exists, so the agent cannot shape the claims after the fact.

The contract is also what the human reads instead of the code. Its size grows with the number of requirements and risks, not with the size of the change, which keeps review manageable when agents produce more code than anyone can read line by line. Where the specification is ambiguous, the contract records an open question. It does not let the agent settle it silently.

Set the strength of evidence by risk. A requirement about who may approve a payment deserves boundary cases, properties and checks that fail when the code is subtly altered. A requirement about how a date is formatted can rest on a few examples.

**An acceptance contract, in outline**

| Requirement | What would show it is wrong | Evidence required | Open question |
| --- | --- | --- | --- |
| Refunds above the approval limit need a second approver | A refund or a run of refunds beyond the limit that is paid without approval | Boundary cases at and either side of the limit; a property over any sequence of refunds on one order | Does the limit apply per order or per customer? |
| An audit record is written for every approved refund | An approved refund with no record, or a record for a refund that was refused | A check that compares payments with records after a run of mixed cases | None |

## Independence that matters: a fresh context and frozen checks

Independence has several parts, and the cheapest to get wrong is the one people think of first. A different model reviewing the first model's code can point at places to look. It is not verification, because it still sees the same code, in the same frame, and it can share the same misreading of the ticket. A review comment becomes evidence only when running the code or a failing check reproduces it. Two reviewers agreeing is not a reproduction.

What matters more is what the verifier has seen and what it can touch. The preprint separates a specification-first phase, designed without access to the implementation, from a later phase that reads the code and adds mutation analysis, property-based testing and fuzzing. Once written, the evidence is frozen. When it finds a violation, the verifier hands the builder a minimal counterexample: the input, what happened, and which claim it breaks. It does not hand over the test code or a fix.

In the preprint's study, a verifier working in a fresh context found more of 46 seeded faults than the builder's own tests did, including on a service written by a third party. A verifier from another provider did not add detection. That is a small study on three services with strong builders and precise specifications, and the authors say as much, so we would not claim that switching model never helps. It does suggest that separating context and access is where the value is, and that swapping vendors is not a substitute.

None of this makes the agent's own tests worthless. Writing a failing test first, at an interface a person has agreed, is good practice and catches a great deal. The agent should also run the real system itself and bring back evidence, such as a transcript or a response, because that closes its own loop quickly. This is a first line of defence, not acceptance. For a requirement that matters, the acceptance checks come from the contract and not from the agent's reading of it.

**Figure: From acceptance contract to release**

1. **Acceptance contract.** Written from the ticket and approved by a person before any code exists.
2. **Frozen checks.** Written from the contract, without sight of the code. Read-only to the agent.
3. **Agent change.** The agent implements and runs the checks. It may not edit, skip or delete them.
4. **Independent run.** The checks run in a clean environment, against the change.
5. **Mutation run.** Small deliberate changes to the code show whether the checks can fail.
6. **Assurance statement.** Per requirement: verified, partially verified, violated or not verified.
7. **Release decision.** A named person decides, or has set the standing approval that covered it.

**Counterexample.** A failing check returns the input, what happened and the claim it breaks. Not the test code, and not a fix.

_A person approves the contract before any code exists. The checks are frozen: the agent can run them and see the result, but cannot change them. A failure goes back to the agent as a counterexample. The release decision stays with a named person._

## What the agent may not change

Independence is only real if the agent cannot undo it. Make these things read-only to the agent, and enforce that in the systems it works through, not in its instructions.

- **The acceptance checks and the contract.** The agent may run them and see the result. It may not edit, delete, skip or reorder them.
- **Pipeline and test configuration.** The CI definition, the list of required checks, the test runner's settings and any file that decides which tests run.
- **Branch protection and required reviews.** OWASP's AI Security Verification Standard says agents cannot bypass branch protection, required reviews or required status checks, and that an attempt to change those settings raises an alert.
- **Approval of its own work.** The same standard says autonomous agents cannot approve, merge, sign or deploy artefacts they generated, that the source-control and CI systems must enforce it, and that "policy alone does not satisfy this control". If you delegate merging to an agent for low-risk changes, make that an explicit, narrow grant enforced by the required checks in source control and not by instructions given to the agent, and keep a named person for anything the contract marks as high risk.

Flag changes to existing tests for a person: deleted tests, assertions that became weaker, and new mocks that replace the real dependency a test existed to exercise. OWASP suggests CI rules that flag test deletions and falling assertion counts in agent-generated pull requests. The files that deserve extra scrutiny for security reasons are listed in the securing guide.

## Evidence that the checks can fail

A suite that has never failed on a wrong answer is untested. Coverage does not settle it. The preprint notes earlier research finding that, once suite size is controlled, coverage is not strongly related to a suite's effectiveness. A line can run without anything checking what it did.

Mutation testing asks the direct question. A tool makes small changes to the code, such as flipping a comparison, and reruns the checks. If the checks still pass, the change survived, and the checks have a gap. Read each survivor. It calls for a new check when it is a mistake someone could plausibly make, and for a recorded reason when it is not, because chasing every survivor bloats the suite and every extra test is one more thing to keep green. Mutation runs can be slow on a large codebase, so aim them at the paths where a wrong answer is expensive, not everywhere.

Two other kinds of check help where examples run out. Property-based tests state a rule that must hold for any input, for instance that the total refunded on an order never exceeds what was paid, and let the tool search for a counterexample. Contract tests pin the behaviour at an interface between services, so a change on one side cannot quietly break the other. OWASP's verification standard also asks for differential fuzzing or property-based tests over input validation, authorisation logic and deserialisation in AI-generated code.

Where the risk is in the order of events, such as an approval flow with retries, a model checker such as [TLC for TLA+](https://lamport.azurewebsites.net/tla/tla.html) can explore every order of steps in a small model of the design and find a fault that no example would reach. It checks the model and not the code, so the model can drift from the implementation, and a checker that has never rejected a deliberately broken model proves nothing. Treat it as one layer beside the tests and a run of the real code, and use it only where the cost of a wrong answer justifies the effort.

## A worked example

This example is synthetic. It does not describe a client. A ticket asks for a payments service to require a second approver when refunds on an order go above a set limit. An agent implements it and writes tests: a refund above the limit is held, a refund below it is paid. Everything is green.

The acceptance contract, written from the ticket by a person before the work began, has a claim the agent's tests do not cover: the limit applies to the total refunded against the order, not to each refund. The independent check issues two refunds, each below the limit and together above it. The service pays both. The agent had read "a refund above the limit" as a property of one request, and its tests inherited that reading.

The agent receives only a counterexample: two refunds, both paid, the total exceeds the limit, claim 1 is violated. It fixes the code. The contract also asks for boundary cases at the limit, and a mutation run shows that changing the comparison from greater-than to greater-than-or-equal survives the agent's own tests but is caught by the acceptance checks. The checks now fail when the code is wrong, which is what they are for.

## The assurance statement: what was verified, what was not, who decided

The output is not a pass rate. The preprint's assurance report lists, for each requirement, a status of verified, partially verified, violated or not verified, the techniques behind it, how strong the evidence was and what was left out. It deliberately avoids a single trust score, because there is no basis for adding up unlike evidence into one number. We keep the same shape.

- **Per requirement:** the status, the checks that support it and the counterexamples found along the way.
- **Strength of evidence:** for example which mutations were caught and which survived, and why the survivors were accepted.
- **What was not verified:** assumptions the test environment does not model, and anything the contract marked as open.
- **The release decision:** the name of the person who decided, or who set the standing approval that covered it. For higher-risk changes, it is not the person who asked for the change.

Kept with the change record, this is the answer to "what did you know when you released it?" in an incident review or an audit.

## Where human review stays

Nobody can read every line an agent produces, and pretending otherwise turns review into a rubber stamp. People move to the judgements only they can make. Approving the contract is a judgement that the specification captures what the business wants, and no agent can make it. Accepting a risk listed as not verified is a judgement about the real environment, and it also stays with a person. The preprint makes the same point: neither can be delegated to the builder without bringing back self-certification.

Architecture and the riskiest paths still get a human reading. OWASP's verification standard asks for an elevated review threshold, such as two-person review, for security-critical files that an agent generated or changed, and for the reviewer to be a qualified engineer who is not the identity that asked for the code. The agent does not count as the reviewer.

Spend effort where it is cheapest and most reliable first. Types and constraints that make a wrong state impossible to write come first, then automated checks in the pipeline, then written rules for whatever needs judgement, used sparingly because nothing enforces them. Human review comes last because it scales worst. When the same correction is made twice, turn it into a check, a type or a lint rather than another instruction.

## How this fits release gates in an AI-native SDLC

In an AI-enabled software lifecycle the pieces line up. The plan names the claims that matter before work starts, as described in [Plan first, then route](https://comonad.co.uk/guides/planning-ai-sdlc-orchestration) and in our account of [swarm-driven development](https://comonad.co.uk/guides/swarm-driven-development). The acceptance checks run as required status checks in the pipeline. The assurance statement travels with the change record. When the agent acts on a live system rather than a repository, the equivalent control is an [action gateway](https://comonad.co.uk/guides/ai-agent-action-gateway): the model proposes and the gateway decides, independently of the prompt. The rules for which assistants may be used, and what they may touch, sit in the [AI coding assistant policy](https://comonad.co.uk/guides/ai-coding-assistant-policy), and the wider control model is in [how to set up an AI-enabled SDLC](https://comonad.co.uk/guides/ai-sdlc-enterprise).

The same idea applies to rewriting old code. Showing that a new system behaves like the old one is acceptance written from observed behaviour, which is how [legacy modernisation with AI agents](https://comonad.co.uk/services/legacy-modernisation) is checked. Operating an agent against a system that stays in place, rather than rewriting it, is in [Integrating AI agents with legacy systems](https://comonad.co.uk/guides/integrating-ai-agents-legacy-systems). Our AI-native delivery service builds this into a team's repositories and pipelines as [independent verification](https://comonad.co.uk/services/ai-sdlc).

## How Comonad helps

If you want acceptance contracts, frozen checks and an assurance statement built into your repositories and pipelines, that is the independent verification part of our [AI-native software delivery](https://comonad.co.uk/services/ai-sdlc) service. We do not certify code or processes, and we are tool- and model-neutral.

## Frequently asked questions

### Is AI code review enough?

No. A reviewing model can find things a person would miss, but it sees the same code and can share the same misreading of the requirement. Treat a review finding as a lead: it counts once a failing check reproduces it. Review suggests; independent acceptance checks decide. Keep a person responsible for the release.

### Should a different model write the tests?

It can help, but it is not the main point. The one study we cite found that a verifier in a fresh context caught more seeded faults than the builder's own tests, and a verifier from another provider added no detection. It is a small preprint, so read it as a pointer. What matters is that the author of the checks has not seen the implementation and the agent cannot change the checks.

### Can the agent run the acceptance tests?

Yes. It should run the checks, see the result and receive a minimal counterexample, so it can fix what is wrong. It should not be able to edit or delete them. For the highest-risk paths, such as money and authorisation, you can also hold back a second set of checks that it never sees, because visible tests become something the agent optimises for.

### What is mutation testing and do we need it everywhere?

Mutation testing makes small deliberate changes to the code and checks that the tests notice. Surviving changes show gaps, though a new check is worth adding only for a mistake someone could plausibly make. It can be slow, so use it where a wrong answer is costly, such as authorisation, money and data handling, and rely on examples elsewhere.

### What do we keep for audit?

The acceptance contract with the name of the person who approved it, the frozen checks and their results, the counterexamples found, which mutations survived and why they were accepted, what was not verified, and the name of the person who decided to release, or who set the standing approval that covered it.

## Sources

- [Sion and April: Who Verifies the Builder? Toward Independent Assurance for Agent-Produced Software (arXiv:2610.28667, preprint, not peer reviewed)](https://arxiv.org/abs/2610.28667)
- [OWASP AI Security Verification Standard 1.01, Appendix C: AI-Assisted Secure Coding](https://github.com/OWASP/AISVS/blob/main/1.01/en/0x92-Appendix-C_AI_for_Code_Generation.md)
- [OWASP Cheat Sheet Series: Secure Coding with AI](https://cheatsheetseries.owasp.org/cheatsheets/Secure_Coding_with_AI_Cheat_Sheet.html)
- [ENISA: Technical Advisory on AI-assisted software development (draft v0.4, September 2026)](https://www.enisa.europa.eu/sites/default/files/2026-09/ENISA%20Technical%20Advisory-AI-assisted-software-development-draft.pdf)
- [Leslie Lamport: The TLA+ home page](https://lamport.azurewebsites.net/tla/tla.html)

## Related

- [AI-native software delivery](https://comonad.co.uk/services/ai-sdlc)
- [Securing AI-generated code: review, provenance and evidence](https://comonad.co.uk/guides/securing-ai-generated-code)
- [What is an AI agent action gateway?](https://comonad.co.uk/guides/ai-agent-action-gateway)
- [Integrating AI agents with legacy systems](https://comonad.co.uk/guides/integrating-ai-agents-legacy-systems)
- [How to set up an AI-enabled SDLC in a large organisation](https://comonad.co.uk/guides/ai-sdlc-enterprise)
- [AI coding policy for engineering teams: the clauses to include](https://comonad.co.uk/guides/ai-coding-assistant-policy)
- [Swarm-driven development](https://comonad.co.uk/guides/swarm-driven-development)
