Verifying AI-Generated Code by Failure Mode: A Practical Guide for Developer QA
Verifying AI-Generated Code by Failure Mode: A Practical Guide for Developer QA
Verifying AI-Generated Code by Failure Mode: A Practical Guide for Developer QA
AI-generated code has an uncomfortable property: it usually compiles, it usually reads well, and it usually passes the tests that came with it. That last part is the trap. When the same model writes the implementation and the tests, a green run tells you the code agrees with itself — not that it agrees with your requirements.
Verification before production starts with a different question. Not "does this look right?" but "which specific ways does code like this fail, and have I checked each one?" Treating verification as a set of failure modes, each with its own check, is more reliable than reading a diff until it feels fine.
The failure modes that survive a passing test suite
Most problems in AI-written code cluster into a handful of categories. Naming them makes them checkable.
Plausible but wrong external calls. A method that exists in a similar library, arguments in the wrong order, a signature that changed two versions ago. The generated tests pass because they encode the same wrong assumption. This is the most common defect that unit tests cannot catch, because nothing in the codebase knows what the real API does.
Silent fallbacks. A broad catch that returns a default, a retry loop with no ceiling, an or {} that turns a missing record into an empty success. These hide failure rather than handle it, and they look defensive in review.
Tests derived from the implementation. The assertion was written by reading the function, not the ticket. Change the function and the test changes with it, which means the test measures nothing.
Dependency and version drift. A package that exists but behaves differently at the pinned version, or a transitive dependency pulled in as a side effect. The source diff looks small; the lockfile diff does not.
Unexercised edges. Empty collections, unicode input, timezone boundaries, nulls, duplicate IDs, concurrent writes, a second run of a migration that was only ever run once.
Environment assumptions. A hardcoded localhost, an environment variable name that exists on your machine, a default port that collides in production, a config value with no validation.
Checks that target each one
Each failure mode has a cheap, specific test.
- Trace external calls against real documentation or type stubs. Then run the code path twice against a stub server: once returning the documented success shape, once returning an error shape. If the error shape produces a silent default, you have found a fallback worth deleting. - Break the fallback on purpose. Replace the swallowed exception with a re-throw in a scratch branch and run the suite. If nothing fails, no test covers that path. That is a fact you now know. - Write the acceptance test from the requirement before reading the generated test file. Then compare. Where the two disagree, one of them is wrong, and it is worth knowing which. - Read the lockfile diff with the same attention as the source diff. New transitive dependencies are a real supply-chain and behaviour risk, not noise. - Parameterise the edge cases rather than hand-writing them. Empty, huge, unicode, duplicated, out-of-order, clock-skewed. For example, you could run a refund calculation against an amount of zero, a negative amount, and a currency with no minor unit. - Run side-effecting operations twice. Migrations, workers, webhook handlers and schedulers should be idempotent. Running them once proves nothing about the second run. - Run the strict static analysis you already have. Type checkers and linters catch a real slice of the API-misuse and null-handling categories for almost no effort.
None of these require reading the whole diff line by line. They require knowing what you are looking for.
Assign roles instead of asking one model to grade itself
A model asked whether its own output is correct tends to agree with itself. The fix is structural: give different models different jobs, and treat disagreement as the signal.
This is where multi-agent collaboration earns its place in developer QA. Imagine a pull request that changes how refunds are calculated. You could assign one agent to re-derive the calculation from the ticket alone, a second to write tests from the ticket alone without seeing the diff, and a third to read the diff specifically for error handling, retries and data access. Where the three outputs disagree is where you look first — and it is a much shorter list than the whole changeset.
VIBA is built for that pattern: run several models such as ChatGPT, Claude and Gemini in one shared session, assign each a role, approve key steps yourself, and see the cost per agent so you know what a review actually spent. It also offers UI testing, repo testing, beta testing and ranked repair reports, which means the adversarial pass can happen against a running system rather than only against text.
What "verified" should mean before merge
A useful bar: every external call traced to documented behaviour; every error path exercised at least once; tests derived from requirements rather than from the implementation; dependency changes reviewed deliberately; side-effecting operations run twice; and a rollback path you have actually considered. If you cannot produce that evidence, the code is not verified. It is just quiet.
Quiet code ships bugs with confidence. Verifying by failure mode turns a judgement call into a checklist you can run in the time you have — and gives you something concrete to point at when someone asks why the review took an hour.
If you want to run that kind of adversarial review with several models in one shared session, start at https://www.viba.guru.
See VIBA: https://www.viba.guru