Sub topic 12
Common pitfalls and anti-patterns
This chapter assumes you have read the earlier chapters on requirements, tasks, tests, review gates and spec drift. You should be comfortable with Git and pytest. Here we collect the mistakes that most often make spec-driven work fail, and how to spot and fix each one.
Pitfalls in the spec itself
Vague acceptance criteria
A criterion that cannot fail cannot be tested. An agent will read "fast" or "secure" in its own way, which brings back the inconsistency a spec was meant to remove.
<!-- Weak -->
1. The system SHALL respond quickly and handle errors gracefully.
<!-- Testable -->
1. WHEN a user requests a report of up to 10,000 rows THEN the system SHALL return it within 2 seconds.
2. IF the database is unreachable THEN the system SHALL return HTTP 503 and log the error.A quick check: can you write a test that fails for the first version? If not, rewrite it.
Design that is really code
A design document should record decisions and their reasons: which storage, which boundaries, which trade-offs. If it lists every function body, it duplicates the code and goes stale at the first refactor. Keep the interfaces and the "why". Leave the "how" to the implementation.
Oversized tasks
A task such as "Implement password reset" gives the agent room to make many unreviewed choices. Review becomes a large diff, and a failure is hard to localize. Tasks should be small enough that one test run tells you whether the task is done, and each should name the requirement it covers.
Pitfalls in the process
Over-specifying small changes
A three-line bug fix does not need requirements, design and a task list. Writing all three costs more than the change and trains the team to skip the process. Match the spec to the risk: a short note or a failing test is enough for a small fix.
Rubber-stamping review gates
Approving a spec or a diff without reading it removes the point of the gate. Typical signs are approvals within seconds and reviews that only check whether the tests pass. Review the spec before implementation starts, because a wrong requirement is cheapest to fix then.
Letting the agent rewrite the contract
When a test fails, an agent may change the test, loosen the requirement, or both. Treat edits to specs and tests as separate changes that need a human decision. A standing rule in your instruction file helps:
## Guardrails
- Do not edit files in `specs/` or existing tests to make a failing test pass.
- If a requirement or test looks wrong, stop and explain why.Silent drift
The code changes in a hotfix and the spec does not. Months later, the next agent run reads the old spec and "fixes" the code back. Update the spec in the same pull request as the code, and fail review if behavior changed without a spec change.
Bloated instruction files
An instruction file with hundreds of lines of rules dilutes the ones that matter, and agents may follow them inconsistently. Keep only stable, checkable conventions. Move feature-specific detail into that feature's spec.
Diagnosing a bad result
When an agent's output is wrong, ask where the fault entered before you re-prompt.
Re-prompting without this check treats a spec problem as an agent problem, and the same fault returns on the next run.
Summary table
| Anti-pattern | Symptom | Fix |
|---|---|---|
| Vague criteria | Agent and reviewer disagree on "done" | Rewrite as a measurable WHEN/IF ... SHALL statement |
| Code in the design | Design is wrong after each refactor | Record decisions and interfaces only |
| Large tasks | Huge diffs, hard reviews | Split until one test run verifies the task |
| Spec for tiny changes | Process slower than the work | Use a short note or a test |
| Rubber-stamp review | Defects found after merge | Review the spec before implementation |
| Agent edits tests | Green tests, wrong behavior | Require human approval for spec and test edits |
Exercise
An agent's change passes all tests, but the behavior is wrong. The git diff shows it also edited an existing test. Name two process failures that allowed this, and one change that prevents it.
Show answer
First, the review gate was passed without checking the test edit, so the diff was effectively rubber-stamped. Second, nothing stopped the agent from editing tests to get a green run. Prevention: add a rule to the instruction file that the agent must not edit specs or existing tests to make a test pass, and require a human to approve any such change.