Skip to content

Latest commit

 

History

History
137 lines (113 loc) · 8.42 KB

steps.md

File metadata and controls

137 lines (113 loc) · 8.42 KB

steps.sh — guide

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.

Overview

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.

Prerequisites

  • A validated declaration and an initialised journal; the lock is taken before the first mutation.
  • git and the provider adapter (see provider.md) with a working credential.
  • For S11: scripts/sync/verify_upstream_parity.sh. If that instrument is absent the step reports instrument_absent and returns 2 (unreachable), never a pass.

Usage examples

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-run

The 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

Edge cases

  • create on 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 records committed no_new_commit=1 and 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> or pr_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_absent are 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_branch and the (c) merge condition both use git merge --no-ff/--no-edit, because a rebase would rewrite the reviewed history. A conflict is BLOCKED 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-event the engine refuses with self_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-stop is BLOCKED approval_identity_absent; under report-and-merge the engine posts a PR-GO|v=0|head=…|no-reviewer-possible=1 note 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> and review_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_lag and unreachable_upstream BLOCK 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.

Internal behaviour

  • 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=… and PR-GO|v=1|head=…|reviews=…|reviewers=…|substrate=…. pr_marker_field extracts one field.
  • The findings digest is sha256 over 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.
  • merge runs preflight informationally, then checks, in order: the GO record, the quorum, base ancestry (merging the base in and returning BLOCKED head_moved when that changes the reviewed head), mergeability (polled for mergeable_poll_budget_s, default 90 s), and a final head re-read.
  • pr_readback_and_retire is 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 state MERGED, 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.

Related scripts

  • pr_deliver.md — the CLI surface, exit codes and the full refusal inventory.
  • preflight.md — the S0 gate create calls and merge runs informationally.
  • journal.md / lock.md — the state record and the mutual exclusion every step uses.
  • provider.md — the verbs every read-back goes through.

Last verified

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.