Reviewing agent code: where to start and what usually goes wrong
Review of agent code starts with the task and the tests, not with functions: the costliest mistake is solving the wrong task or weakening checks. Typical failures are invented library calls, duplicated helpers, swallowed errors, happy-path-only code and going beyond the task. Check a test with a deliberate breakage, ask to split an oversized pull request, and leave the verdict to a human.
Agentic development · The cycle
An agent's pull request looks clean: green tests. What is wrong with it anyway?
An agent added a limit on login attempts. Tests are green, the description is tidy. The diff contained: a new library nobody asked for, an empty catch around the counter write and a test that only checks "does not throw". Code from an agent is read more carefully than from a colleague: it writes fast and with confidence, and its mistakes look plausible. Review is the main way a human answers for a change.
How it works and why. An agent optimises for "passes and looks finished", not for "correct in all cases". So its typical mistakes are systematic: what tests do not check and what is hard to see at a glance stays half-done. The review order is built to filter big problems first (the wrong task, the wrong limits) and only then read details.
Review order
What an agent most often gets wrong.
- Invents what does not exist: a method call, a parameter or a library option that is not there, or an outdated way. Unfamiliar calls are checked against docs or types.
- Duplicates: writes a new helper although the project has one.
- Swallows errors: an empty
catch, a default value that hides a failure, "success" on failure. - Covers only the happy path: empty values, big volumes, a repeated request and time zones are ignored.
- Leaves the task limits: changes a format, config or other people's files.
- Leaves litter: debug output, commented-out code, temporary files.
- Describes what it did not do: the pull request description does not match the diff.
Example: a swallowed error. A fragment from the login attempts pull request:
async function registerFailedLogin(userId: string) {
try {
await redis.incr(`login:fail:${userId}`);
} catch {
// ignore counter errors
}
}
A test "does not throw" always passes, even if Redis is down. Then the attempt limit is silently disabled and a password guessing attack runs unhindered. The reviewer asks direct questions: what happens if Redis is down and is there a test that proves it. The right behaviour depends on requirements (deny login or allow with a warning), so this is a human decision, not the agent's. The fix: rethrow or log and return an explicit result, and add a scenario with an unavailable store to the test.
How to read an agent's diff
Description and a green badge
The description is written by the agent and may not match the changes. A green badge does not say what was checked.
Task, tests, diff, run
The description is compared with the diff, tests are read, risky places are asked about directly, the code is run by you.
Practical techniques. Compare the change description with the diff itself, not with the agent's reasoning. Ask directly about an unclear fragment: why this way, what happens on an empty input. Make a trial breakage: if the test stays green after a deliberate error in the code, it proves nothing. Substituted tests and bypassed checks are covered in the article on tests with an agent and in the section on control.
Limits and alternatives. A second agent can make a first pass looking for the obvious, but it does not see what is not visible in the code (requirements, agreements), and the final decision stays with the human. Static analysers and linters remove part of the mechanical problems (litter, unused code, known dangerous patterns) and save attention for the substance. A pull request that is too big is sent back to be split: it cannot be read carefully.
Common mistakes.
- Reading only the description and the CI result: mistakes that tests do not catch stay unnoticed.
- Judging code without remembering the task: well-written code that solves the wrong problem passes review.
- Trusting an unfamiliar library call: it may be invented or outdated.
- Accepting a big diff "because tests are green": there was no careful reading.
Check yourself
An agent's diff has an empty catch around a database write and the test only checks "does not throw". Why is it dangerous and what do you add?
Answer
A write failure goes unnoticed while the test is green whatever happens. Add a scenario with an unavailable database and an expected result (an error or an explicit denial), and either remove the catch or log and return an explicit status.
Why does review of agent code start with the task and the tests rather than reading functions in order?
Answer
The costliest mistake is solving the wrong task or weakening the checks. That is visible by matching the task with the tests, while detailed reading of code that solves the wrong problem is wasted.