跪拜 Guibai
← Back to the summary

AI Code's Bottleneck Is Verification: A Three-Layer Acceptance System

Over the past year, AI-assisted coding has moved from 'trying it out' to our team's default workflow: we hand requirements to the model, and implementations and unit tests come back in minutes. But in that rollout we've found a badly underestimated fact — once AI generates the code, the main delivery bottleneck has shifted from code production to code verification.

A typical pitfall: let AI write both the implementation and its unit tests. If both come from the same wrong understanding, tests pass consistently and business logic drifts consistently. The pipeline is all green, but upstream logic is distorted.

In our review of AI-assisted code (about 310,000 lines), generation speed did improve, but problems like blurred layering, inconsistent practices, and deepened dependency coupling grew in parallel. Industry data also shows that a significant portion of AI-generated code, even after passing QA and pre-production, still needs manual debugging, and many teams go through two or three redeployment cycles before confirming a fix works.

This article shares the three-layer acceptance system we distilled after tripping over these issues: architecture gating, independent contracts + mutation testing, and runtime verification. The goal is one sentence: make AI's generated output verifiable, blockable, and rollbackable.

Layer 1: Use architecture contracts and layered gatekeeping to constrain AI's free play

AI has a most typical problem: it always gets the job done, but its methods often overstep — Controller directly connects to the database, dependencies penetrate module boundaries, sensitive paths get replaced with non-standard implementations. Such issues are easy to miss in code review because each one works.

Our approach is to turn architecture contracts into machine-readable hard constraints:

This layer doesn't touch business logic; it eliminates the most common and hidden structural risks in AI code. It answers the question: does this code exceed the shape the system should have.

Layer 2: Break the 'same-source common error', make acceptance evidence independent of implementation

This is the most critical discipline in the whole system. If tests are also generated by AI from its own implementation, they're just acting alongside the implementation: changed boundary conditions might still pass — because tests and implementation share the same wrong premise.

The solution is to separate spec, verification, and implementation:

  1. Freeze read-only contracts. Before writing, put the business contracts down — key invariants, interface semantics, boundary conditions, and at least one counterexample — in a directory or repository area that AI cannot modify, as the only correctness basis. The contract can be written by humans or drafted by AI then reviewed by humans, but once frozen it doesn't follow implementation changes.
  2. Use mutation testing as an independent referee. Inject small faults into the implementation: change comparison operators, delete null checks, relax the refund cap. If the tests AI wrote can't kill these mutants, they don't cover the contract and aren't trustworthy. PIT (Pitest) can plug directly into Java pipelines, turning 'mutation score' into a hard merge gate.

This layer cuts off the quality illusion that 'tests pass = business is correct'. Tests generated by AI aren't scary; what's scary is that acceptance evidence and implementation come from the same 'subject' — even if that subject is a model.

Layer 3: Use runtime verification to install a behavior fuse in production

Static gatekeeping stops structural overreach, mutation testing stops test-scripting, but neither stops problems that only real traffic exposes: null pointers, boundary state drift, timeout and retry storms.

So acceptance must extend to runtime observability:

This layer's trust philosophy is one sentence: don't trust 'looks right', trust 'behavior evidence'. Behavior evidence observed in the canary stage is more trustworthy than the green-light before merge.

AI will write code faster and faster, but the responsibility for verification will never be automatically handed to the model. This three-layer acceptance system is fundamentally not about limiting AI, but installing brakes and a yardstick for high-speed code production. Don't be fooled by the pipeline's green lights or beautiful unit test reports — the same-source common error trap hides in every AI generation. Guard architecture boundaries, make verification evidence independent, and trust only real runtime behavior evidence, to safely receive the efficiency dividend of AI coding. AI can help us produce code, but the decision of whether code is correct and fits the system's long-term design must remain in human hands.