Dev.to AI πŸ€– Ai πŸ‘ 2 πŸ“– 4 min read

8 checks before you merge code an AI wrote

I build with AI coding agents every day. They're fast, and most of what they write works. But "most" is doing a lot of work in that sentence, and the bugs they leave behind tend to look perfectly reasonable. So before a

I build with AI coding agents every day. They're fast, and most of what they write works. But "most" is doing a lot of work in that sentence, and the bugs they leave behind tend to look perfectly reasonable.

So before anything an agent writes gets merged, it goes through the same short list. Here it is.

TL;DR

  1. Run it, don't just read it
  2. Check every package actually exists
  3. Read the whole diff
  4. Check the security basics
  5. Test the edge cases it skipped
  6. Make sure errors aren't swallowed
  7. Confirm the APIs and options are real
  8. Explain it before you merge it

1. Run it, don't just read it

Code from an agent usually reads well. That's the problem. Clean names and tidy structure make it easy to skim and approve.

Run the actual path the change touches: click the button, submit the form, call the endpoint. Run the tests. "It compiles" and "it looks right" aren't the same as "it works".

2. Check every package actually exists

Models sometimes import packages that don't exist. In a USENIX Security 2025 study, researchers generated 576,000 code samples with 16 models and found that at least 5.2% of the packages recommended by commercial models, and 21.7% from open-source models, didn't exist.

That's more than a broken install. Attackers can publish a real package under a name models keep inventing, and wait for someone to install it. People call this slopsquatting.

Before you install anything new from an AI suggestion, look it up:

npm view some-package name version repository.url

If it doesn't exist, has no repository, or was published last week with almost no downloads, stop and check before you add it.

3. Read the whole diff

Agents often change more than you asked for: a renamed variable here, a "cleaned up" function there, a formatting pass over a file you didn't mention. Each change might be fine. Together they make the real change hard to review.

git diff --stat
git diff

Start with --stat to see which files changed. If a file you didn't expect is in the list, find out why before you read anything else. Keep the agent to the change you asked for, and undo the rest.

4. Check the security basics

Veracode's 2025 GenAI Code Security Report tested 80 coding tasks across more than 100 models. The generated code introduced a security vulnerability in 45% of cases, and models failed to defend against cross-site scripting 86% of the time.

The common misses are the classics:

// Built from user input: open to SQL injection
db.query(`SELECT * FROM users WHERE email = '${email}'`);

// Parameterized: the input stays data, never code
db.query("SELECT * FROM users WHERE email = $1", [email]);

Also check that:

  • user input is escaped before it's shown on a page
  • permission checks happen on the server, not only in the UI
  • no keys, tokens or passwords are written into the code
  • error messages don't leak internal details to users

5. Test the edge cases it skipped

Agents write for the happy path. Try the inputs a real user will eventually send:

  • empty strings, null and missing fields
  • a very long input, or one with emoji and accented letters
  • clicking submit twice
  • a slow or dropped connection halfway through
  • dates near midnight and in other time zones

If any of these break, ask the agent to handle that case specifically, then test it again yourself.

6. Make sure errors aren't swallowed

A common pattern in generated code looks safe and hides every failure:

try {
  await saveOrder(order);
} catch (e) {
  console.log(e);
}

The order fails to save, the user sees nothing, and the log line gets lost. Handle the error properly or pass it on:

try {
  await saveOrder(order);
} catch (err) {
  logger.error("saveOrder failed", { orderId: order.id, err });
  throw err; // let the caller tell the user something went wrong
}

7. Confirm the APIs and options are real

Packages aren't the only thing models invent. They also invent function parameters, config keys and options that would make sense but don't exist, or that existed in an older version.

If a call or a setting looks unfamiliar, check the documentation for the version you actually have installed. A setting that's silently ignored is worse than an error, because nothing tells you it didn't work.

8. Explain it before you merge it

The last check is the simplest. Could you explain every line of this change to a teammate in a code review?

If not, ask the agent why it did it that way, then check the answer yourself rather than taking it on trust. If you still can't explain it, don't merge it. You're the one who'll be fixing it at 2am.

The short version

AI agents changed how fast code gets written. They didn't change who's responsible for it. Run it, read it, check it, and only merge what you understand.

What would you add to this list? I'd like to hear the checks other people run.

I'm Kweku Hexer, a software engineer from Ghana and co-founder and CEO of Hexerize, where we build useful apps for everyone.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.