Sub topic 3
Scoping the Task and Defining Done Before the Run
What this chapter assumes
You know basic Git (branches, commits, diffs), and you can run your project's tests, linter, and type checker from the command line. You have used a coding agent at least once. This chapter covers what to prepare before the agent starts editing.
Why scope comes first
You can only review a diff against a stated intent. Suppose you ask an agent to "clean up the config code". Nearly any change then looks defensible, and you cannot tell useful work from scope creep. A written scope turns review into a comparison: does the diff match the brief?
The four parts of a scoped task
A good brief has four parts:
- Goal: one sentence describing the outcome.
- Boundaries: the files or directories the agent may change, and the ones it must not touch.
- Constraints: rules such as "no new dependencies", "do not change public interfaces", and "do not skip or delete tests".
- Done criteria: commands you will run and the results that count as success.
Here is a brief for a rename task:
Task: Rename load_config to load_settings in src/config/loader.py and update every caller.
Allowed: src/config/, files that call load_config, tests/test_loader.py (rename only).
Do not change: src/billing/, CLI flags, dependency files.
Do not weaken tests: no skips, no xfail, no removed assertions.
Done when:
- grep -rn "load_config" src tests prints nothing
- pytest passes
- ruff check . and mypy src report no new errors
Report the exact commands you ran and their results.Write done as commands
"Works correctly" cannot be checked. "pytest exits with status 0" can. Each criterion should be something you can run yourself, because the agent's own summary is not evidence (a later chapter covers this).
Record a baseline before the run. Without one, you cannot tell a failure the agent caused from one that was already there.
git switch -c agent/rename-config-loader
pytest -q 2>&1 | tail -n 3
ruff check . 2>&1 | tail -n 3
mypy src 2>&1 | tail -n 3Note the failures you see. If three tests already fail, your done criterion is "no new failures", not "all green".
Size the task
| Size | Example | Review cost |
|---|---|---|
| Too broad | "Modernize the config system" | The diff is large and its intent is unclear |
| Right-sized | "Rename one function and update its callers" | The diff can be checked against a short list |
| Too narrow | "Change line 42" | Faster to do by hand |
If you cannot describe the expected file list in a sentence or two, split the task. Two small runs that you review separately are easier to check than one large run.
Common mistakes
- Listing only positive goals. If you do not say what is off limits, the agent may fix "related" problems in other files.
- Done criteria the agent can game. "The tests pass" is satisfied by skipping the failing test. Pair it with a rule against weakening tests.
- Skipping the baseline. Pre-existing failures later look like regressions, or regressions get dismissed as old failures.
Exercise
You ask an agent to "make the loader faster" and set the done criterion as "all tests pass". Name two problems with this brief and rewrite one of them.
Show answer
The goal has no measurable outcome, so you cannot tell whether the run succeeded. There are also no boundaries or test-integrity rule, so the agent could edit unrelated files or skip slow tests to pass. A rewrite of the goal: "Reduce the time of load_settings on tests/data/large.toml, measured with the benchmark command, without changing its return values or any files outside src/config/."