Sub topic 7
Failure modes to look for in agent changes
This chapter assumes you can read a Git diff and run your project's tests, linter, and type checker. It also assumes you have already triaged the change set and read it in order. Here you learn what to look for while reading.
Why agent defects look different
A coding agent produces code that reads well. Names are sensible, comments are tidy, and the summary sounds confident. Most defects are therefore not syntax errors. They are plausible changes that do something other than what you asked. Knowing the usual patterns lets you scan for them on purpose.
The common failure modes
| Failure mode | What it looks like in the diff |
|---|---|
| Scope creep | Files outside the task changed, or unrelated cleanups mixed in |
| Invented APIs | Calls to functions, flags, or config keys that do not exist in your dependency versions |
| Silent behavior change | A default, return value, or error path changed during a "refactor" |
| Weakened checks | Skipped tests, loosened assertions, added lint or type suppressions |
| Partial rename | Old names remain in strings, docs, configs, or dynamic lookups |
| Duplicated logic | A new helper that repeats one already in the codebase |
| Swallowed errors | New broad `except` blocks that hide a failure instead of fixing it |
Tests that were weakened to pass are covered in the next chapter. The rest of this chapter covers the other modes.
Scope creep
Compare the file list with the task you wrote. Any file you did not expect is a question. Ask why it changed before you read how. Unrelated edits make the diff harder to review and can introduce bugs in code you were not looking at.
Invented APIs
Agents sometimes call a method that sounds right but does not exist, or one that exists only in a different version. Type checkers and imports catch many of these. Dynamic code, such as getattr or string-keyed config, can hide them until runtime. When a call looks unfamiliar, check it against the installed package:
python -c "import yaml; print(hasattr(yaml, 'safe_load'), hasattr(yaml, 'load_safe'))"This prints True False. The second name looks plausible but is not part of PyYAML.
Silent behavior changes
Refactors should keep behavior the same, but agents often "improve" edge cases along the way. Watch for changed defaults, changed exception types, and reordered operations. This example looks like a harmless cleanup:
-def load(path):
- with open(path) as f:
- return json.load(f)
+def load(path):
+ try:
+ with open(path) as f:
+ return json.load(f)
+ except OSError:
+ return {}A missing file used to raise an error. Now every caller silently gets an empty dict. Nothing in the diff announces this, and a test that never covered the missing-file case still passes.
Partial renames and duplication
A rename the agent finished in code may still be missing from places a type checker does not see. Search for the old name across the whole repository, including YAML, Markdown, and string literals:
git grep -n "load_config"For duplication, search for the behavior before accepting a new helper. If a similar function already exists, ask the agent to reuse it.
A scanning routine
Run this check hunk by hunk. A hunk that fails any question goes into your feedback to the agent, or into a selective revert.
Exercise
An agent refactors a function and its diff replaces raise ValueError on bad input with return None. The test suite passes. Which failure mode is this, and why did the tests not catch it?
Show answer
This is a silent behavior change. No existing test covers the bad-input path, so the changed error behavior went unnoticed. Restore the exception, and add a test that asserts the ValueError.