Sub topic 9
Reviewing the spec and the agent's output
This chapter covers the review gates in a spec-driven workflow. It assumes you have read the earlier chapters on requirements, design, tasks, and acceptance tests. It also assumes you can read a Git diff and run a test suite.
Why review is a separate step
An agent can produce a plausible requirements file, a plausible design, and plausible code. Plausible is not the same as correct. The agent has no stake in the outcome, and it will usually agree with whatever the earlier documents say.
Review is where a human supplies what the agent lacks: knowledge of the business, the users, and the cost of being wrong. A spec-driven workflow gives you fixed points to do this. Each point is a review gate, a place where work stops until a person approves it.
Reviewing the spec is much cheaper than reviewing code. A wrong sentence in a requirement costs minutes to fix. The same mistake after the agent has built three modules on top of it costs hours.
The gates
The workflow has four gates. Each one asks a different question.
The gates differ in what they protect against:
| Gate | You review | Main question | Typical defect |
|---|---|---|---|
| 1 | Requirements | Is this the problem we want solved? | Missing case, vague wording, invented feature |
| 2 | Design | Does this approach meet the requirements within our constraints? | Wrong data model, new dependency, ignored existing code |
| 3 | Task list | Can each task be done and checked alone? | Tasks too large, wrong order, requirement not covered |
| 4 | Code and tests | Does the change do what the task says and nothing else? | Scope creep, weakened tests, silent spec changes |
Gate 1: reviewing requirements
Read each acceptance criterion and ask whether you could write a test for it today. If you cannot, the wording is too loose.
Look for these problems:
- Unmeasurable words. "Fast", "secure", and "user-friendly" cannot be tested. Replace them with numbers or observable behavior, such as "within 30 minutes".
- Missing negative cases. Agents tend to write the happy path. Ask what happens with an expired link, an unknown email, or a repeated request.
- Invented requirements. The agent may add behavior you never asked for, such as a rate limiter or an admin screen. Delete it or move it to a separate spec.
- Hidden assumptions. If the criterion says "the user is logged in" and the feature is password reset, the criterion is wrong.
A quick method is to read only the acceptance criteria, without the user story. If the system you would build from them alone would still be correct, the criteria are complete enough.
Gate 2: reviewing the design
The design should explain how the requirements will be met. Check three things:
- Traceability. Every requirement should appear somewhere in the design. If a requirement has no matching component or data structure, the design has a gap.
- Fit with the existing system. The agent may propose a new library, a new table, or a new pattern when the codebase already has one. Ask which existing modules the design reuses.
- Decisions and alternatives. A good design states why it chose an option. A design with no rejected alternatives often means the agent took the first idea.
Do not review the design for style. Review it for decisions that are expensive to reverse, such as data formats, public interfaces, and security boundaries.
Gate 3: reviewing the task list
Approve the task list before any code exists. Check that:
- each task is small enough to finish and check in one sitting;
- each task names the requirement it covers, so a reviewer can find the match;
- tests come before or with the code they check;
- the order has no hidden dependency, such as an endpoint task before the storage task it uses;
- every acceptance criterion is covered by at least one task.
The last check is easy to automate. If your tasks use "Covers: Requirement 1.1" lines, a short script can list requirement numbers that no task mentions. Even without a script, scan the criteria one by one and find the task for each.
Gate 4: reviewing the agent's output
This is the gate people skip, because the tests pass and the code looks fine. Passing tests are necessary and not sufficient. Review in this order.
Step 1: run the checks yourself
Do not rely on the agent's report that tests passed. Run the full suite, not only the new tests. A task that breaks an unrelated test is a common failure.
Step 2: review the file list before the code
Look at which files changed. A task titled "Add a reset token store" should not touch the login module. Unexpected files are the fastest signal of scope creep.
Step 3: check the tests were not weakened
When a test fails, an agent has two ways to make it pass: fix the code or change the test. The second is easier and sometimes happens. Check whether the diff:
- deletes tests, or adds skip markers;
- loosens assertions, such as changing an exact value to "not None";
- widens a tolerance, such as increasing a 30-minute limit;
- edits the spec or requirements file to match the code.
Step 4: map the diff back to the task
For each bullet in the task, find the lines that implement it. For each substantial block of changed code, find the bullet that justifies it. Code with no matching bullet is scope creep. A bullet with no matching code is incomplete work.
Step 5: look for what tests cannot see
Tests check the behavior you wrote down. They do not check error messages that leak information, secrets in logs, missing input validation, or an unbounded loop. Read the code for these.
A small automated gate
Some checks do not need human judgment. This script compares the working tree to a base commit and flags two things: any change under specs/, and any deleted test file. It exits with a non-zero status when it finds either, so you can run it before reviewing the diff or in CI.
import subprocess
import sys
SPEC_PREFIX = "specs/"
TEST_PREFIX = "tests/"
def changed_files(base):
"""Return (status, path) pairs for tracked files changed since base."""
result = subprocess.run(
["git", "diff", "--name-status", base],
capture_output=True,
text=True,
check=True,
)
changes = []
for line in result.stdout.splitlines():
parts = line.split("\t")
if len(parts) >= 2:
# For renames the last field is the new path.
changes.append((parts[0][0], parts[-1]))
return changes
def main():
base = sys.argv[1] if len(sys.argv) > 1 else "HEAD"
problems = []
for status, path in changed_files(base):
if path.startswith(SPEC_PREFIX):
problems.append(f"spec changed: {path}")
if status == "D" and path.startswith(TEST_PREFIX):
problems.append(f"test deleted: {path}")
for problem in problems:
print(problem)
return 1 if problems else 0
if __name__ == "__main__":
sys.exit(main())Run it with python gate.py HEAD from the repository root. Note two limits. git diff does not list untracked files, so a brand-new file will not appear until you stage it with git add. The script also cannot tell a legitimate spec edit from a silent one. It only makes the edit visible so that you decide.
Giving useful feedback
When you reject output, say what is wrong in terms of the spec. "This is not right" gives the agent nothing to work with. Compare:
- Weak: "The expiry logic looks off."
- Strong: "Criterion 1.1 requires expiry after 30 minutes.
redeemaccepts a token at 31 minutes. Add a failing test for that case, then fix it."
Point to the criterion, state the observed behavior, and ask for a test first. This keeps the fix tied to the spec and leaves a regression test behind.
Common review errors
- Rubber-stamping. Approving because the agent sounds confident. Counter this by always running the checks yourself.
- Reviewing too much at once. A diff covering six tasks is not reviewable. Stop after each task, as the project instruction file should require.
- Reviewing only the code. If the requirement was wrong, correct code is still wrong. Gates 1 and 2 exist for this reason.
- Letting the agent grade itself. An agent asked "does this meet the spec?" will usually say yes. Ask for evidence instead: which test covers each criterion.
- Fixing the code by hand and leaving the spec stale. The next agent session will read the old spec and undo your fix.
Exercise
An agent finishes the task "Implement token redemption". All tests pass. The diff shows changes to tokens.py, test_tokens.py, and requirements.md. In test_tokens.py, a test that expected an error at 31 minutes now expects success, and requirements.md now says the link expires after 60 minutes. What do you do?
Show answer
Reject the change and do not merge it. The agent altered both the test and the requirement to match its code, which hides the fact that the code no longer meets the approved criterion of 30 minutes. Restore the original requirement and test, ask the agent to fix tokens.py so the original test passes, and ask why it changed the spec. If 60 minutes might actually be better, discuss that as a separate, explicit spec change before touching code.
Exercise
Name two things the file list alone can tell you at Gate 4, before you read any code.
Show answer
It can reveal scope creep, such as a task about a token store that touches the login module. It can also reveal edits to the spec or deleted and modified tests, which are signs the agent may have adjusted the checks instead of the code. A missing expected file, such as no test file for a task that required tests, shows incomplete work.
Exercise
At Gate 3, a task list has twelve tasks, and none of them mention criterion 1.2 ("same response for registered and unregistered emails"). What is the problem, and how do you fix it?
Show answer
Criterion 1.2 is not covered, so the agent will probably never implement it, or will implement it by accident without a test. Ask for a task that covers it, ideally with a test written first, and place it after any task it depends on. Then re-check that every other criterion has at least one task.