Loading VIBA…

Verification Gates: What to Check Before AI-Written Code Reaches Production

Verification Gates: What to Check Before AI-Written Code Reaches Production

AI-generated code arrives with confidence attached. The model reports that the task is complete, the test suite is green, and the diff looks tidy. None of that is evidence that the change is safe to ship. The distance between "it passes" and "it belongs in production" is where most of the risk lives, and it is a distance you can close with structure rather than vigilance.

This is a workflow for verifying AI-written code: independent review, explicit gates, and a human who decides.

A green test suite is not evidence

When the same model writes the implementation and the tests, both encode the same misunderstanding. The tests confirm the model's mental model of the problem, not the problem itself.

Imagine an agent asked to add pagination to an endpoint. It writes a handler that returns ten rows per page and a test asserting that page two returns ten rows. Both pass. Neither notices that the offset is computed as page times size instead of page minus one times size, so the first row of every page is skipped. The test is not wrong about the code; it is wrong about the world.

Verification starts with a different question. Not "does this pass?" but "what would have to be true for this to be wrong?" Ask the authoring agent to name its assumptions: what it believes about callers, about data shape, about failure modes. Then have something else check those assumptions against the repository.

Separate the author from the reviewer

A model grading its own work is a weak loop. Multi-agent collaboration works better when roles are explicit and the agents disagree productively. In one shared session, you can run ChatGPT, Claude, Gemini and other models side by side, assign each a role, and approve the steps that matter.

A workable split:

- One agent implements the change. - A second reviews for correctness against the actual call sites in the repo. - A third looks only for security and data-exposure problems. - A fourth writes adversarial tests designed to break the first agent's assumptions.

Different models fail in different ways, so disagreement between two reviewers is a signal worth chasing rather than noise to average out. Keep reviewer context independent where you can: an agent that has read the author's reasoning tends to inherit it.

Gates that must pass before merge

Gate one: reproduce the change in a clean environment. Repo testing against the real codebase catches the imports, config and migrations that a model working from a snippet will miss.

Gate two: run the existing suite plus the adversarial tests. If the new tests fail, that is the point — you found it before production did.

Gate three: exercise the actual user path. Unit tests do not tell you whether a form submits, a redirect lands, or an error state renders. UI testing against the running app covers the layer where AI-generated front-end code most often drifts.

Gate four: inspect the diff for scope. Files touched that nobody asked about, new dependencies, disabled checks, and broadened permissions all deserve a second look.

Gate five: confirm failure behaviour. Does the code fail loudly, log enough to debug, and leave the system in a consistent state? A hypothetical invoice export endpoint should return a clear error when storage is unavailable, scope every query to the requesting tenant, and avoid holding an entire export in memory. Those are testable claims, and each one should have a test behind it.

Keep a human at the gate

Autonomy without approval is how a small mistake becomes an incident. Approve the steps that change state: merges, migrations, deploys. Let the agents do the reading, the running, and the arguing, and keep the decision.

Two practical signals help here. Cost per agent shows which parts of the loop are earning their place — if a fourth reviewer never finds anything the third missed, you can drop it. Ranked repair reports turn a pile of findings into an ordered list, so you fix the tenant-scoping bug before the inconsistent log message. For changes that touch user-facing behaviour, beta testing gives you feedback from real usage before the change becomes permanent.

The structure is the safeguard

Verification is a design decision, not a final review. Keep the author away from the verdict, require evidence for each claim, and approve the steps that cannot be undone. The models are capable; the workflow is what makes them safe to rely on.

If you want to run that loop in one place — several models, assigned roles, approval gates, and cost per agent — start at https://viba.guru.

See VIBA: https://viba.guru