跪拜 Guibai
← All articles
Code Standards · AI Programming

AI code is cheap, verification is expensive: a 6-layer checklist for reviewing AI-generated code

By 郑恩赐 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

This shifts the verification budget from reading syntax to testing intent and boundaries. It also names the AI-specific failure modes Western teams will hit — hallucinated dependencies, tautological tests, and indirect prompt injection into coding agents — and gives a practical delete-or-rewrite trigger to avoid drowning in a bad diff sunk cost.

Summary

AI has made writing code cheap, but it made verifying code expensive. A patch that takes AI 5 minutes to write can take a human 45 minutes to validate. The six-layer checklist starts by running every machine check: compile, lint, type checking, and the existing test suite. Only after those gates pass does the human step in, and the goal is explicit: catch code that passes CI but is still wrong.

Those errors come from structural causes. AI predicts patterns rather than reasons, its tests often mirror its own implementation instead of the requirement (tautological tests), and AI-based reviewers share the generator's training bias, so their failures correlate. The cost is measurable: CodeRabbit's analysis of 470 production PRs found AI code raises about 1.7x more issues than human code, with 75% more logic and correctness errors.

The checklist covers all of that: review intent before syntax, read tests before implementation, check boundary and security cases, verify whether the diff is atomic and rollbackable, and when to delete. Layer 6 includes concrete rewrite triggers — a diff over 300 lines, more than 2 new dependencies for a small feature, an intent you cannot explain after 10 minutes. A portable Python script demonstrates Layer 1 plus Layer 4 by flagging hardcoded secrets, eval/exec, pickle, SQL string concatenation, and dangerous subprocess calls before any human looks at the receipt.

Takeaways
— A patch can be written by AI in 5 minutes, but human verification typically takes 45 minutes.
— The biggest risk is hallucinated correctness: code that compiles, passes tests, and looks normal but is logically wrong.
— AI errors differ from human errors for three structural reasons: pattern matching rather than reasoning, shared assumptions between generated code and tests, and lack of an external baseline.
— Letting the same AI write code and tests produces tautological tests that validate the implementation, not the requirement.
— CodeRabbit measured AI-generated code producing about 1.7x more issues than human code, with 75% more logic and correctness errors in 470 real GitHub PRs.
— AI-generated tests had better boundary variety (0.62 vs 0.32) but a worse flaky rate (0.41 vs 0.30) than human tests.
— The six layers are: machine gates (compile/lint/type/test), intent, tests and boundaries, security, scope and rollback, and whether to rewrite.
— Rewrite triggers include a diff over 300 lines, more than 2 new dependencies added for a small feature, and an intent that cannot be explained after 10 minutes.
— Security review must cover injection, missing authorization, hardcoded secrets, mass assignment, hallucinated dependencies, and indirect prompt injection into coding agents.
— A standard-library Python script scans for hardcoded secrets, eval/exec, pickle, SQL concatenation, and dangerous subprocess calls to serve as Layer 1's gate.
— Authentication does not equal authorization; each branch that trusts a logged-in user must also check permission.
— Non-existent package names can be registered by attackers, so every hallucinated dependency is a possible supply-chain entry point.
Conclusions

The tautological-test warning is the sharpest point: if the same model writes code and its tests, the tests can never fail on the requirement, only on the implementation. That means a green suite gives almost no signal that the problem being solved is the right one.

The Layer 6 rewrite criteria (300-line diff, 2+ new dependencies, 10 minutes to explain intent) overturn the default "fix it" instinct. With AI, a clean re-generation from a sharper prompt can cost less than untangling a large, vague diff, so the economic equation favors deletion more often than in human-written code.

Paragraph 6's indirect prompt injection is underappreciated. Attackers can hide instructions in AGENTS.md or PR descriptions and turn the developer's own coding agent into an unwitting accomplice, so the threat model now includes the agent's context, not just the code it outputs.

Concepts & terms
Hallucinated correctness
AI-generated code that compiles, passes tests, and looks normal but is logically incorrect. It happens because the model is pattern-matching, not reasoning, so it confidently produces a wrong implementation. CI cannot catch it because it only catches obvious errors like bad syntax or a missing import.
Tautological test
A test generated from the implementation instead of from the requirement. It passes because it validates what the code does, not what the code should do. When the same AI writes both code and tests, the tests become tautological, and a green suite no longer proves the requirement is met.
Indirect prompt injection
An attack where hidden instructions are placed in files that an AI coding agent reads, such as issue bodies, PR descriptions, AGENTS.md, or MEMORY.md. The agent then executes those instructions as part of its normal workflow, turning the developer's own tool into an attacker-controlled actor.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗