Sub topic 6
Breaking work into small, verifiable tasks
This chapter assumes you have written requirements with testable acceptance criteria and a short design document, as covered in earlier chapters. It also assumes you can read Python and pytest, use Git, and have prompted a coding agent before. Here you turn an approved design into a task list that an agent can execute one item at a time and that a reviewer can check.
Why the task list is the unit of control
Requirements say what must be true. The design says how the system will be shaped. Neither tells the agent what to do next. If you hand an agent a whole design and say "implement this", you are back to an open-ended prompt. The agent picks its own order, makes its own scope decisions, and produces one large change that nobody can review properly.
A task list restores control at the point where code is actually written. Each task limits what the agent may change, names the requirement it serves, and gives you a way to check the result. A good task list has these properties:
- Single outcome. The task can be described in one sentence without "and".
- Small diff. A reviewer can read the resulting change in a few minutes.
- Traceable. The task names the acceptance criteria it satisfies.
- Verifiable. A command, usually a test run, shows whether the task is done.
- Ordered. Earlier tasks do not depend on later ones.
Anatomy of a task
Here is the task list for the password-reset requirement used throughout this tutorial.
## Tasks
- [ ] 1. Add a reset token store
- Store the token, its issue time, and a used flag.
- Covers: Requirement 1.1, 1.3
- [ ] 2. Implement token redemption
- Reject expired tokens and tokens that were already used.
- Write tests first. Covers: Requirement 1.1, 1.3
- [ ] 3. Add the reset-request endpoint
- Return the same response for registered and unregistered emails.
- Covers: Requirement 1.2Each task has three parts. The title says what changes. The bullets give the specifics that bound the work. The Covers: line links the task back to numbered acceptance criteria. That link lets a reviewer ask "does this change satisfy criterion 1.3?" instead of "does this look reasonable?".
Task 2 also says "Write tests first". This is an instruction about process. It tells the agent to write failing tests before the implementation, so the tests describe the requirement and are not fitted to code that already exists.
Ordering tasks by dependency
Order tasks so that each one builds on work that is already merged and tested. A common sequence is data structures, then core logic, then interfaces, then integration. In the password-reset example, the endpoint comes last because it calls redemption and storage.
The loops back to each task matter. A failed gate does not move the agent forward. It sends the agent back to the same task with the failure output as new context.
Tasks that do not depend on each other can run in parallel, for example on separate branches. Do this only when they touch different files. Two agents editing the same module will produce merge conflicts that cost more than the parallelism saved.
Sizing tasks
Sizing is a judgment call. Use the review as your measure: if you cannot review the result in one sitting, the task was too large.
| Symptom | Likely cause | Fix |
|---|---|---|
| Diff touches many unrelated files | Task mixes layers, such as storage and HTTP | Split along the layer boundary |
| Agent asks which approach to take | Task leaves a design decision open | Settle it in the design, then restate the task |
| Task title contains "and" | Two outcomes in one task | Split into two tasks |
| Task is "create file X" with no behavior | Too small to verify | Merge it into the task that gives the file behavior |
| Tests cannot be written until later tasks exist | Wrong ordering | Reorder, or add a stub the test can use |
Tasks that are too small cause a different problem. A list of forty one-line tasks adds overhead and encourages rubber-stamp reviews. A good task usually changes one behavior and includes its tests, which often means one to three files of production code plus their tests.
Defining "done" for each task
A task is done when its check passes, not when the agent says so. Write the check into the task or into the project instruction file. Prefer checks in this order:
- An automated test that encodes the acceptance criterion.
- A command with observable output, such as a type checker, linter, or build.
- A manual check with exact steps, used only when automation is not practical.
The tests below encode criteria 1.1 and 1.3 for tasks 1 and 2.
from datetime import datetime, timedelta, timezone
import pytest
TOKEN_TTL = timedelta(minutes=30)
class TokenError(Exception):
pass
class ResetTokens:
def __init__(self):
self._issued = {}
self._used = set()
def issue(self, token, now):
self._issued[token] = now
def redeem(self, token, now):
if token in self._used:
raise TokenError("already used")
issued = self._issued.get(token)
if issued is None or now - issued > TOKEN_TTL:
raise TokenError("expired or unknown")
self._used.add(token)
T0 = datetime(2026, 1, 1, tzinfo=timezone.utc)
def test_token_expires_after_30_minutes():
tokens = ResetTokens()
tokens.issue("abc", T0)
tokens.redeem("abc", T0 + timedelta(minutes=29)) # still valid
tokens.issue("def", T0)
with pytest.raises(TokenError):
tokens.redeem("def", T0 + timedelta(minutes=31))
def test_token_can_be_used_only_once():
tokens = ResetTokens()
tokens.issue("abc", T0)
tokens.redeem("abc", T0)
with pytest.raises(TokenError):
tokens.redeem("abc", T0)The tests pass the current time in as an argument instead of reading the clock. This is a design choice that makes time-dependent criteria testable without sleeping. If your task list says "reject expired tokens" but the design reads datetime.now() inside the function, the criterion is hard to test. That is a sign to fix the design before the task.
Checking that tasks cover the spec
Traceability only helps if it is complete. Two failures are common: a criterion that no task covers, which never gets built, and a task that cites a criterion that does not exist, which usually means the task is inventing scope. A small script can check both. It reads Requirement N headings and the numbered criteria beneath them, then compares the resulting ids with the Covers: lines.
import re
import sys
from pathlib import Path
REQ_HEADING = re.compile(r"^###\s+Requirement\s+(\d+)\b")
CRITERION = re.compile(r"^(\d+)\.\s+(?:WHEN|IF)\b")
COVERS = re.compile(r"Covers:(.*)")
ID = re.compile(r"\d+\.\d+")
def criteria(path):
found = set()
req = None
for line in Path(path).read_text().splitlines():
heading = REQ_HEADING.match(line)
if heading:
req = heading.group(1)
continue
item = CRITERION.match(line)
if item and req:
found.add(f"{req}.{item.group(1)}")
return found
def covered(path):
ids = set()
for line in Path(path).read_text().splitlines():
match = COVERS.search(line)
if match:
ids.update(ID.findall(match.group(1)))
return ids
def main(requirements_path, tasks_path):
wanted = criteria(requirements_path)
cited = covered(tasks_path)
for cid in sorted(wanted - cited):
print(f"UNCOVERED: criterion {cid} has no task")
for cid in sorted(cited - wanted):
print(f"UNKNOWN: a task cites {cid}, which is not in the requirements")
return 1 if (wanted ^ cited) else 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1], sys.argv[2]))Run it as python check_coverage.py specs/password-reset/requirements.md specs/password-reset/tasks.md. It exits with status 1 on any mismatch, so you can run it in CI next to the tests.
Running tasks with the agent
Give the agent one task at a time. A prompt such as "Do task 2 from specs/password-reset/tasks.md. Do not touch other tasks." keeps the scope narrow. The project instruction file can hold the standing rules, such as stopping for review after each task and running pytest before reporting done, so you do not repeat them.
After the agent finishes a task, check four things:
- The tests named in the task exist and pass when you run them yourself.
- The diff touches only files that the task plausibly needs.
- No test was deleted, skipped, or weakened to make the run pass.
- The agent did not tick off or rewrite other tasks.
Then commit, one commit per task, with the task number in the message. This gives you a clean revert point and a history that mirrors the task list.
Edge cases
A task cannot be verified automatically. Some work, such as a UI layout or an email template, has no good unit test. Write the manual check as exact steps and expected results in the task. Do not leave it as "looks right".
The agent finds a missing requirement mid-task. It should stop and report, not guess. Update the requirements, then the design if needed, then the task list. Changing only the code creates drift.
A task turns out to be too large. If the agent's change grows past what you can review, stop it, discard or stash the partial work, and split the task. Do not let it finish and hope the review goes well.
Refactoring tasks. These have no new acceptance criteria. Use the existing tests as the check, and require that they pass unchanged before and after. State this in the task.
Tests that pass for the wrong reason. An agent can write a test that asserts nothing meaningful. Spot-check by temporarily breaking the implementation and confirming that the test fails.
Common errors
- Writing tasks as activities ("investigate caching") instead of outcomes with a check.
- Omitting the
Covers:line, which breaks the link between code and criteria. - Letting the agent work through several tasks in one session without review.
- Putting design decisions inside tasks. Tasks should carry out the design, not make it.
Exercise
A task reads "Add the password-reset endpoint and send the email and log the request". It covers criteria 1.1 and 1.2. Name two problems with this task and rewrite it as a better set of tasks.
Show answer
Problems: it has three outcomes joined by "and", so the diff will be large and hard to review, and a failure cannot be traced to one change. It also cannot be verified with one check. A rewrite: Task A, "Add the reset-request endpoint returning the same response for registered and unregistered emails" (Covers: 1.2, check: a test comparing the two responses). Task B, "Send the reset link with a 30-minute expiry on a registered address" (Covers: 1.1, check: a test that a message is queued with an expiring token). Task C, "Log reset requests without recording whether the address was registered", added only if a requirement calls for logging. If none does, leave it out or add the requirement first.
Exercise
Your coverage script prints "UNKNOWN: a task cites 2.1, which is not in the requirements". Give two possible causes and say what you should change in each case.
Show answer
Cause one: the task is correct but the requirements lack the criterion, so the spec is incomplete. Add the criterion to the requirements first, then keep the task. Cause two: the task invented scope or contains a typo in the id. Fix the id if it is a typo. If the task is extra scope, remove it or get a requirement approved for it. In both cases, change the spec before the code.