One change, end to end
In Level 1 you saw that a software factory is a pipeline wrapped around coding agents. It is not just the agents. This level follows one change through that pipeline from start to finish. The point to hold on to is that each stage is there to catch a different kind of defect. If two stages catch the same thing, one of them is wasted cost. If no stage catches a kind of defect, it reaches production.
Think of an airport. Check-in confirms you have a ticket. Security scans for dangerous items. Boarding checks that you are on the right flight. No single checkpoint does the whole job, and none of them is meant to.
Here is the change we will follow. A ticket in a TypeScript billing service says: "Invoices for customers in Ireland show the wrong VAT rounding."
[0] Task spec -> [1] Agent run -> [2] Deterministic gates -> [3] AI review
|
[6] Monitor & roll back <- [5] Merge <- [4] Human review <--------+
Stage 0: The task spec catches wrong work
Most bad agent output starts as a bad ticket. Before any code exists, the spec has to settle three things: what "done" means, what the agent must not touch, and how anyone will check the result.
# .factory/tasks/BILL-412.yaml (format is illustrative, not a standard)
title: Fix VAT rounding for IE invoices
goal: Round VAT per line item to 2 decimals, half-up, before summing
acceptance:
- existing test suite passes unchanged
- new case: 3 x 0.335 EUR lines at 23% VAT -> invoice VAT 0.23 EUR
scope:
allowed_paths: [src/billing/vat/**, test/billing/vat/**]
forbidden: [db/migrations/**, .github/workflows/**]
risk: medium # money is involved
What it stops: solving the wrong problem, scope creep, and changes nobody can verify. Who decides: a person. Writing the goal and the risk level is a judgement call. Checking that a ticket has all the fields can be automated.
Stage 1: The agent run catches nothing. It produces.
The agent can be Claude Code, OpenAI Codex, Copilot's cloud agent, or an open-weight model in your own harness. Whichever you use, it works on its own branch in a sandbox and opens a pull request. Treat this stage as untrusted output. The agent's own claim that "all tests pass" is not a check.
Gotcha: an agent that can edit
.github/workflows/can weaken the gates that are supposed to judge it. GitHub's Copilot cloud agent, by default, will not run Actions workflows on its PRs until someone with write access clicks Approve and run workflows. That default exists because workflows can reach secrets. Admins can now turn the approval off, so check what your repository is set to.
Stage 2: Deterministic gates catch mechanical defects
These checks give the same answer every time and need no human. They run before anyone spends attention on the PR.
# .github/workflows/gates.yml
name: gates
on: pull_request
jobs:
gates:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci # lockfile only: no surprise dependency upgrades
- run: npx tsc --noEmit # type errors
- run: npx eslint . --max-warnings 0 # lint and style
- run: npm test # behaviour against existing tests
- run: ./scripts/check-scope.sh # diff stays inside allowed_paths
In Python the same gates would be pip install -r requirements.lock, mypy, ruff check and pytest.
What it stops: code that doesn't compile, broken existing behaviour, style drift, and edits outside the agreed scope. Who decides: nobody. A red check means the PR goes back to the agent and no human sees it yet.
Stage 3: AI review catches likely logic and readability problems
An AI reviewer reads the diff and leaves comments. Examples are the Claude Code GitHub Action (anthropics/claude-code-action), Codex code review (@codex review) and Gemini Code Assist (/gemini review). Codex and Gemini both let you limit comments to higher-severity findings, which keeps the noise down.
What it stops: off-by-one logic, a missed edge case, a confusing name. It cannot prove anything. It gives probable findings, not guarantees. That makes it a filter that saves human time, not a gate you can rely on by itself.
Stage 4: Human review catches judgement problems
This is where you ask whether the change is the right change. Does it fit the design? Is the risk acceptable? Would we be happy maintaining this?
# .github/CODEOWNERS: money code always needs the billing team
/src/billing/ @acme/billing-reviewers
Pair CODEOWNERS with a branch ruleset that requires code-owner approval and passing status checks. GitHub adds one useful default here: when you ask Copilot to open a PR, your own approval of it does not count towards the required approvals, so someone else has to sign off. That is the four-eyes principle, applied for you.
Who decides: a person, always, for anything risky. Later levels cover how low-risk changes can earn their way past this stage.
Stage 5: Merge catches integration collisions
Two PRs can each pass on their own and still break once both land. A merge queue re-runs the required checks against the latest main plus everything queued ahead before it merges. This stage is fully automated.
Stage 6: Monitoring catches what got through
Errors in production, alerts, a revert. Our VAT fix might pass every gate and still show up later as a support ticket about one invoice in a thousand. When that happens, ask which earlier stage should have caught it, then improve that stage.
| Stage | Defect it targets | Decided by |
|---|---|---|
| Spec | wrong or unverifiable work | human (fields checked by machine) |
| Gates | mechanical breakage | machine |
| AI review | probable logic flaws | machine, advisory only |
| Human review | design and risk judgement | human |
| Merge queue | integration collisions | machine |
| Monitoring | escaped defects | machine alerts, human response |
Hands-on exercise: map your baseline
- Choose one recently merged PR in your team's repository and trace its path: where the ticket came from, which CI checks ran, who reviewed it, and how it merged.
- Pull rough timing data:
# last 20 merged PRs: when opened, when merged
gh pr list --state merged --limit 20 --json number,title,createdAt,mergedAt
- Draw your pipeline using the six stages above. For each stage, write the defect it catches, who decides, and MISSING if the stage doesn't exist. Keep this drawing. It is your starting baseline for the rest of the course.
Key takeaways
- A factory is a chain of stages, and each one targets a different kind of defect.
- The spec is the cheapest place to stop bad work, because no code exists yet.
- Deterministic gates run before any human looks, and a red check sends the PR back to the agent.
- AI review gives advice, not proof. Human review is for judgement and risk.
- Merge queues catch collisions between PRs. Monitoring catches what escaped, and every escape should lead you to improve an earlier stage.
- Agent output is untrusted. Protect the workflow files that judge it.