Sub topic 14
Putting It Together as a Repeatable Review Loop
This chapter assumes you know the pieces from earlier chapters. You should be comfortable with Git branches, staging, and diffs. You should be able to run your project's tests, linter, and type checker. You should also have used a coding agent to edit code at least once. Here you combine those pieces into one loop that you can run after every agent task, whatever its size.
Why a loop and not a checklist
A checklist works once. A loop works repeatedly, because it says what to do when a check fails. Agent work rarely passes on the first try. The usual outcome is a mostly good change with one or two problems. You need a fixed procedure for deciding what to keep, what to send back, and when to stop.
The loop has three properties:
- Each step produces evidence. You rely on command output and on code you read, not on the agent's summary.
- Each correction is bounded. You name the files and the problems. You do not say "try again".
- The loop has an exit. After a set number of rounds without progress, you narrow the task or take over.
The loop at a glance
Step 1: Scope the task and define done
Before the run, write down two things: what the agent may change and how you will know it is finished. A good definition of done is a command, not a feeling. For example, "the test suite passes and no file outside src/config/ and its tests changed."
Write this in the prompt as well. The agent then has the same boundary you will review against.
Step 2: Start from a clean baseline
Create a branch and confirm the working tree is clean. Everything that changes afterwards is the agent's work.
git switch -c agent/rename-config-loader
git status --short # no output means the working tree is clean
git log --oneline -1 # note the commit the agent starts fromRecord the starting commit. You will use it as the comparison point for every later command.
Step 3: Triage before you read
When the run ends, do not open files yet. Get the shape of the change first. git diff does not list untracked files, so pair it with git status.
The commands below can go into a small script. Save it as review-triage.sh and pass the starting commit as the argument.
#!/usr/bin/env bash
set -euo pipefail
base="${1:?usage: review-triage.sh BASE_COMMIT}"
echo "== All touched files (includes untracked) =="
git status --short
echo "== Size per file =="
git diff --stat "$base"
echo "== Deleted files =="
git diff --diff-filter=D --name-only "$base"
echo "== Added lines that silence tests, lint, or types =="
git diff -U0 "$base" | grep -nE '^\+.*(@pytest\.mark\.(skip|xfail)|# noqa|# type: ignore)' || echo "none found"Run it with bash review-triage.sh <commit>. Then compare the file list to the scope you wrote in step 1. Any file outside the scope is the first item on your review list. A large diff in a file you expected to be small is the second.
The marker search only catches Python-style suppressions. Adapt the pattern to your stack, for example eslint-disable, @ts-ignore, #[allow(, or t.Skip(.
Step 4: Read in a deliberate order
Read in this order:
- The file list. You already did this in triage.
- Interfaces. Read changed function signatures, public types, configuration keys, and exported names. A change here affects every caller.
- Tests. Check what the tests now assert. Weakened tests make every later check meaningless.
- Implementation. Read the bodies last, with the interfaces and tests in mind.
When a refactor moves code, two options reduce noise:
git diff --color-moved=zebra # highlight moved code so real edits stand out
git diff -w # ignore whitespace-only changesMoved code is shown in a different color, so what remains is the real edit. Use -w with care. In languages where whitespace is meaningful, such as Python or YAML, a whitespace change can change behavior.
What to look for while reading
Keep a short list of defects in mind. Each one has appeared in agent output often enough to check on purpose:
| Defect | What it looks like in the diff |
|---|---|
| Scope creep | Files or hunks unrelated to the task |
| Invented APIs | Calls to functions or options that do not exist in your dependency version |
| Weakened tests | Removed assertions, `skip`, `xfail`, loosened expected values |
| Silent behavior change | A default value, error type, or ordering that changed without being mentioned |
| Incomplete rename | Old name still present in strings, docs, or config files |
For the last row, a text search is cheap and catches what the type checker cannot:
git grep -n "load_config" # replace with the old name; any hit outside history needs an explanationStep 5: Verify with your own checks
Run the project's checks yourself. Do not rely on the agent's statement that they passed. The agent may have run a different command, run only a subset, or run them before its last edit.
pytest -q # tests
mypy src # type check
ruff check . # lintSubstitute your project's real commands. Then run the changed code on at least one real input, for example by starting the program or calling the function from a REPL. Tests can pass while the feature is broken if they never exercise the changed path.
Look at the test changes separately:
git diff -- tests/If tests changed, ask whether the requirement changed or whether the test was bent to fit the code. Only the first is acceptable.
Step 6: Decide what to keep
After checks and reading, each hunk falls into one of three groups: correct, correct but out of scope, or wrong. You do not have to treat the change as all or nothing. Stage the good hunks and discard the rest.
git add -p # stage only the hunks you accept
git commit -m "Rename config loader (reviewed agent changes)"
git restore -p . # interactively discard remaining unwanted hunks in the working treeThe commit contains only what you chose. git restore -p removes unstaged hunks permanently, because they were never committed. If you are unsure about a hunk, commit the good parts first, then use git stash on the remainder instead of discarding it.
Step 7: Steer with bounded feedback
If problems remain, send one message that states what is acceptable, lists each problem with its file, limits the next edit, and asks for a verifiable report.
The change to src/config/loader.py is correct. Two problems remain:
1. You edited src/billing/invoice.py, which is outside this task. Revert that file.
2. tests/test_loader.py now skips test_missing_file. Restore the test and fix the code so it passes.
Do not change any other files. When finished, run the project's test suite and report the exact command and its result.Because you committed the accepted hunks in step 6, the next diff shows only the new round of changes. You review it with the same triage script and the new starting commit.
Step 8: Know when to leave the loop
Each round should shrink the list of problems. Use these rules:
- Re-run with the same task when the problems are small and independent, such as one stray file.
- Narrow the task when the same kind of error repeats. Split a large change into two or three steps, such as the interface change first and the call-site updates second.
- Take over when the agent keeps reintroducing the same defect after specific feedback, or when the fix is quicker for you to type than to describe.
A practical cap is two corrective rounds. If round two still has the same problem as round one, further rounds rarely help.
Step 9: Turn repeated corrections into instructions
If you gave the same correction twice, move it into the project's persistent instructions, the file your agent reads at the start of each session. Keep entries short and checkable. Good examples are "Run pytest -q and report the command and result", "Do not edit files outside the paths named in the task", and "Never skip or delete a failing test; fix the code".
Avoid vague entries such as "write good code". They cannot be verified in a diff.
A worked pass
Suppose you asked for a rename of load_config to read_config across src/config/ and its tests.
- You branch, note commit
a1b2c3d, and state the scope in the prompt. - Triage shows six changed files. One is
src/billing/invoice.py, which is out of scope. - Reading interfaces, you find the new
read_confighas a changed default forstrict. That is a silent behavior change. - The marker search finds a new
@pytest.mark.skipintests/test_loader.py. - You run the suite yourself. It passes, but only because of the skip.
- You stage the correct rename hunks with
git add -pand commit them. You discard the billing edit withgit restore -p. - You send the bounded message from step 7, adding the default value to the list.
- Round two shows only the loader and its test. You re-run triage and the checks, then commit.
- You add "Never skip a failing test" to the instructions file.
Exercise
The agent reports "all tests pass". Triage shows no deleted files and no out-of-scope files, and your own test run also passes. Which check from the loop could still reveal a problem, and why?
Show answer
Check the test diff and search added lines for suppression markers. Tests can pass because they were skipped, marked xfail, or had assertions loosened. A passing run proves nothing if the tests were weakened. Also run the changed code on a real input, because tests may not cover the changed path.
Exercise
You committed the hunks you accepted and the agent's second round introduces new edits. Why is committing before the second round useful, and what do you pass to the triage script?
Show answer
The commit saves the reviewed work and makes the next diff contain only the second round's changes. You pass the new commit hash as the base, so the triage output covers only what changed since your last review.
Exercise
The same out-of-scope file edit appears in three consecutive rounds despite specific feedback. List two reasonable next actions.
Show answer
Narrow the task into smaller steps that name the files explicitly, or take over and make the edit yourself. You can also add a rule to the project instructions about editing only named paths. Further identical re-runs are not a good choice.