Revision: 1 Last modified: 2026-12-04T00:00:00Z
State machine: scripts/pr/lib/steps.sh (sourced by scripts/pr/pr_deliver.sh; never executed on its own).
Engine guide: docs/scripts/pr_deliver.md. Manual: docs/manuals/pr_delivery_engine_manual.md.
One closed state machine, S1–S12, in which every step is idempotent, resumable, and READS ITS EFFECT BACK from the provider or from git. A tool's exit status is never the proof: a push is proven by the remote tip, a commit by the trailer parsed back out of the message, a review by the review object the provider lists, a merge by the merged state plus the landing form, and a retirement by the branch being absent.
(no journal) → preflighted → branch_ready → committed → pushed → pr_opened
→ reviewed → approval_recorded → go_posted → merge_ready → merging
→ merged → parity_ok → cleaned → done
any state → refused | blocked | failed (terminal for that run; `recover` resumes the work)
This is the only file that mutates anything, and it does so in one order: branch, commit, push, pull request, review comment, merge, read-back, parity, retirement.
- A validated declaration and an initialised journal; the lock is taken before the first mutation.
gitand the provider adapter (seeprovider.md) with a working credential.- For S11:
scripts/sync/verify_upstream_parity.sh. If that instrument is absent the step reportsinstrument_absentand returns 2 (unreachable), never a pass.
The four subcommands, in the order a delivery uses them:
# S1–S5: branch, commit with the Roadmap-Item trailer, push, open (idempotent)
bash scripts/pr/pr_deliver.sh create --task CON-641 --slug delivery-docs --roadmap-item CON-641
# S6–S8: post one independent reviewer's verdict, read it back, post the aggregate GO
bash scripts/pr/pr_deliver.sh review --task CON-641 --verdict-file /tmp/verdict.txt --reviewer reviewer-a
# S9–S12: verify, merge, read back, prove parity, retire
bash scripts/pr/pr_deliver.sh merge --task CON-641
# stop before the merge, having proved every condition
bash scripts/pr/pr_deliver.sh merge --task CON-641 --dry-runThe reviewer's own artifact — the engine computes the findings digest over the block after ---, so the
reviewer cannot hand-wave it:
VERDICT: PASS
HEAD: 4f2c1a9… # must equal the pull request's current head
REVIEWER: reviewer-a
SUBSTRATE: opus-xhigh # or harness-unset when the path cannot set or report effort
FINDINGS: 0
---
src/a.sh:12: minor: an example finding
createon an already-pushed branch is not a second delivery. If the working tree is clean and either an open pull request exists or the branch already carries commits the base lacks, the step recordscommitted no_new_commit=1and continues — demanding an empty commit to open a pull request would be absurd.- A merged-but-still-present branch is refused with
stale_branch:<branch>: the work landed and the branch was not retired, which is a cleanup that must happen before a new delivery of that task. - An existing pull request is ADOPTED, never duplicated, but only when its base matches and it is not a
draft; otherwise
base_mismatch:<n>orpr_is_draft:<n>. A pull request the engine just created and then found wrong is CLOSED by the engine (it is its own), not left wrong. roadmap_item_absent/roadmap_item_annotated:<id>/multi_task_reason_absentare refusals raised BEFORE staging anything: ids only, no annotation, and more than one id requires--multi-task-reason.- No changes at all is
no_changes_to_deliver— the engine delivers a change, it never invents one. - The base is merged into the branch, never rebased.
pr_sync_base_into_branchand the (c) merge condition both usegit merge --no-ff/--no-edit, because a rebase would rewrite the reviewed history. A conflict isBLOCKED pr_conflicts:<base>, with the merge aborted so the tree is left as it was. - A review must name the CURRENT head.
review_head_mismatch:<a>_vs_<b>refuses a verdict produced for a head that has since moved. - The review POST's exit code is not the proof. The verdict is accepted only when the provider lists a
review carrying the reviewer and the findings digest (
review_not_landed:<reviewer>otherwise). - An APPROVE event is not the gate. Under
approval_mode=approve-eventthe engine refuses withself_approval_impossible:<me>when the authenticated identity is on the assignee list, because the platform itself refuses an author's own approval (measured: GitHub 422). - Author-only reviewer list under
report-and-stopisBLOCKED approval_identity_absent; underreport-and-mergethe engine posts aPR-GO|v=0|head=…|no-reviewer-possible=1note in the pull request, reads it back, and continues — it never pretends a reviewer was assigned. A second run does not stack a duplicate note but still completes the rest of the step (quorum count and GO record). - The GO record must exist for the exact head.
go_record_absent:<head>andreview_quorum_unmet:<n>/<min>are checked at merge time as well as at review time. - A head that moved voids everything. The head is re-read immediately before the merge
(
head_moved:<a>_to_<b>), and the merge itself carries a head pin where the provider supports one. - A pull request already merged resumes at the read-back, not at the merge conditions: re-proving them would fail (the base tip has moved past the head) and a completed delivery would be reported as blocked.
- A landing form that lost the reviewed head is a FAIL, and the branch is KEPT on purpose
(
landing_form_unexpected:<mc>): a squash or rebase landing must be investigated, never tidied away. - Parity runs before retirement.
mirror_lagandunreachable_upstreamBLOCK with the branch kept, so a branch is never retired before the work is provably on every upstream. - Deleting an already-deleted branch is not a failure: the engine re-reads the remote to decide which of the two situations it is in.
- Markers are single lines by construction, because the read-back must stay line-parseable in pure shell:
PR-VERDICT|v=1|head=…|verdict=…|reviewer=…|substrate=…|findings=…|digest=…andPR-GO|v=1|head=…|reviews=…|reviewers=…|substrate=….pr_marker_fieldextracts one field. - The findings digest is
sha256over the text after the---line, computed by the engine, so a verdict file's digest cannot be fabricated by its author. - The quorum is counted from the PASS markers read back for that head, de-duplicated by reviewer name, and
compared with
review_fanout_min. mergeruns preflight informationally, then checks, in order: the GO record, the quorum, base ancestry (merging the base in and returningBLOCKED head_movedwhen that changes the reviewed head), mergeability (polled formergeable_poll_budget_s, default 90 s), and a final head re-read.pr_readback_and_retireis ONE implementation used by both the merge step and a resumed run that finds an already-merged pull request, so the two paths cannot drift apart: read stateMERGED, prove the merge commit's second parent is the reviewed head (or that the head is contained in the base, recorded as "form not proven"), prove parity, then retire.- The engine never force-pushes, never rewrites history, never pushes the base branch, and never closes a pull request it did not open.
pr_deliver.md— the CLI surface, exit codes and the full refusal inventory.preflight.md— the S0 gatecreatecalls andmergeruns informationally.journal.md/lock.md— the state record and the mutual exclusion every step uses.provider.md— the verbs every read-back goes through.
2026-12-04 — read against scripts/pr/lib/steps.sh (923 lines). The behaviour above is exercised by
scripts/pr/selftest.sh (279 assertions across config/preflight/lifecycle/recovery/edge_cases) and by the
eight paired mutants of scripts/pr/selftest_mutations.sh — M2 (a merge needs a verified review), M3 (the
review POST's exit code is not proof), M4 (the merge is pinned to the reviewed head) and M5 (a branch is never
retired before parity) target this file directly.