Sub topic 12
Common pitfalls and anti-patterns
This chapter assumes you have read the earlier chapters on the requirements, design, and tasks phases. It also assumes you can write a basic automated test and review a Git diff. Spec-driven development fails in recognizable ways. Most failures come from a small set of habits, and you can spot and fix them once you know what they look like.
Why pitfalls cluster
A spec-driven workflow has three kinds of artifacts: the spec documents, the tests that encode them, and the code the agent writes. Each pitfall in this chapter breaks one of the links between these artifacts, or breaks the human review that holds the links in place.
The agent reads the spec as input and treats it as authoritative. Defects in the spec therefore pass straight into the code, and they pass in with confidence. A vague spec does not cause an error message. It causes plausible code that does the wrong thing.
Pitfalls in the requirements
Vague acceptance criteria
The most common anti-pattern is a criterion that sounds precise but cannot be checked. Compare these:
1. The system SHALL handle password resets quickly and securely.
2. WHEN a user submits a registered email address THEN the system SHALL send a reset link within 60 seconds that expires after 30 minutes.The first line has no observable behavior. The agent must invent what "quickly" and "securely" mean, and a different run may invent something different. The second line names a trigger, a response, and two numbers a test can assert.
You can catch much of this mechanically. The script below checks that each numbered criterion contains SHALL and flags common vague words. Save it as lint_spec.py and run python lint_spec.py specs/password-reset/requirements.md.
import re
import sys
from pathlib import Path
VAGUE = [
"fast", "quickly", "user-friendly", "intuitive", "robust",
"secure", "securely", "appropriate", "as needed", "etc",
"properly", "easy", "easily",
]
CRITERION = re.compile(r"^\s*\d+\.\s+(.*)$")
def check(text):
problems = []
for number, line in enumerate(text.splitlines(), start=1):
match = CRITERION.match(line)
if not match:
continue
body = match.group(1)
if "SHALL" not in body:
problems.append((number, "no SHALL: behavior is not stated"))
for word in VAGUE:
if re.search(rf"\b{re.escape(word)}\b", body, re.IGNORECASE):
problems.append((number, f"vague word: {word!r}"))
return problems
if __name__ == "__main__":
text = Path(sys.argv[1]).read_text(encoding="utf-8")
problems = check(text)
for number, message in problems:
print(f"line {number}: {message}")
sys.exit(1 if problems else 0)A lint like this cannot judge meaning. It finds only the obvious cases, so treat it as a first filter before human review.
Only the happy path
Agents implement what the spec mentions. If the requirements describe only successful flows, the code will have no defined behavior for expired links, reused links, unregistered emails, or malformed input. The password-reset example from earlier chapters has three criteria, and two of them are not happy paths. That ratio is deliberate.
For each criterion, ask what happens when the input is missing, duplicated, too large, too late, or from someone who is not allowed to do this. Write the answers as IF ... THEN ... SHALL criteria.
Implementation details inside requirements
Requirements say what the system does. Design says how. Mixing them locks the agent into choices nobody reviewed as choices. "The system SHALL store tokens in a Redis hash" is a design decision hiding in a requirement. If the team later moves off Redis, the requirement becomes false even though user-visible behavior did not change.
Keep storage, libraries, and class names in the design document. Requirements should stay true across any valid implementation.
Pitfalls in tasks and context
Tasks that are too large
A task such as "Implement password reset" gives the agent room to make dozens of unreviewed decisions. The resulting diff is too big to review properly, so reviewers skim it. Good tasks are small enough that you can read the whole diff in a few minutes and trace each change to a criterion.
A sign that a task is too large: its "Covers" line lists most of the requirements.
Tasks with no link to requirements
If a task does not name the criteria it satisfies, you cannot check it, and the agent can add behavior nobody asked for. Keep the Covers: line on every task. When a diff contains behavior that maps to no criterion, treat it as a finding. Either the spec is missing a requirement or the agent added scope.
Letting the agent change the spec to match the code
Agents under pressure to finish often take the easy path. A test fails, so they edit the test. A criterion looks hard, so they reword it. Your project instruction file should forbid this explicitly, as in the AGENTS.md example from the project instructions chapter: "Do not change requirements. If one looks wrong, say so and ask."
Also check this in review. Look at the diff of specs/ and tests/ separately from the diff of src/. Any change to a spec or an existing test during an implementation task needs a stated reason.
Instruction files that grow without limit
An instruction file is read on every run, so each line costs context and competes with the task for attention. Files that accumulate every past incident become long and contradictory. The agent then follows some rules and ignores others, and you cannot predict which.
Keep the file to stable rules: where specs live, how to verify work, naming and layout conventions. Put feature-specific detail in the spec for that feature. When you add a rule, delete or merge an older one.
Pitfalls in verification
Tests that restate the implementation
A test is only evidence if it can fail when the code is wrong. Tests that compute the expected value with the same logic as the code can never fail. This happens often when the agent writes the code and the tests together.
from datetime import datetime, timedelta, timezone
TOKEN_TTL = timedelta(minutes=30)
def is_expired(issued, now):
return now - issued > TOKEN_TTL
T0 = datetime(2026, 1, 1, tzinfo=timezone.utc)
def test_weak_mirrors_implementation():
now = T0 + timedelta(minutes=45)
assert is_expired(T0, now) == (now - T0 > TOKEN_TTL)
def test_strong_uses_literal_boundaries():
assert not is_expired(T0, T0 + timedelta(minutes=29))
assert not is_expired(T0, T0 + timedelta(minutes=30))
assert is_expired(T0, T0 + timedelta(minutes=31))The first test passes even if someone changes > to >= or the TTL to 3 minutes. The second test pins the behavior at the boundary that the criterion states. Write or review the tests from the criteria, not from the code.
Treating "tests pass" as "spec satisfied"
Passing tests show only that the covered behavior works. If a criterion has no test, nothing fails when it is broken. Keep a simple traceability habit: for every criterion, you should be able to name the test that covers it. A table in the spec folder is enough.
| Criterion | Test | Status |
|---|---|---|
| 1.1 | test_token_expires_after_30_minutes | passing |
| 1.2 | none yet | uncovered |
| 1.3 | test_token_can_be_used_only_once | passing |
An uncovered row is a to-do item, not a pass.
Trusting the agent's report
Agents sometimes report a task as done without running the tests, or after running a subset. Require the command and its output in the report, and rerun it yourself before approving. Your instruction file can state this: "Run pytest before reporting a task as done."
Pitfalls in process
Approving without reading
Review gates exist because the spec is the cheapest place to catch an error. Fixing a wrong criterion costs one line. Fixing it after the agent has built three modules on it costs a rewrite. Approving a long generated spec with a quick scroll removes that benefit while keeping the ceremony.
Read the requirements for missing cases and the design for decisions you disagree with. Check that every requirement is covered by at least one task.
Letting the spec drift
A spec is accurate on the day it is approved. After that, bug fixes, urgent changes, and manual edits move the code away from it. A stale spec is worse than none, because the next agent run trusts it and undoes the fix.
Update the spec in the same change as the code, and make this a review check. When you find drift, decide which side is right. If the code is right, change the spec. If the spec is right, file a task to fix the code.
Spec for everything, or spec for nothing
Two opposite mistakes affect how much spec to write:
- Over-specifying small changes. A full requirements, design, and tasks set for a typo fix or a one-line config change costs more than the change and trains the team to skip the process.
- Under-specifying risky changes. Authentication, payments, data migrations, and public APIs need written criteria because mistakes there are expensive and hard to reverse.
A rough rule: if you could describe the change and its check in two sentences, a prompt and a test are enough. If the change touches several modules, has security or data impact, or will be handled by more than one person or session, write the spec.
Treating the spec as a one-way waterfall
Specs are not frozen contracts. Implementation often shows that a requirement is unclear or impossible. Stopping to revise the spec is the process working correctly. The anti-pattern is continuing to code around a known-bad requirement, or rewriting it silently.
Diagnosing from symptoms
When agent output disappoints, the symptom often points to the pitfall. This flowchart maps common symptoms to the first thing to check.
A review checklist
Use this list at each gate:
- Does every criterion state a trigger and an observable result?
- Does each requirement have at least one failure or edge case?
- Are technology choices kept out of the requirements?
- Does every task link to criteria, and can you review its diff in minutes?
- Does every criterion map to a test with literal expected values?
- Did the diff change any spec or existing test, and is there a reason?
- Is the instruction file short, consistent, and free of feature-specific detail?
Exercise
A task says "Add the reset-request endpoint". The agent's diff adds the endpoint, a rate limiter, and an audit log. The tests pass. Which pitfalls does this show, and what do you do?
Show answer
The task was not linked tightly to criteria, and the agent added behavior that no requirement covers (the rate limiter and audit log). Passing tests do not show the extras are wanted, because nothing tests them. Check whether they are needed. If so, add criteria and tasks for them, with tests, before accepting them. If not, remove them from the diff. Also add a "Covers:" line to the task so scope is checkable next time.
Exercise
This criterion is in a spec: "The system SHALL respond quickly and handle errors gracefully." Rewrite it as two testable criteria in WHEN/IF ... THEN ... SHALL form, and name the pitfall.
Show answer
The pitfall is vague acceptance criteria. One rewrite: "1. WHEN a user submits a registered email address THEN the system SHALL return an HTTP 202 response within 2 seconds. 2. IF the email service is unavailable THEN the system SHALL return HTTP 503 and SHALL NOT report the reset as sent." Other numbers and statuses are fine if the team agrees on them and a test can assert them.
Exercise
Your test suite is green after an agent finishes, but a reviewer finds that tokens now expire after 29 minutes instead of 30. Give two ways the process could have caught this.
Show answer
First, a test with literal boundary values (accepting a token at 29 and 30 minutes, rejecting one at 31) would have failed, which counters tests that mirror the implementation. Second, a traceability table showing that criterion 1.1 had a boundary test would have shown whether the criterion was only loosely covered. A review of the diff against the criterion would also have caught the changed constant.