Deliver a task
You are the orchestrator. You don't write product code and you don't review it. You hand the building and the independent review to separate roles, and you decide when the work moves on.
First read storage and the shared task record, resolve $FACTORY_ROOT, and acquire the selected task's lock before changing it. All task state and evidence stay in that shared catalog, never in product commits.
ready → building → [gate] → reviewing → [STR run] → (checking) → done → PR
↑ | | | | |
└─ gaps ──┘ | | | |
└─ blocking findings ┘ | | |
└─ failed STR step ───────────────┘ | |
└─ failed manual check ──────────────────────────┘ |
└─ reopened on request ─────────────────────────────────────┘
Two side states pause delivery until the developer acts: waiting-for-approval (a changed definition awaits re-approval, see edit an approved task) and blocked (the builder needs a developer decision, or the environment can't be fixed). A task waiting for another task is not blocked: it stays ready and lists that task in depends_on.
1. Start
This orchestrator owns only code delivery. Resolve the complete requested ID through task identity. If given a design task, stop and direct the developer to /factory:design deliver <id>; do not load its rules or launch its agents. Unknown or conflicting identity/kind requires a developer decision.
First run the settle script as that skill describes, so a task whose PR was merged while it wasn't done no longer holds back the tasks that depend on it. Mention what it settled and its Needs attention lines, then go on. If the developer named a task that settle left under Needs attention with a merged PR, follow settle with the developer instead of the steps below.
- Pick the complete ID the developer gave, or the highest-priority eligible ready code task using shared priority and selection, including its deterministic ID tie-break. To choose automatically, run the overview script from the product checkout with
--track code --format json and take its recommendation; when it is null, report its reason. Exclude design tasks and unresolved blockers/dependencies. Missing/invalid priority or ambiguous ready-task identity prevents automatic selection; report it rather than guessing or backfilling. Explicit selection does not bypass approval/status/dependency gates. For a code task already building, reviewing, checking, waiting-for-approval or blocked, follow Resume existing delivery below instead of creating a new branch or replacing its recorded base. For a done task the developer wants changed, follow reopen a done task. When the developer asks to finish the PR of a done task with no delivery.pr, or to retry publishing one whose open PR failed to update or retarget, or to move one whose stacked parent was merged, take the lock and check that HEAD, submitted and delivery.approved match and the passing run's evidence folder exists; then resume at Finish step 4 without reopening. Otherwise report what is missing.
- If the task is
draft, stop and suggest running define first.
- Check that the working tree is clean. If it isn't, ask the developer how to proceed. If the task's
implements field references a design, require the design task itself to be done with an approval whose revision matches implements.revision before starting. Missing, stale or rejected approval means this code task can't start: leave it ready, report it, and ask for the approved handoff rather than reviewing or producing designs here.
- Resolve the base commit as project repository describes, recording the project settings first if they are missing. For a stacked task, use the parent's branch instead. Never use a design/prototype branch or blindly use current HEAD. Create
factory/<full-id>-short-slug (for example factory/DEV-003-settings) from the resolved base SHA. If a factory/<full-id>-* branch already exists for a task that is still ready, an earlier start was interrupted: reuse it only if it points exactly at the newly resolved base, otherwise ask. Use an isolated worktree if this checkout belongs to another task/track or concurrent session; never switch it underneath active work. A new worktree has none of the source checkout's ignored files, such as .env; prepare its environment when a check needs them. Keep using the same absolute catalog task path; do not copy or cherry-pick records onto the branch. Read linked design handoff/approval records from the catalog and inspect the exact external/prototype revision without merging it. If the task or evidence cannot be located, stop and ask.
- Run the baseline check on the new branch before anything changes it.
- After acquiring the task lock, re-read priority, status, dependencies and approval evidence from the record itself, not by re-running the overview, which shows your own lock as making the task ineligible. If eligibility or the automatic ranking changed, release the lock and reassess rather than acting on a stale overview. Then persist the task's
delivery header field, including base_ref and baseline, and set status: building before launching agents.
Baseline check
Run the project's automated checks that the gate will re-run (tests, lint, format, type checks, build) on the task branch while it still equals the base, as running checks describes. A failure caused by the environment, such as a missing .env, a service that isn't running or a port in use, is not a baseline failure: fix the environment and run the check again, or follow the environment rule in running checks when you can't. If they all pass, record baseline: []. For each check that still fails:
- If a baseline decision in the project settings covers these failures, apply it without asking.
- Otherwise ask the developer once, listing every failing check and its failures together, to choose:
- fix first: stop. Remove the task branch (and worktree) you just created, which has no commits, leave the task
ready, and suggest fixing the baseline in its own task.
- ignore: the check still runs at the gate. Failures already present at the base don't count; new ones do.
- waive: the check is not required for this delivery.
- Record each decision in
delivery.baseline with the check, its failures as a list of files, tests or rule IDs, each with its error when the check prints one (for example `tests/api.test.ts` "search": timeout), and the decision. A failure that names no file, test or rule, such as a build's command error, is recorded by its error alone. When the developer says a decision should also apply to future deliveries, add it to the settings' baseline decisions.
Ask once per delivery; on later rounds and on resume, use the recorded delivery.baseline. The one exception is a failure outside the diff that sorting it finds already on the base: ask about that one once.
Use the production baseline and any approved designs as references. Do not merge a throwaway prototype as implementation; connect the UI to the actual system and run production verification. Code tasks without a design dependency do not wait for the design track.
Resume existing delivery
- Acquire the task lock and re-read its
delivery, submitted and implements fields and its status. Use its recorded branch/base, not the current checkout's HEAD or a newly fetched baseline.
- Locate the owning checkout with
git worktree list --porcelain. Verify its shared Git directory, checked-out branch, and the recorded base object; require git merge-base --is-ancestor <base> <branch> to succeed. Missing references, a removed/moved checkout, a different repository/branch, or rewritten history require a developer decision before updating references or continuing. Do not silently recreate a branch or switch an unrelated checkout. A transferred catalog does not authorize adopting a same-named branch in another clone.
- Confirm no other session owns that checkout and inspect its working tree. Unexpected/uncommitted product edits require agreement on preservation before resuming; never discard them or assume a clean unrelated checkout is the task's checkout. Pass the verified owning checkout to agents along with branch/base and catalog paths. Then run steps 1–2 of the base check, so the newest base commit is computed against a freshly fetched tip: when the branch already contains base commits newer than
delivery.base, for example from the host's Update branch button, record that base before the next gate or review.
- Whenever a task returns to
reviewing, or resumes from a side state it entered from reviewing without a re-approved definition change, and delivery.approved equals submitted and HEAD, the review is done: remove any leftover sandbox for the task and run the STR again (section 5), without a new gate or review. Otherwise, for reviewing, require the checkout HEAD to match submitted; if it changed or is missing, stop for a decision and rerun the gate before a new review. Re-run the gate's automated checks to rebuild the verification evidence before starting or restarting a review. For a checking task, require HEAD to match submitted and continue at Finish (section 6) with the developer's results. If the developer needs the steps again, derive them from the criterion and the diff. For a waiting-for-approval task, apply the developer's answer as edit an approved task describes, then continue from the step it paused in (its latest <from> → waiting-for-approval log line names the status), logging the status change. For a blocked task, resume only once the developer has resolved the reason in its latest → blocked log line, and continue from that <from> status. For either side state, when that <from> is itself a side state, follow the earlier log lines back until you reach a status that isn't one. Otherwise continue the recorded build/review step after rechecking linked design approval. Never infer approval from the recovered status.
2. Build
Use the delegate skill to start the builder role with this job. Give it:
- the absolute task file path and resolved catalog root,
- the verified owning checkout, branch and base commit,
- the
delivery.baseline decisions, so it leaves ignored baseline failures outside its scope alone, and the settings' known noise entries,
- the running checks rules, and any environment you prepared, such as copied env files,
- on later rounds, the gaps or review findings it must fix (quote them).
Don't pass it your own conversation history.
3. Gate: is it ready for review?
The builder's report is a claim. Check it before you spend a review on it. Pass to review only when all of these hold:
- [ ] Every acceptance criterion is addressed in the report. A criterion that only a person can check is listed under Manual checks with the steps to check it; it passes the gate as
pending and is not missing evidence.
- [ ] The builder ran the project's documented checks for the change in the running checks order, and the report shows the commands, their results and the prerequisites they needed.
- [ ] You re-ran those automated checks yourself, the same way, and they pass. A failure counts only as sort a failure decides. An
ignored check passes when its only failures are the ones recorded in delivery.baseline; a waived check is not required.
- [ ] The changes are committed on the task branch (
git status is clean, git diff <base>..HEAD is not empty).
- [ ] The diff stays within the task and contains no
.factory/ records or status-only commits. Required docs/factory/ and .agents/skills/ changes are product changes, not workflow state. Out-of-scope edits count as a gap.
- [ ] The report has an STR that covers every acceptance criterion that isn't a manual check.
- [ ] The builder has no open question that only the developer can answer.
Persist each manual check in delivery.manual_checks with result: pending. Every passed gate resets all entries to pending, including ones the STR run added, because earlier results checked an earlier revision. If a check fails, send the specific gaps back to the builder (step 2); an environment failure is yours to fix before you re-run, not a gap. After 2 failed gates in a row, stop and ask the developer. If the builder needs a decision from the developer, set status: blocked with the question as the log reason and ask.
4. Review
Record the owning checkout's full HEAD SHA, read with git rev-parse HEAD, as submitted, never a SHA from the builder's report; if the report names a different commit, tell the developer in the final summary. Then set status: reviewing in the catalog. Use the delegate skill to start the reviewer role in a fresh context with this job. Give it only:
- the absolute task file path and resolved catalog root,
- the verified owning checkout, base commit and branch, so it can read
git diff <base>..HEAD,
- the verification evidence (commands, results and prerequisites) from your gate re-run, including the
delivery.baseline decisions,
- the pending manual checks and their steps,
- for a reopened task or one sent back by a base update, the previously reviewed SHA from its most recent reopen or base-update log line, expanded to the full SHA with
git rev-parse <short SHA>^{commit}.
Never pass the builder's reasoning or your conversation. The reviewer must judge the result, not the story behind it. Your gate re-run is the independent run of the automated checks, so the reviewer doesn't repeat the whole gate; it re-runs a command only when it doubts the evidence.
- approve → record the approved SHA as
delivery.approved (it equals submitted) and go to step 5.
- changes requested → send only the blocking findings back to the builder (step 2), then gate and review again. Non-blocking findings go into the final summary.
- After 3 review rounds without approval, stop and ask the developer.
If review introduces follow-up tasks, use the priority handoff rules when they are defined. Reassess pending order with the developer, without interrupting this delivery or treating a suggestion as authorization to start another task.
5. Verify the running app
After the last review round approves, run the builder's steps to reproduce (STR) once against the final implementation. The task stays reviewing meanwhile. The checkout HEAD must equal submitted and delivery.approved; if it doesn't, stop for a decision.
- Take the STR from the builder's report for the approved revision. Each step names what to open or run, the action and the expected result, and the acceptance criterion it shows.
- Run every step yourself, in an app sandbox when a step needs the running app or touches its data. Use seeded or fake data and test accounts only, never real credentials or personal data. Follow UI steps with a browser automation tool (prefer the project's Playwright, headless) and save a screenshot of each screen the path visits. Run command or API steps as written and keep their output.
- Save the evidence in
$FACTORY_ROOT/evidence/<full-id>/<short submitted SHA>/: str.md with each step, its result and its screenshots, and the screenshots as NN-<screen>.png in path order.
- Stop the app and the sandbox's services, and remove the sandbox, also when a step fails.
- A step fails because of the environment (a port, the sandbox, a flaky run) → handle it as running checks describes and run the step again. A step fails because the app doesn't do what it should → it is a gap: clear
delivery.approved, set status: building (log reason "STR step failed"), send the step, its expected and actual result and the screenshot to the builder (step 2), then gate, review and run the STR again. After 2 failed STR runs in a row, stop and ask the developer.
- A step can't be automated, for example a visual comparison with a design, a real external account or hardware, or because no browser tool is available or the app can't be sandboxed: add it to
delivery.manual_checks as pending, under its criterion and with its steps; don't add a criterion twice. The developer is involved only for these.
6. Finish
- When the task has a
delivery.pr, for example after a reopen, read its state again (gh pr view <PR> --json state): someone may have merged it during delivery. If it was merged, don't set done or open another PR: release the lock and follow settle with the developer. For a stacked task, check whether its parent was merged. Then check whether the base moved. If it did, offer to update the branch before going on.
- If
delivery.manual_checks has a pending check, ask the developer to run it, giving the steps. Record each answer in the check's result with by and date. A failed check clears delivery.approved, sets status: building (log reason "manual check failed") and goes back to the builder (step 2) with what the developer saw, then gate, review and the STR again. If the developer defers the checks, set status: checking (log reason "manual checks deferred"), report as in Finish step 6 including each check's steps, release the lock and stop. When the developer later reports results for a checking task, take the lock, record them and continue here. A task with a pending or failed manual check is never done.
- When the task has a
delivery.pr and the project publishes PRs (not local-only, and not pull_requests: off), publish first (open the pull request) and set done only once that PR is updated. If it turns out merged, don't set done: release the lock and follow settle with the developer. If the push or the PR update fails, don't set done either: keep the status, release the lock and report as that procedure's last step describes; /factory:deliver <ID> retries from here. Set status: done and tick the acceptance criteria. Save the task file update in the shared catalog; do not create a status commit.
- Open the pull request, when step 3 didn't, unless the project is
local-only or its settings say pull_requests: off. Record its URL as delivery.pr.
- Release the task lock before handing back.
- Tell the developer: what changed, the branch name, the PR link (or, without a PR, the STR and the evidence folder), the verification evidence, the manual check results and any baseline decisions, whether the base moved and how it was handled, any tasks stacked on this one, the build and review rounds, and any non-blocking findings. Never merge.
- Add a journal entry with the
journal skill (type delivery). Record the build and review rounds, failed gates and anything the factory got wrong or made awkward: a weak gate, a noisy review, a missing instruction.
Update a moved base
When the base check reports that the branch already contains base commits newer than delivery.base, set delivery.base to that commit and add the base updated log line from the task record before anything else, so the gate judges only the task's own changes. This counts as a base update for the rules below.
After any base update, re-run each ignored failure in delivery.baseline on the new base before the next checks run, whether those are the next gate or a clean update's re-run. Drop an entry whose failure no longer happens there, so a regression on the branch can't hide behind a decision about the old base. Say so in the summary.
Tell the developer what the base check found: the new commits, the files they share with the task's diff and whether the task's changes apply to the tip without conflicts. Then ask whether to update the branch onto the tip. If the developer already chose to leave it for the same tip, the branch in delivery.base_ref still exists and, for a stacked task, its parent hasn't merged since, don't ask again.
- Leave it: continue. Mention it in the final summary. This choice is not offered when the base branch no longer exists, or when a stacked task's parent was merged, even if its branch is kept: merging the child into the parent's branch then would leave its changes out of the integration branch.
- Update: rebase the task's own commits onto the tip:
git rebase --onto <tip> <delivery.base>. Never merge the tip in. When the branch is already on the remote, fetch it first and require git merge-base --is-ancestor <remote tip> HEAD; if the local branch doesn't contain the remote tip yet, bring those commits in as reopen a done task step 2 describes before rebasing. Note the pre-rebase HEAD and that remote tip: the push's lease is pinned to it, as open the pull request step 4 describes.
- Clean (the check found no conflict and no shared files): update the branch yourself. If the rebase stops on a conflict anyway, run
git rebase --abort so the branch is back where it was, and take the conflict path below. Check that the tip is an ancestor of the new HEAD and that the task's own changes are the same: git diff --raw --no-abbrev <old base> <old HEAD> and git diff --raw --no-abbrev <tip> HEAD must be identical; if they aren't, take the conflict path. Then re-run the gate's automated checks and run the STR (section 5) with the new HEAD as the revision and the tip as the base. The diff, sort a failure and its runs on the base, the sandbox and the evidence folder (<short new HEAD>) all use them, and section 5's HEAD check compares against the new HEAD. Until both pass, submitted and delivery.approved still name the old HEAD, so an interrupted update stops at resume for a decision instead of skipping them. A failure is a gap, as at the gate: set delivery.base to the tip and submitted to the new HEAD first, untick every acceptance criterion, so the builder and the next gate judge the diff from the new base, then clear delivery.approved and set status: building (log reason "base update failed checks, reviewed ") before the builder gets the gap. If the STR adds a pending manual check, first record the update as below, then continue at Finish step 2 before publishing; a done task goes back to reviewing first (log reason "base update added a manual check"). Once both pass, set delivery.base to the tip, record the new HEAD as submitted and delivery.approved, and add the base updated log line from the task record. The review and the manual check results still stand, because the changes they judged are the same, so the task keeps its status.
- Conflicts or shared files: for a
done task, follow reopen a done task from step 1, with "base update" as the reason; its first step catches a task that was already merged. Otherwise clear delivery.approved and set status: building (log reason "base update, reviewed "). Then send the builder (step 2) the job to rebase the branch onto the tip the same way and resolve the conflicts within the task's scope. Set delivery.base to the tip once it has. Then gate, review and the STR again. The reviewer gets the previously reviewed SHA, as for a reopened task.
Open the pull request
- Check the base again, as in Finish step 1, in case it moved after that. If it moved, offer the update before publishing anything.
- Check the evidence. It goes to a remote branch that everyone with read access can see, and pushed history is hard to take back. Read
str.md and look at every screenshot. Leave out or redact anything sensitive: secrets, tokens, env values, personal data. Never put env files in the evidence folder. If you're unsure, ask the developer before pushing.
- Publish the evidence. All evidence goes to one
factory-evidence branch on the recorded remote, in folders by task: <full-id>/<short submitted SHA>/. It shares no history with the product: create it as an orphan branch only if the remote doesn't have it. Fetch it first and work in a temporary worktree at the remote tip, never the task checkout. Copy in only the passing run's folder, commit it with explicit paths and push. When a retry finds that folder already there with the same files, reuse its commit and go on. If the push is rejected because another delivery pushed first, fetch, rebase onto the new tip and push again. Remove the worktree afterwards. Never force-push, merge the branch or base work on it.
- Push the task branch to the recorded remote. When the task has a
delivery.pr, first read its state (gh pr view <delivery.pr> --json state). If it was merged, don't push, update or open another PR: leave the task's status as it is, release the lock and follow settle with the developer, which finds the commits the merge left out. Push with the method that connected when the base was resolved. When a rebase rewrote a branch that is already on the remote, push it with a lease on the remote tip the branch contained before the rebase, as noted in update a moved base: git push --force-with-lease=<branch>:<that SHA> <remote> <branch>. Never pin the lease to a tip fetched after the rebase: the rebased branch doesn't contain its commits, so the push would discard them. If the lease is refused, someone pushed after that tip. Reset the task branch to its pre-rebase HEAD, bring their commits in as reopen a done task step 2 describes, then redo the base update from the base check, including its verification, and push with a lease on the tip you brought in. Never force-push without a lease, and never force-push the integration branch, the evidence branch or a branch that isn't this task's. When the push rewrote the branch, say in the PR description that it was rebased and onto what.
- Open the PR into the branch
delivery.base_ref names: the integration branch, or the parent's branch for a stacked task. A record without base_ref uses the integration branch. Use the host's CLI (for example gh pr create). When the task has a delivery.pr, update that PR by its URL (gh pr edit <delivery.pr>), never another PR on the branch. If the branch has an open PR, for example after a reopen, update its description instead, and retarget it when its base differs (gh pr edit <PR> --base <branch>). The description holds:
- a short summary and the acceptance criteria,
- the STR, so the developer can run it,
- the screenshots next to their steps, linked by the evidence commit's SHA (on GitHub,
https://github.com/<owner>/<repo>/blob/<evidence SHA>/<full-id>/<short SHA>/01-<screen>.png?raw=true),
- the verification evidence, baseline decisions and manual check results.
- an Agents line naming the agent and model that built and that reviewed the submitted revision, from the
Agent section of the builder's and reviewer's reports, for example Built by Claude Code (Claude Opus 5.5) · Reviewed by Codex (GPT-5). Add (same agent as the build) when the review ran on the build's agent. When this session has no such report, for example after resuming from an earlier session, write not recorded for that role; never guess.
- If a push or the PR fails, or the host has no CLI, report what failed and the commands to finish it by hand. The task stays
done, unless Finish step 3 was publishing before setting it: then it keeps its status.
Stacked tasks
A code task can be built on the branch of a code task it depends on before that task is merged. That dependency is its parent. A design dependency is never a parent: it has no product branch to build on.
- Start. A dependency is met once it is
done, merged or not. When a done code dependency is not in the integration branch yet, ask the developer whether to stack on it or wait for the merge. It is not in yet while its delivery.pr is open, when that PR was merged into another task's branch, or, without a PR, while its delivery.approved is not an ancestor of the integration branch tip. Waiting leaves the task ready. If a dependency's PR was closed without merging, ask. The branch to stack on is the dependency's own branch (its delivery.branch) while its PR is open or when it has none, or the branch its PR was merged into. When that branch's own task was merged too, follow its merge the same way; once the changes are in the integration branch, there is nothing to stack on. When the project opens PRs, stack only on a branch that is on the remote; otherwise wait until the dependency's PR is published. With several such dependencies, stack only on a branch that contains all their changes; otherwise wait.
- Base. Get that branch as project repository gets the integration branch, fetched from the remote when the parent has a PR and read locally when it doesn't. The parent's own branch must contain its
delivery.approved; a branch its PR was merged into must contain that merge. If not, ask. Its tip is the base. Record base_ref as <remote>/<branch> (stacked on <ID>), or <branch> (local, stacked on <ID>), where <ID> is the task that owns the branch. That task is the parent from then on. The baseline check runs there as usual.
- PR. Open it into the parent's branch, with the description starting
Stacked on <parent PR>: merge that first. Don't merge this PR as it is afterwards: run /factory:deliver <ID> again, so it is rebased onto the branch the parent merged into, verified and retargeted. Merging it unchanged could bring back parent changes the parent's review removed, or land it in a branch that no longer leads to the integration branch.
- Parent merged. At Finish step 1, check whether the parent's PR was merged, and into which branch. When it was, or without a PR when its
delivery.approved is in the integration branch, the task must move onto the branch it was merged into, following further merges exactly as at Start: past every branch whose own task's PR was merged too, whether or not that branch still exists, to the first unmerged one or the integration branch. Use the rules of update a moved base, with that branch's tip as the tip. Moving needs the developer's agreement; until they agree, don't publish. The rebase from delivery.base replays only the task's own commits, so a squash-merged parent's history, including changes its review removed, doesn't come back. Set base_ref to the new branch's ref, keeping (stacked on <ID>) when that branch belongs to another task, which is then the parent. Publishing the PR retargets it.
- Parent changed in review. A parent's branch is rewritten when it is rebased, for a base update or a reopen. Reopening the parent never changes its children; at the parent's Finish, list the tasks stacked on it, those whose
delivery.base_ref names it, in the summary. A child still in delivery sees the moved parent tip at its own base check and rebases onto it from its own delivery.base, the same way. A done child keeps its PR until the developer asks to reopen it.
- Parent's branch deleted. When the branch a stacked
base_ref names no longer exists, for example because the host deleted it after the merge, the base check doesn't stop, including at resume and reopen. If the parent's PR was merged, move as Parent merged describes. If it was closed without merging, ask the developer: the task's commits need the parent's changes. Otherwise, when there is no PR or its state can't be read, fall back to the integration branch: its tip is the tip, the move follows the rules of update a moved base like a merged parent, and base_ref becomes the integration branch's ref.
Changes after approval
Release the task lock whenever you wait for the developer below, and reacquire it and re-read the task before acting on the answer.
Edit an approved task
While a task is building, reviewing, checking, waiting-for-approval or blocked, edit its definition only while holding the task lock, and only as the developer asks or agrees.
- Small edit: it doesn't change the meaning of the Goals, Scope of work or Acceptance criteria, for example a typo, a link or a clarification. Make it and add a log line:
- YYYY-MM-DD: edited (deliver, <what changed>).
- Scope or criteria change: anything else. Show the change and ask the developer to re-approve it.
- Approved: make it and log
- YYYY-MM-DD: edited (deliver, <what changed>, re-approved by dev). A task in reviewing or checking, or in waiting-for-approval after one of those, then goes back to building with its own log line (<status> → building), because the review judged the old definition: clear delivery.approved, send the change to the builder (step 2), then gate, review and the STR again.
- Declined: keep the definition as it is and continue the delivery.
- No answer yet: set
status: waiting-for-approval with a log line naming the status it left, release the lock and stop.
- Environment details, such as a port, a service or an env file, are not part of the task. They belong in the project's docs, as running checks describes.
Reopen a done task
A done task is reopened only when the developer asks, for example to fix PR review comments. Never reopen one on your own, and never select one automatically. The task stays done until step 4; if you stop before then, release the lock and leave it unchanged.
- Already merged? Check whether the task's branch is merged into the integration branch. Fetch the integration branch first as project repository describes (not for
local-only), and check the state of the PR in delivery.pr when there is one: a squash or rebase merge doesn't keep the branch's commits. If it's unclear, ask. If it is merged, don't reopen it: suggest defining a new task for the change with define, so the merged task's history stays as it was, and stop.
- Acquire the task lock and verify the recorded branch and checkout as Resume existing delivery steps 2–3 describe, and recheck any linked design approval. When there is a PR, fetch the remote task branch too: commits pushed there, for example accepted review suggestions, are part of the change, so bring the local branch up to them: fast-forward, or, when they have diverged, rebase the local commits onto the remote branch (
git rebase <remote>/<branch>). On a conflict, run git rebase --abort and ask. The branch must still contain the recorded base and submitted commits (git merge-base --is-ancestor). The integration branch moving ahead is normal. Then run steps 1–2 of the base check, so the newest base commit is computed against a freshly fetched tip. When the branch contains base commits newer than delivery.base, for example from the host's Update branch button, whether you just brought them in or they were already in the local branch, record the base the branch now contains before step 4. A branch that no longer contains the recorded base and submitted (rebased or reset) needs a developer decision, and an agreed new base goes in delivery.base and the log.
- If the change goes beyond the task's Goals, Scope of work or Acceptance criteria, suggest a new task instead. If the developer wants it in this task, ask them to re-approve it as a scope or criteria change and log it as edit an approved task describes before step 4. If they decline or haven't answered yet, stop; the task stays
done.
- Set
status: building, clear delivery.approved, untick every acceptance criterion, and log - YYYY-MM-DD: done → building (deliver, reopened: <reason>, reviewed <short submitted SHA>). Keep delivery, including baseline.
- Run steps 2–6 as usual. Commits that already landed on the branch outside deliver are part of the change: the builder gets them and the requested changes, and makes whatever is still missing. The gate re-runs every automated check on the new head and resets manual checks to
pending. The reviewer also gets the previously reviewed SHA, so it can focus on what changed since, but it judges the whole <base>..HEAD diff. Record the new head as submitted when review starts. The STR runs again on the final revision, and Finish updates the task's open PR. Anything you write in the PR's review threads, such as a reply saying a comment was fixed, follows comments on pull requests.
Running checks
The baseline check, the builder, your gate re-run and the reviewer all run checks this way. Only the builder fixes product code. The builder and you fix environment failures the way the project documents. Only you, the orchestrator, ask the developer, including before copying env files.
- Order. Run the static checks first: format and lint, type checks, unit tests, then build. Then run the checks that depend on them, such as scans of build output and integration or e2e tests. Manual checks come last. If a static check still fails after sort a failure with failures that
delivery.baseline doesn't cover, don't run the checks after it; their results mean nothing until it passes. The builder fixes the failure (or reports it, when sort a failure says so), the gate counts it as a gap, the reviewer reports it, and the baseline check records it. A dependent check skipped at the baseline is handled by sort a failure if it fails later.
- Prerequisites. Take them from the project's docs (
README.md, AGENTS.md): services, migrations, env files, seed data. Report the prerequisites each check needed with its result. In a new worktree, you list the ignored env files in the source checkout and ask the developer before copying them; never copy secrets without asking.
- Foreground. Run each command in the foreground and wait for it to finish. Don't background it and poll, and don't cut it short. The one exception is the app while you run the STR in its sandbox.
- App sandbox. The STR runs the app where it can't touch other work running in parallel: a temporary worktree at
submitted, its own services and data (for example its own Compose project, database or schema, migrated and seeded), and free ports. Use the project's documented way to run an isolated instance, or the ## App sandbox section of the project settings. If there is neither, ask the developer once how to isolate it and record the answer there. Never point the sandbox at another checkout's database or services. Name everything the sandbox creates after the task, factory-<full-id> (worktree, Compose project, database), so a later session can find a sandbox an interrupted run left behind: that one is yours to stop and remove before starting again.
- Dev servers. Start one only when a check needs it, on a free port instead of the default, and stop it when the check finishes. This includes a server the test runner starts (for example Playwright's
webServer): point it at the free port and don't let it reuse a server that is already running. Never reuse or stop a server you didn't start.
- Retries. Use the project's configured retries, for example for e2e tests, no more. Re-run a failing test at most once, to tell a flaky test from a real failure, and report every run. Only sort a failure asks for more runs.
- Failures. React to what the command reports rather than adding pre-checks for problems that may not exist. If it fails because of the environment (a port in use, another dev server running for the project, a missing env file, a service down), the builder and you fix it the way the project documents, for example with a free port or by stopping your own server, and run it again. The reviewer only reports it. If the fix needs the developer (a secret to copy, a server you didn't start), the builder reports the command and its error as an open question, and you ask the developer. If the developer won't fix the environment, the check can't run: at the baseline check, ask whether to waive it; later, set
status: blocked with the reason in the log.
Sort a failure
When a check fails and the cause is not the environment (see Failures above), sort the failure before acting on it. A failure is one test or rule with one error. A re-run that fails with a different error doesn't repeat the original: the original counts as passing on its re-run (case 4), and the new error is sorted on its own. On the base, only the same error counts as the same failure.
The builder and you both re-run a failure once, the failing tests or the whole command for a check without separate tests, and report both runs. If the builder's repeated failure is outside the diff and delivery.baseline doesn't cover it, it reports the failure with its runs instead of fixing it, and leaves the checks after it unrun. Once you send it back as a gap, the builder fixes it. The rest is yours, at the baseline check and the gate. The reviewer judges your result from the evidence instead of sorting again. Take the first case that fits:
- Known noise. The failure matches a known noise entry in the project settings: the same check and message. Run the check once more. If it passes, the check passes; report both runs. If it repeats, go on to case 2 and count it as already re-run.
- Recorded baseline failure.
delivery.baseline covers it: the same check, one of its listed files, tests or rules and, when the entry records it, the same error. A failure that names no file, test or rule matches an entry of that check that also names none and records the same error. Apply the recorded ignore or waive.
- Repeated failure. Re-run the failing tests once, or the whole command for a check without separate tests such as a build, unless it was already re-run. If it repeats:
- At the baseline check, it is a baseline failure.
- At the gate, inside the diff (a file the diff changes, or a test of it): a gap. A failure that names no file or test, such as a build that only reports a command error, counts as outside the diff, so the base decides.
- At the gate, only outside the diff: run it on the base. If the same failure happens there, it is pre-existing: ask the developer once whether to ignore or waive it, and record the answer in
delivery.baseline as the baseline check does, with the error, or to stop: set status: blocked, keep the branch and its commits, and suggest fixing the failure in its own task. Otherwise it is a gap.
- Passes on the re-run. The failure is intermittent. At the baseline check, the check passes; say so in the summary. At the gate, run the same tests, or the whole command, 3 more times on the branch and 3 times on the base. If the failure comes back on the branch and never on the base, it is a gap. If it also happens on the base, or never comes back, the check passes. Keep every run in the verification evidence, and in the final summary suggest a follow-up task for the flaky test.
A failure the builder reports as passing on its re-run, and that isn't known noise, is intermittent. Sort it as case 4 unless your own run shows that same failure, which you then sort as you see it. This holds per failure: other failures your run shows are sorted on their own and don't settle the builder's one. A single green run doesn't clear a flaky test.
When the builder stopped at a failure that turns out not to be a gap, send it back to run the remaining checks; that is not a failed gate.
To run on the base, use a temporary worktree at delivery.base, with its own services and data when the tests need them, set up as an app sandbox. Name everything it creates factory-<full-id>-base, remove it afterwards, and remove one an interrupted run left behind before making a new one.
When the developer says a failure that passed on its re-run is toolchain noise that will come back, add it to the settings' known noise.
Original Markdown
---
name: deliver
description: Orchestrate one ready code task through build and independent code review. Design tasks have their own design orchestrator.
argument-hint: "[task id, e.g. DEV-003]"
disable-model-invocation: true
---
# Deliver a task
You are the **orchestrator**. You don't write product code and you don't review it. You hand the building and the independent review to separate roles, and you decide when the work moves on.
First read [storage](../storage.md) and the shared [task record](../task-record.md), resolve `$FACTORY_ROOT`, and acquire the selected task's lock before changing it. All task state and evidence stay in that shared catalog, never in product commits.
```text
ready → building → [gate] → reviewing → [STR run] → (checking) → done → PR
↑ | | | | |
└─ gaps ──┘ | | | |
└─ blocking findings ┘ | | |
└─ failed STR step ───────────────┘ | |
└─ failed manual check ──────────────────────────┘ |
└─ reopened on request ─────────────────────────────────────┘
```
Two side states pause delivery until the developer acts: `waiting-for-approval` (a changed definition awaits re-approval, see [edit an approved task](#edit-an-approved-task)) and `blocked` (the builder needs a developer decision, or the environment can't be fixed). A task waiting for another task is not blocked: it stays `ready` and lists that task in `depends_on`.
## 1. Start
This orchestrator owns only code delivery. Resolve the complete requested ID through [task identity](../task-ids.md). If given a design task, stop and direct the developer to `/factory:design deliver <id>`; do not load its rules or launch its agents. Unknown or conflicting identity/kind requires a developer decision.
First run the [settle](../settle/SKILL.md) script as that skill describes, so a task whose PR was merged while it wasn't `done` no longer holds back the tasks that depend on it. Mention what it settled and its **Needs attention** lines, then go on. If the developer named a task that settle left under **Needs attention** with a merged PR, follow [settle with the developer](../settle/SKILL.md#3-with-the-developer) instead of the steps below.
1. Pick the complete ID the developer gave, or the highest-priority eligible ready code task using [shared priority and selection](../task-priorities.md), including its deterministic ID tie-break. To choose automatically, run the [overview script](../tasks/overview.mjs) from the product checkout with `--track code --format json` and take its `recommendation`; when it is `null`, report its `reason`. Exclude design tasks and unresolved blockers/dependencies. Missing/invalid priority or ambiguous ready-task identity prevents automatic selection; report it rather than guessing or backfilling. Explicit selection does not bypass approval/status/dependency gates. For a code task already `building`, `reviewing`, `checking`, `waiting-for-approval` or `blocked`, follow **Resume existing delivery** below instead of creating a new branch or replacing its recorded base. For a `done` task the developer wants changed, follow [reopen a done task](#reopen-a-done-task). When the developer asks to finish the PR of a `done` task with no `delivery.pr`, or to retry publishing one whose open PR failed to update or retarget, or to move one whose [stacked](#stacked-tasks) parent was merged, take the lock and check that HEAD, `submitted` and `delivery.approved` match and the passing run's evidence folder exists; then resume at Finish step 4 without reopening. Otherwise report what is missing.
2. If the task is `draft`, stop and suggest running `define` first.
3. Check that the working tree is clean. If it isn't, ask the developer how to proceed. If the task's `implements` field references a design, require the design task itself to be `done` with an `approval` whose revision matches `implements.revision` before starting. Missing, stale or rejected approval means this code task can't start: leave it `ready`, report it, and ask for the approved handoff rather than reviewing or producing designs here.
4. Resolve the base commit as [project repository](../repository.md#resolve-the-delivery-base) describes, recording the project settings first if they are missing. For a [stacked task](#stacked-tasks), use the parent's branch instead. Never use a design/prototype branch or blindly use current HEAD. Create `factory/<full-id>-short-slug` (for example `factory/DEV-003-settings`) from the resolved base SHA. If a `factory/<full-id>-*` branch already exists for a task that is still `ready`, an earlier start was interrupted: reuse it only if it points exactly at the newly resolved base, otherwise ask. Use an isolated worktree if this checkout belongs to another task/track or concurrent session; never switch it underneath active work. A new worktree has none of the source checkout's ignored files, such as `.env`; [prepare its environment](#running-checks) when a check needs them. Keep using the same absolute catalog task path; do not copy or cherry-pick records onto the branch. Read linked design handoff/approval records from the catalog and inspect the exact external/prototype revision without merging it. If the task or evidence cannot be located, stop and ask.
5. Run the [baseline check](#baseline-check) on the new branch before anything changes it.
6. After acquiring the task lock, re-read priority, status, dependencies and approval evidence from the record itself, not by re-running the overview, which shows your own lock as making the task ineligible. If eligibility or the automatic ranking changed, release the lock and reassess rather than acting on a stale overview. Then persist the task's `delivery` header field, including `base_ref` and `baseline`, and set `status: building` before launching agents.
### Baseline check
Run the project's automated checks that the gate will re-run (tests, lint, format, type checks, build) on the task branch while it still equals the base, as [running checks](#running-checks) describes. A failure caused by the environment, such as a missing `.env`, a service that isn't running or a port in use, is not a baseline failure: fix the environment and run the check again, or follow the environment rule in [running checks](#running-checks) when you can't. If they all pass, record `baseline: []`. For each check that still fails:
- If a baseline decision in the [project settings](../repository.md#project-settings) covers these failures, apply it without asking.
- Otherwise ask the developer once, listing every failing check and its failures together, to choose:
- **fix first**: stop. Remove the task branch (and worktree) you just created, which has no commits, leave the task `ready`, and suggest fixing the baseline in its own task.
- **ignore**: the check still runs at the gate. Failures already present at the base don't count; new ones do.
- **waive**: the check is not required for this delivery.
- Record each decision in `delivery.baseline` with the check, its failures as a list of files, tests or rule IDs, each with its error when the check prints one (for example `` `tests/api.test.ts` "search": timeout ``), and the decision. A failure that names no file, test or rule, such as a build's command error, is recorded by its error alone. When the developer says a decision should also apply to future deliveries, add it to the settings' baseline decisions.
Ask once per delivery; on later rounds and on resume, use the recorded `delivery.baseline`. The one exception is a failure outside the diff that [sorting it](#sort-a-failure) finds already on the base: ask about that one once.
Use the production baseline and any approved designs as references. Do not merge a throwaway prototype as implementation; connect the UI to the actual system and run production verification. Code tasks without a design dependency do not wait for the design track.
### Resume existing delivery
1. Acquire the task lock and re-read its `delivery`, `submitted` and `implements` fields and its status. Use its recorded branch/base, not the current checkout's HEAD or a newly fetched baseline.
2. Locate the owning checkout with `git worktree list --porcelain`. Verify its shared Git directory, checked-out branch, and the recorded base object; require `git merge-base --is-ancestor <base> <branch>` to succeed. Missing references, a removed/moved checkout, a different repository/branch, or rewritten history require a developer decision before updating references or continuing. Do not silently recreate a branch or switch an unrelated checkout. A transferred catalog does not authorize adopting a same-named branch in another clone.
3. Confirm no other session owns that checkout and inspect its working tree. Unexpected/uncommitted product edits require agreement on preservation before resuming; never discard them or assume a clean unrelated checkout is the task's checkout. Pass the verified owning checkout to agents along with branch/base and catalog paths. Then run steps 1–2 of the [base check](../repository.md#check-whether-the-base-moved), so the newest base commit is computed against a freshly fetched tip: when the branch already contains base commits newer than `delivery.base`, for example from the host's **Update branch** button, [record that base](#update-a-moved-base) before the next gate or review.
4. Whenever a task returns to `reviewing`, or resumes from a side state it entered from `reviewing` without a re-approved definition change, and `delivery.approved` equals `submitted` and HEAD, the review is done: remove any [leftover sandbox](#running-checks) for the task and run the STR again (section 5), without a new gate or review. Otherwise, for reviewing, require the checkout HEAD to match `submitted`; if it changed or is missing, stop for a decision and rerun the gate before a new review. Re-run the gate's automated checks to rebuild the verification evidence before starting or restarting a review. For a `checking` task, require HEAD to match `submitted` and continue at **Finish** (section 6) with the developer's results. If the developer needs the steps again, derive them from the criterion and the diff. For a `waiting-for-approval` task, apply the developer's answer as [edit an approved task](#edit-an-approved-task) describes, then continue from the step it paused in (its latest `<from> → waiting-for-approval` log line names the status), logging the status change. For a `blocked` task, resume only once the developer has resolved the reason in its latest `→ blocked` log line, and continue from that `<from>` status. For either side state, when that `<from>` is itself a side state, follow the earlier log lines back until you reach a status that isn't one. Otherwise continue the recorded build/review step after rechecking linked design approval. Never infer approval from the recovered status.
## 2. Build
Use the [delegate](../delegate/SKILL.md) skill to start the builder role with this job. Give it:
- the absolute task file path and resolved catalog root,
- the verified owning checkout, branch and base commit,
- the `delivery.baseline` decisions, so it leaves ignored baseline failures outside its scope alone, and the settings' known noise entries,
- the [running checks](#running-checks) rules, and any environment you prepared, such as copied env files,
- on later rounds, the gaps or review findings it must fix (quote them).
Don't pass it your own conversation history.
## 3. Gate: is it ready for review?
The builder's report is a claim. Check it before you spend a review on it. Pass to review only when **all** of these hold:
- [ ] Every acceptance criterion is addressed in the report. A criterion that only a person can check is listed under **Manual checks** with the steps to check it; it passes the gate as `pending` and is not missing evidence.
- [ ] The builder ran the project's documented checks for the change in the [running checks](#running-checks) order, and the report shows the commands, their results and the prerequisites they needed.
- [ ] You re-ran those automated checks yourself, the same way, and they pass. A failure counts only as [sort a failure](#sort-a-failure) decides. An `ignore`d check passes when its only failures are the ones recorded in `delivery.baseline`; a `waive`d check is not required.
- [ ] The changes are committed on the task branch (`git status` is clean, `git diff <base>..HEAD` is not empty).
- [ ] The diff stays within the task and contains no `.factory/` records or status-only commits. Required `docs/factory/` and `.agents/skills/` changes are product changes, not workflow state. Out-of-scope edits count as a gap.
- [ ] The report has an **STR** that covers every acceptance criterion that isn't a manual check.
- [ ] The builder has no open question that only the developer can answer.
Persist each manual check in `delivery.manual_checks` with `result: pending`. Every passed gate resets all entries to `pending`, including ones the STR run added, because earlier results checked an earlier revision. If a check fails, send the specific gaps back to the builder (step 2); an environment failure is yours to fix before you re-run, not a gap. After **2** failed gates in a row, stop and ask the developer. If the builder needs a decision from the developer, set `status: blocked` with the question as the log reason and ask.
## 4. Review
Record the owning checkout's full HEAD SHA, read with `git rev-parse HEAD`, as `submitted`, never a SHA from the builder's report; if the report names a different commit, tell the developer in the final summary. Then set `status: reviewing` in the catalog. Use the [delegate](../delegate/SKILL.md) skill to start the reviewer role in a fresh context with this job. Give it **only**:
- the absolute task file path and resolved catalog root,
- the verified owning checkout, base commit and branch, so it can read `git diff <base>..HEAD`,
- the verification evidence (commands, results and prerequisites) from your gate re-run, including the `delivery.baseline` decisions,
- the pending manual checks and their steps,
- for a [reopened task](#reopen-a-done-task) or one sent back by a [base update](#update-a-moved-base), the previously reviewed SHA from its most recent reopen or base-update log line, expanded to the full SHA with `git rev-parse <short SHA>^{commit}`.
Never pass the builder's reasoning or your conversation. The reviewer must judge the result, not the story behind it. Your gate re-run is the independent run of the automated checks, so the reviewer doesn't repeat the whole gate; it re-runs a command only when it doubts the evidence.
- **approve** → record the approved SHA as `delivery.approved` (it equals `submitted`) and go to step 5.
- **changes requested** → send only the blocking findings back to the builder (step 2), then gate and review again. Non-blocking findings go into the final summary.
- After **3** review rounds without approval, stop and ask the developer.
If review introduces follow-up tasks, use the [priority handoff rules](../task-priorities.md) when they are defined. Reassess pending order with the developer, without interrupting this delivery or treating a suggestion as authorization to start another task.
## 5. Verify the running app
After the last review round approves, run the builder's steps to reproduce (STR) once against the final implementation. The task stays `reviewing` meanwhile. The checkout HEAD must equal `submitted` and `delivery.approved`; if it doesn't, stop for a decision.
1. Take the STR from the builder's report for the approved revision. Each step names what to open or run, the action and the expected result, and the acceptance criterion it shows.
2. Run every step yourself, in an [app sandbox](#running-checks) when a step needs the running app or touches its data. Use seeded or fake data and test accounts only, never real credentials or personal data. Follow UI steps with a browser automation tool (prefer the project's Playwright, headless) and save a screenshot of each screen the path visits. Run command or API steps as written and keep their output.
3. Save the evidence in `$FACTORY_ROOT/evidence/<full-id>/<short submitted SHA>/`: `str.md` with each step, its result and its screenshots, and the screenshots as `NN-<screen>.png` in path order.
4. Stop the app and the sandbox's services, and remove the sandbox, also when a step fails.
5. **A step fails** because of the environment (a port, the sandbox, a flaky run) → handle it as [running checks](#running-checks) describes and run the step again. **A step fails** because the app doesn't do what it should → it is a gap: clear `delivery.approved`, set `status: building` (log reason "STR step failed"), send the step, its expected and actual result and the screenshot to the builder (step 2), then gate, review and run the STR again. After **2** failed STR runs in a row, stop and ask the developer.
6. **A step can't be automated**, for example a visual comparison with a design, a real external account or hardware, or because no browser tool is available or the app can't be sandboxed: add it to `delivery.manual_checks` as `pending`, under its criterion and with its `steps`; don't add a criterion twice. The developer is involved only for these.
## 6. Finish
1. When the task has a `delivery.pr`, for example after a reopen, read its state again (`gh pr view <PR> --json state`): someone may have merged it during delivery. If it was merged, don't set `done` or open another PR: release the lock and follow [settle with the developer](../settle/SKILL.md#3-with-the-developer). For a [stacked task](#stacked-tasks), check whether its parent was merged. Then [check whether the base moved](../repository.md#check-whether-the-base-moved). If it did, [offer to update the branch](#update-a-moved-base) before going on.
2. If `delivery.manual_checks` has a `pending` check, ask the developer to run it, giving the steps. Record each answer in the check's `result` with `by` and `date`. A `failed` check clears `delivery.approved`, sets `status: building` (log reason "manual check failed") and goes back to the builder (step 2) with what the developer saw, then gate, review and the STR again. If the developer defers the checks, set `status: checking` (log reason "manual checks deferred"), report as in Finish step 6 including each check's steps, release the lock and stop. When the developer later reports results for a `checking` task, take the lock, record them and continue here. A task with a `pending` or `failed` manual check is never `done`.
3. When the task has a `delivery.pr` and the project publishes PRs (not `local-only`, and not `pull_requests: off`), publish first ([open the pull request](#open-the-pull-request)) and set `done` only once that PR is updated. If it turns out merged, don't set `done`: release the lock and follow [settle with the developer](../settle/SKILL.md#3-with-the-developer). If the push or the PR update fails, don't set `done` either: keep the status, release the lock and report as that procedure's last step describes; `/factory:deliver <ID>` retries from here. Set `status: done` and tick the acceptance criteria. Save the task file update in the shared catalog; do not create a status commit.
4. [Open the pull request](#open-the-pull-request), when step 3 didn't, unless the project is `local-only` or its settings say `pull_requests: off`. Record its URL as `delivery.pr`.
5. Release the task lock before handing back.
6. Tell the developer: what changed, the branch name, the PR link (or, without a PR, the STR and the evidence folder), the verification evidence, the manual check results and any baseline decisions, whether the base moved and how it was handled, any tasks [stacked on this one](#stacked-tasks), the build and review rounds, and any non-blocking findings. Never merge.
7. Add a journal entry with the `journal` skill (type `delivery`). Record the build and review rounds, failed gates and anything the factory got wrong or made awkward: a weak gate, a noisy review, a missing instruction.
### Update a moved base
When the [base check](../repository.md#check-whether-the-base-moved) reports that the branch already contains base commits newer than `delivery.base`, set `delivery.base` to that commit and add the `base updated` log line from the [task record](../task-record.md#log) before anything else, so the gate judges only the task's own changes. This counts as a base update for the rules below.
After any base update, re-run each `ignore`d failure in `delivery.baseline` on the new base before the next checks run, whether those are the next gate or a clean update's re-run. Drop an entry whose failure no longer happens there, so a regression on the branch can't hide behind a decision about the old base. Say so in the summary.
Tell the developer what the [base check](../repository.md#check-whether-the-base-moved) found: the new commits, the files they share with the task's diff and whether the task's changes apply to the tip without conflicts. Then ask whether to update the branch onto the tip. If the developer already chose to leave it for the same tip, the branch in `delivery.base_ref` still exists and, for a [stacked task](#stacked-tasks), its parent hasn't merged since, don't ask again.
- **Leave it:** continue. Mention it in the final summary. This choice is not offered when the base branch no longer exists, or when a [stacked task's](#stacked-tasks) parent was merged, even if its branch is kept: merging the child into the parent's branch then would leave its changes out of the integration branch.
- **Update:** rebase the task's own commits onto the tip: `git rebase --onto <tip> <delivery.base>`. Never merge the tip in. When the branch is already on the remote, fetch it first and require `git merge-base --is-ancestor <remote tip> HEAD`; if the local branch doesn't contain the remote tip yet, bring those commits in as [reopen a done task](#reopen-a-done-task) step 2 describes before rebasing. Note the pre-rebase HEAD and that remote tip: the push's lease is pinned to it, as [open the pull request](#open-the-pull-request) step 4 describes.
- **Clean** (the check found no conflict and no shared files): update the branch yourself. If the rebase stops on a conflict anyway, run `git rebase --abort` so the branch is back where it was, and take the conflict path below. Check that the tip is an ancestor of the new HEAD and that the task's own changes are the same: `git diff --raw --no-abbrev <old base> <old HEAD>` and `git diff --raw --no-abbrev <tip> HEAD` must be identical; if they aren't, take the conflict path. Then re-run the gate's automated checks and run the STR (section 5) with the new HEAD as the revision and the tip as the base. The diff, [sort a failure](#sort-a-failure) and its runs on the base, the sandbox and the evidence folder (`<short new HEAD>`) all use them, and section 5's HEAD check compares against the new HEAD. Until both pass, `submitted` and `delivery.approved` still name the old HEAD, so an interrupted update stops at resume for a decision instead of skipping them. A failure is a gap, as at the gate: set `delivery.base` to the tip and `submitted` to the new HEAD first, untick every acceptance criterion, so the builder and the next gate judge the diff from the new base, then clear `delivery.approved` and set `status: building` (log reason "base update failed checks, reviewed <short old submitted>") before the builder gets the gap. If the STR adds a `pending` manual check, first record the update as below, then continue at Finish step 2 before publishing; a `done` task goes back to `reviewing` first (log reason "base update added a manual check"). Once both pass, set `delivery.base` to the tip, record the new HEAD as `submitted` and `delivery.approved`, and add the `base updated` log line from the [task record](../task-record.md#log). The review and the manual check results still stand, because the changes they judged are the same, so the task keeps its status.
- **Conflicts or shared files:** for a `done` task, follow [reopen a done task](#reopen-a-done-task) from step 1, with "base update" as the reason; its first step catches a task that was already merged. Otherwise clear `delivery.approved` and set `status: building` (log reason "base update, reviewed <short submitted>"). Then send the builder (step 2) the job to rebase the branch onto the tip the same way and resolve the conflicts within the task's scope. Set `delivery.base` to the tip once it has. Then gate, review and the STR again. The reviewer gets the previously reviewed SHA, as for a reopened task.
### Open the pull request
1. **Check the base again**, as in Finish step 1, in case it moved after that. If it moved, [offer the update](#update-a-moved-base) before publishing anything.
2. **Check the evidence.** It goes to a remote branch that everyone with read access can see, and pushed history is hard to take back. Read `str.md` and look at every screenshot. Leave out or redact anything sensitive: secrets, tokens, env values, personal data. Never put env files in the evidence folder. If you're unsure, ask the developer before pushing.
3. **Publish the evidence.** All evidence goes to one `factory-evidence` branch on the recorded remote, in folders by task: `<full-id>/<short submitted SHA>/`. It shares no history with the product: create it as an orphan branch only if the remote doesn't have it. Fetch it first and work in a temporary worktree at the remote tip, never the task checkout. Copy in only the passing run's folder, commit it with explicit paths and push. When a retry finds that folder already there with the same files, reuse its commit and go on. If the push is rejected because another delivery pushed first, fetch, rebase onto the new tip and push again. Remove the worktree afterwards. Never force-push, merge the branch or base work on it.
4. **Push the task branch** to the recorded remote. When the task has a `delivery.pr`, first read its state (`gh pr view <delivery.pr> --json state`). If it was merged, don't push, update or open another PR: leave the task's status as it is, release the lock and follow [settle with the developer](../settle/SKILL.md#3-with-the-developer), which finds the commits the merge left out. Push with the method that connected when the [base was resolved](../repository.md#resolve-the-delivery-base). When a rebase rewrote a branch that is already on the remote, push it with a lease on the remote tip the branch contained before the rebase, as noted in [update a moved base](#update-a-moved-base): `git push --force-with-lease=<branch>:<that SHA> <remote> <branch>`. Never pin the lease to a tip fetched after the rebase: the rebased branch doesn't contain its commits, so the push would discard them. If the lease is refused, someone pushed after that tip. Reset the task branch to its pre-rebase HEAD, bring their commits in as [reopen a done task](#reopen-a-done-task) step 2 describes, then redo the base update from the base check, including its verification, and push with a lease on the tip you brought in. Never force-push without a lease, and never force-push the integration branch, the evidence branch or a branch that isn't this task's. When the push rewrote the branch, say in the PR description that it was rebased and onto what.
5. **Open the PR** into the branch `delivery.base_ref` names: the integration branch, or the parent's branch for a [stacked task](#stacked-tasks). A record without `base_ref` uses the integration branch. Use the host's CLI (for example `gh pr create`). When the task has a `delivery.pr`, update that PR by its URL (`gh pr edit <delivery.pr>`), never another PR on the branch. If the branch has an open PR, for example after a reopen, update its description instead, and retarget it when its base differs (`gh pr edit <PR> --base <branch>`). The description holds:
- a short summary and the acceptance criteria,
- the STR, so the developer can run it,
- the screenshots next to their steps, linked by the evidence commit's SHA (on GitHub, `https://github.com/<owner>/<repo>/blob/<evidence SHA>/<full-id>/<short SHA>/01-<screen>.png?raw=true`),
- the verification evidence, baseline decisions and manual check results.
- an **Agents** line naming the agent and model that built and that reviewed the submitted revision, from the `Agent` section of the builder's and reviewer's reports, for example `Built by Claude Code (Claude Opus 5.5) · Reviewed by Codex (GPT-5)`. Add `(same agent as the build)` when the review ran on the build's agent. When this session has no such report, for example after resuming from an earlier session, write `not recorded` for that role; never guess.
6. If a push or the PR fails, or the host has no CLI, report what failed and the commands to finish it by hand. The task stays `done`, unless Finish step 3 was publishing before setting it: then it keeps its status.
## Stacked tasks
A code task can be built on the branch of a code task it depends on before that task is merged. That dependency is its **parent**. A design dependency is never a parent: it has no product branch to build on.
- **Start.** A dependency is met once it is `done`, merged or not. When a `done` code dependency is not in the integration branch yet, ask the developer whether to stack on it or wait for the merge. It is not in yet while its `delivery.pr` is open, when that PR was merged into another task's branch, or, without a PR, while its `delivery.approved` is not an ancestor of the integration branch tip. Waiting leaves the task `ready`. If a dependency's PR was closed without merging, ask. The branch to stack on is the dependency's own branch (its `delivery.branch`) while its PR is open or when it has none, or the branch its PR was merged into. When that branch's own task was merged too, follow its merge the same way; once the changes are in the integration branch, there is nothing to stack on. When the project opens PRs, stack only on a branch that is on the remote; otherwise wait until the dependency's PR is published. With several such dependencies, stack only on a branch that contains all their changes; otherwise wait.
- **Base.** Get that branch as [project repository](../repository.md#resolve-the-delivery-base) gets the integration branch, fetched from the remote when the parent has a PR and read locally when it doesn't. The parent's own branch must contain its `delivery.approved`; a branch its PR was merged into must contain that merge. If not, ask. Its tip is the base. Record `base_ref` as `<remote>/<branch> (stacked on <ID>)`, or `<branch> (local, stacked on <ID>)`, where `<ID>` is the task that owns the branch. That task is the parent from then on. The baseline check runs there as usual.
- **PR.** Open it into the parent's branch, with the description starting `Stacked on <parent PR>: merge that first. Don't merge this PR as it is afterwards: run /factory:deliver <ID> again, so it is rebased onto the branch the parent merged into, verified and retargeted.` Merging it unchanged could bring back parent changes the parent's review removed, or land it in a branch that no longer leads to the integration branch.
- **Parent merged.** At Finish step 1, check whether the parent's PR was merged, and into which branch. When it was, or without a PR when its `delivery.approved` is in the integration branch, the task must move onto the branch it was merged into, following further merges exactly as at Start: past every branch whose own task's PR was merged too, whether or not that branch still exists, to the first unmerged one or the integration branch. Use the rules of [update a moved base](#update-a-moved-base), with that branch's tip as the tip. Moving needs the developer's agreement; until they agree, don't publish. The rebase from `delivery.base` replays only the task's own commits, so a squash-merged parent's history, including changes its review removed, doesn't come back. Set `base_ref` to the new branch's ref, keeping `(stacked on <ID>)` when that branch belongs to another task, which is then the parent. Publishing the PR retargets it.
- **Parent changed in review.** A parent's branch is rewritten when it is rebased, for a base update or a reopen. Reopening the parent never changes its children; at the parent's Finish, list the tasks stacked on it, those whose `delivery.base_ref` names it, in the summary. A child still in delivery sees the moved parent tip at its own base check and rebases onto it from its own `delivery.base`, the same way. A `done` child keeps its PR until the developer asks to reopen it.
- **Parent's branch deleted.** When the branch a stacked `base_ref` names no longer exists, for example because the host deleted it after the merge, the [base check](../repository.md#check-whether-the-base-moved) doesn't stop, including at resume and reopen. If the parent's PR was merged, move as **Parent merged** describes. If it was closed without merging, ask the developer: the task's commits need the parent's changes. Otherwise, when there is no PR or its state can't be read, fall back to the integration branch: its tip is the tip, the move follows the rules of [update a moved base](#update-a-moved-base) like a merged parent, and `base_ref` becomes the integration branch's ref.
## Changes after approval
Release the task lock whenever you wait for the developer below, and reacquire it and re-read the task before acting on the answer.
### Edit an approved task
While a task is `building`, `reviewing`, `checking`, `waiting-for-approval` or `blocked`, edit its definition only while holding the task lock, and only as the developer asks or agrees.
- **Small edit**: it doesn't change the meaning of the Goals, Scope of work or Acceptance criteria, for example a typo, a link or a clarification. Make it and add a log line: `- YYYY-MM-DD: edited (deliver, <what changed>)`.
- **Scope or criteria change**: anything else. Show the change and ask the developer to re-approve it.
- **Approved:** make it and log `- YYYY-MM-DD: edited (deliver, <what changed>, re-approved by dev)`. A task in `reviewing` or `checking`, or in `waiting-for-approval` after one of those, then goes back to `building` with its own log line (`<status> → building`), because the review judged the old definition: clear `delivery.approved`, send the change to the builder (step 2), then gate, review and the STR again.
- **Declined:** keep the definition as it is and continue the delivery.
- **No answer yet:** set `status: waiting-for-approval` with a log line naming the status it left, release the lock and stop.
- **Environment details**, such as a port, a service or an env file, are not part of the task. They belong in the project's docs, as [running checks](#running-checks) describes.
### Reopen a done task
A `done` task is reopened only when the developer asks, for example to fix PR review comments. Never reopen one on your own, and never select one automatically. The task stays `done` until step 4; if you stop before then, release the lock and leave it unchanged.
1. **Already merged?** Check whether the task's branch is merged into the integration branch. Fetch the integration branch first as [project repository](../repository.md#resolve-the-delivery-base) describes (not for `local-only`), and check the state of the PR in `delivery.pr` when there is one: a squash or rebase merge doesn't keep the branch's commits. If it's unclear, ask. If it is merged, don't reopen it: suggest defining a new task for the change with `define`, so the merged task's history stays as it was, and stop.
2. Acquire the task lock and verify the recorded branch and checkout as **Resume existing delivery** steps 2–3 describe, and recheck any linked design approval. When there is a PR, fetch the remote task branch too: commits pushed there, for example accepted review suggestions, are part of the change, so bring the local branch up to them: fast-forward, or, when they have diverged, rebase the local commits onto the remote branch (`git rebase <remote>/<branch>`). On a conflict, run `git rebase --abort` and ask. The branch must still contain the recorded `base` and `submitted` commits (`git merge-base --is-ancestor`). The integration branch moving ahead is normal. Then run steps 1–2 of the [base check](../repository.md#check-whether-the-base-moved), so the newest base commit is computed against a freshly fetched tip. When the branch contains base commits newer than `delivery.base`, for example from the host's **Update branch** button, whether you just brought them in or they were already in the local branch, [record the base the branch now contains](#update-a-moved-base) before step 4. A branch that no longer contains the recorded `base` and `submitted` (rebased or reset) needs a developer decision, and an agreed new base goes in `delivery.base` and the log.
3. If the change goes beyond the task's Goals, Scope of work or Acceptance criteria, suggest a new task instead. If the developer wants it in this task, ask them to re-approve it as a scope or criteria change and log it as [edit an approved task](#edit-an-approved-task) describes before step 4. If they decline or haven't answered yet, stop; the task stays `done`.
4. Set `status: building`, clear `delivery.approved`, untick every acceptance criterion, and log `- YYYY-MM-DD: done → building (deliver, reopened: <reason>, reviewed <short submitted SHA>)`. Keep `delivery`, including `baseline`.
5. Run steps 2–6 as usual. Commits that already landed on the branch outside deliver are part of the change: the builder gets them and the requested changes, and makes whatever is still missing. The gate re-runs every automated check on the new head and resets manual checks to `pending`. The reviewer also gets the previously reviewed SHA, so it can focus on what changed since, but it judges the whole `<base>..HEAD` diff. Record the new head as `submitted` when review starts. The STR runs again on the final revision, and Finish updates the task's open PR. Anything you write in the PR's review threads, such as a reply saying a comment was fixed, follows [comments on pull requests](../repository.md#comments-on-pull-requests).
## Running checks
The baseline check, the builder, your gate re-run and the reviewer all run checks this way. Only the builder fixes product code. The builder and you fix environment failures the way the project documents. Only you, the orchestrator, ask the developer, including before copying env files.
- **Order.** Run the static checks first: format and lint, type checks, unit tests, then build. Then run the checks that depend on them, such as scans of build output and integration or e2e tests. Manual checks come last. If a static check still fails after [sort a failure](#sort-a-failure) with failures that `delivery.baseline` doesn't cover, don't run the checks after it; their results mean nothing until it passes. The builder fixes the failure (or reports it, when [sort a failure](#sort-a-failure) says so), the gate counts it as a gap, the reviewer reports it, and the baseline check records it. A dependent check skipped at the baseline is handled by [sort a failure](#sort-a-failure) if it fails later.
- **Prerequisites.** Take them from the project's docs (`README.md`, `AGENTS.md`): services, migrations, env files, seed data. Report the prerequisites each check needed with its result. In a new worktree, you list the ignored env files in the source checkout and ask the developer before copying them; never copy secrets without asking.
- **Foreground.** Run each command in the foreground and wait for it to finish. Don't background it and poll, and don't cut it short. The one exception is the app while you run the STR in its sandbox.
- **App sandbox.** The STR runs the app where it can't touch other work running in parallel: a temporary worktree at `submitted`, its own services and data (for example its own Compose project, database or schema, migrated and seeded), and free ports. Use the project's documented way to run an isolated instance, or the `## App sandbox` section of the [project settings](../repository.md#project-settings). If there is neither, ask the developer once how to isolate it and record the answer there. Never point the sandbox at another checkout's database or services. Name everything the sandbox creates after the task, `factory-<full-id>` (worktree, Compose project, database), so a later session can find a sandbox an interrupted run left behind: that one is yours to stop and remove before starting again.
- **Dev servers.** Start one only when a check needs it, on a free port instead of the default, and stop it when the check finishes. This includes a server the test runner starts (for example Playwright's `webServer`): point it at the free port and don't let it reuse a server that is already running. Never reuse or stop a server you didn't start.
- **Retries.** Use the project's configured retries, for example for e2e tests, no more. Re-run a failing test at most once, to tell a flaky test from a real failure, and report every run. Only [sort a failure](#sort-a-failure) asks for more runs.
- **Failures.** React to what the command reports rather than adding pre-checks for problems that may not exist. If it fails because of the environment (a port in use, another dev server running for the project, a missing env file, a service down), the builder and you fix it the way the project documents, for example with a free port or by stopping your own server, and run it again. The reviewer only reports it. If the fix needs the developer (a secret to copy, a server you didn't start), the builder reports the command and its error as an open question, and you ask the developer. If the developer won't fix the environment, the check can't run: at the baseline check, ask whether to waive it; later, set `status: blocked` with the reason in the log.
### Sort a failure
When a check fails and the cause is not the environment (see **Failures** above), sort the failure before acting on it. A failure is one test or rule with one error. A re-run that fails with a different error doesn't repeat the original: the original counts as passing on its re-run (case 4), and the new error is sorted on its own. On the base, only the same error counts as the same failure.
The builder and you both re-run a failure once, the failing tests or the whole command for a check without separate tests, and report both runs. If the builder's repeated failure is outside the diff and `delivery.baseline` doesn't cover it, it reports the failure with its runs instead of fixing it, and leaves the checks after it unrun. Once you send it back as a gap, the builder fixes it. The rest is yours, at the baseline check and the gate. The reviewer judges your result from the evidence instead of sorting again. Take the first case that fits:
1. **Known noise.** The failure matches a known noise entry in the [project settings](../repository.md#project-settings): the same check and message. Run the check once more. If it passes, the check passes; report both runs. If it repeats, go on to case 2 and count it as already re-run.
2. **Recorded baseline failure.** `delivery.baseline` covers it: the same check, one of its listed files, tests or rules and, when the entry records it, the same error. A failure that names no file, test or rule matches an entry of that check that also names none and records the same error. Apply the recorded `ignore` or `waive`.
3. **Repeated failure.** Re-run the failing tests once, or the whole command for a check without separate tests such as a build, unless it was already re-run. If it repeats:
- At the baseline check, it is a baseline failure.
- At the gate, inside the diff (a file the diff changes, or a test of it): a gap. A failure that names no file or test, such as a build that only reports a command error, counts as outside the diff, so the base decides.
- At the gate, only outside the diff: run it on the base. If the same failure happens there, it is pre-existing: ask the developer once whether to **ignore** or **waive** it, and record the answer in `delivery.baseline` as the baseline check does, with the error, or to **stop**: set `status: blocked`, keep the branch and its commits, and suggest fixing the failure in its own task. Otherwise it is a gap.
4. **Passes on the re-run.** The failure is intermittent. At the baseline check, the check passes; say so in the summary. At the gate, run the same tests, or the whole command, 3 more times on the branch and 3 times on the base. If the failure comes back on the branch and never on the base, it is a gap. If it also happens on the base, or never comes back, the check passes. Keep every run in the verification evidence, and in the final summary suggest a follow-up task for the flaky test.
A failure the builder reports as passing on its re-run, and that isn't known noise, is intermittent. Sort it as case 4 unless your own run shows that same failure, which you then sort as you see it. This holds per failure: other failures your run shows are sorted on their own and don't settle the builder's one. A single green run doesn't clear a flaky test.
When the builder stopped at a failure that turns out not to be a gap, send it back to run the remaining checks; that is not a failed gate.
To run on the base, use a temporary worktree at `delivery.base`, with its own services and data when the tests need them, set up as an app sandbox. Name everything it creates `factory-<full-id>-base`, remove it afterwards, and remove one an interrupted run left behind before making a new one.
When the developer says a failure that passed on its re-run is toolchain noise that will come back, add it to the settings' known noise.