docs/spec/implementation/requirements/the-script-13.md
Requirements
Section titled “Requirements”The Script — requirements, continued (part 13 of 13; 8d–8d: The arming step (D18 WI-7, same design §5.1/§6/§7; agent-ops#410)…)
Section titled “The Script — requirements, continued (part 13 of 13; 8d–8d: The arming step (D18 WI-7, same design §5.1/§6/§7; agent-ops#410)…)”8d. The arming step (D18 WI-7, same design §5.1/§6/§7; agent-ops#410).
Immediately after run_approver_stage returns — never before, and gating
nothing above it, the same placement 8b already establishes for the
Approver stage itself relative to the handoff — run_landing_stage
(lib/landing.sh, called from agent-cycle.sh’s own phase sequence)
decides whether to land the
pull request this cycle just reviewed. It arms nothing at all unless this
very round’s own Approver engagement reached an explicit, non-adjudicating
approve — an adjudication’s own land does not count, because a
disagreement settled this round is not the same fact as an engagement
that agreed the first time, and a tier the Approver stage never reached
at all (the stage disabled, a credential absent, an unparseable verdict)
arms nothing by construction. Everything else is re-read fresh from
GitHub at the moment of decision, never reused from earlier in the round
— the same discipline lib/review-gate.sh established for the ready-gate
handoff, applied here because nothing that arms an automatic merge may
trust state more than one function call old:
-
merge_autonomy_effective_level(lib/merge-autonomy.sh), called withFRESH(issue #513) so the kill switch bypasses this process’s own memo — must still beagent-merges-routineoragent-merges-all. The kill switch or a WI-6 budget freeze may have moved since the Approver stage ran. A refusal here names its actual cause (landing_autonomy_refusal_reason,lib/landing.sh, D18 issue #576, exercised end to end — one case permerge_autonomyrung — bytest/landing-kill-switch-wiring.test.sh): a second, independent read ofmerge_autonomy_kill_state(alsoFRESH, since gate 1’s own LEVEL read already carries it) tells the fleet-wide kill switch apart from a repository that simply has not had its level raised, since LEVEL alone is the collapsed answer and does not itself say why it collapsed. Thekill-switch:tag this branch prefixes onto itsreason(landing-refused, requirement 33) is what letsscripts/publish-dashboard.sh’s landings digest (byReason,dashboard/index.html) group it apart from every other refusal class, including the plain “effective level is …” wording this gate emits when the level was simply never raised — one tag among the class prefixes every colon-carrying refusal reason in this step wears (requirement 33). -
landing_eligible(lib/landing.sh) — the deterministic classifier: acomplexity:*grade in this repository’s ownmerge_autonomy_routine_complexity(default["low", "medium"]; D18 Stage 3, agent-ops#725), asourcein this repository’s ownmerge_autonomy_routine_sources, andlanding_protected_paths_hitreporting no protected path touched (.github/,deploy/,prompts/,lib/,config.schema.json,CODEOWNERS— anchored whole-path prefixes, in the shapescripts/is-docs-only.shuses for its own allowlist;lib/landing.shis self-protecting through thelib/prefix already). Reads the changed-file list fresh from GitHub (gh api repos/SLUG/pulls/N/files), bounded and truncation-checked the waylib/github-limit.sh’sGITHUB_PR_LIST_LIMITbounds agh pr list— a truncated or unreadable list isunknown, never a pass, and so is amerge_autonomy_protected_pathslist_landing_is_protectedcannot even evaluate against a path (a non-string entry, which raises rather than returns false; TD-PPagop-26082320) — never read as “no protected path touched” merely because the comparison itself failed. The two causes are distinct exit codes fromlanding_protected_paths_hit(2 for the changed-file list, 3 for the protected-paths list) andlanding_eligiblenames which one fired in its ownunknown:reason text, rather than blaming the changed-file list regardless of cause (TD-PPagop-26082325). Any exit code outsidelanding_protected_paths_hit’s documented 0/1/2/3 contract (e.g. 128+n from the command-substitution subshell being signal-killed mid-gate, agent-ops#1232) isunknowntoo —landing_eligible’s ownhit_rccase names the legitimate exit 1 explicitly and fails every other unrecognised code closed, rather than falling through to the sameeligiblearm exit 1 reaches.unknownis treated asineligibleat this and every other call site; an empty or unrecognisedsourceorcomplexityisineligible, never eligible by omission. Wideningmerge_autonomy_routine_complexityto admithighinteracts with requirement 26a, which already forces that grade onto anything touching concurrency/locking, security, CI/workflow machinery or shared library code — so this key’s ceiling and that rule’s floor meet at the same diffs, and the protected-path gate below stays in force regardless of this key (risk register item 1’s belt and braces). Protected paths refuse arming at every level belowagent-merges-allunconditionally. Atagent-merges-alla hit is deliberately reportedeligibleinstead (D18 WI-12, Stage 4, agent-ops#415) — this classifier alone cannot see the two compensating controls §7 risk 1 requires, so it defers rather than refuses, and gate 4.5 below is what actually decides. A resolvedmerge_autonomy_protected_pathsof[]— schema-valid, since the schema constrains each entry to a non-empty string but sets nominItems— disables this gate for that repository at every level: an operator may legitimately want that for a repository whose own gate code lives elsewhere, so this classifier honours the empty list exactly as any other, but reaching it silently would leave a repository atagent-merges-routineor above with its deadliest landing gate off with nothing to show for it;scripts/doctor.sh(component 14, D18 Stage 3, TD-PPagop-26082403) warns, naming the repository and its configured level, when its resolved list is empty and its configuredmerge_autonomyisagent-merges-routineor above, the same shape as its neighbouringlanding_cool_off_hours 0warning. -
review_gate_verdict(lib/review-gate.sh) — must readclean. Stricter than the ready-gate handoff’s own use of this function (requirement 31a): there, an alerts-onlyunknownstill lets the handoff proceed with a logged warning; here, any word butclean—dirtyor either flavour ofunknown— refuses arming outright. -
The Approver App’s own review is genuinely standing
APPROVEDon GitHub right now (landing_approver_standing_review,lib/landing.sh), and no humanCHANGES_REQUESTEDstands (_handoff_blocking_reviewers,lib/handoff.sh, requirement 34a’s own standing-position computation, reused rather than re-derived for the human half). Both fresh reads, and the first is not redundant with the explicitapprovegate 0 already required:approver_post_or_warnalways returns 0 even when the write itself failed (“a missing review, never a stranded PR”, requirement 8b) — a review GitHub itself refused reaches this point withapprover_stage_verdictstill readingapprove, which is this process’s own intent, never proof the review exists._handoff_latest_reviewscannot answer the first half either way — it excludes bots outright (requirement 34a), and the Approver posts as one — solanding_approver_standing_reviewreads the same endpoint directly, filtered to the App’s own login.landing_approver_standing_review_at(D18 WI-12) is what this gate actually calls — the same one reviews-list read, plus the standing review’s ownsubmitted_atandcommit_id, at no extra cost — since gate 4.5 needs both and it is never worth a second fetch.Neither of the two reads above sees a plain comment: a human cannot leave a formal
REQUEST_CHANGESreview on this system’s own pull requests at all (GitHub refuses that review type from a pull request’s own author, and every pipeline write and every human comment here land under the same account), so an ordinary comment is their only instrument, and_handoff_blocking_reviewersreads only formal reviews.lib/reconciliation-gate.sh’sreconciliation_gate(requirement 31c, agent-ops#533) already closes that gap at the Reviewer’s own ready-flip — a pull request carrying an unreconciled comment since it last left draft cannot be flipped Ready in the first place — but that gate runs once, at hand-off, and does not reach here: a plain comment posted after the pull request is already Ready, in the window before a later cycle’s arming step lands it, was answered by neither mechanism (agent-ops#672). Gate 4 closes that residual window by callingreconciliation_gateitself a second time, unbounded (noNOT_AFTER) — this stage never flips the pull request out of draft the way the Reviewer’s own call must guard against, so the real current “last left draft, and stayed left” anchor is exactly the read this gate needs.dirtyrefuses arming, naming the unreconciled comment(s) as the reason; any other answer that is notclean—unknown, where the timeline or the comment list could not be read, and the empty word left behind by a call that did not execute at all — refuses too (#753’s ruling on agent-ops#746), naming the pull request and what could not be confirmed. Neither is unfolded as a case distinct from the other, and neither is conditioned onmerge_autonomy_effective_level: unlike the Reviewer’s own reconciliation read at hand-off, which does tolerate anunknownthere with a logged warning, this arming-time instance never lets an unanswered question pass. Only the exact wordcleanpasses silently: a veto check that reads as clear on the one path where it never ran is the failure this gate exists to prevent. Because every non-cleanword now refuses before this gate sequence can reach an arm, the landing audit record (acceptance check 8x) can only ever carry acomment-reconciliationentry readingclean. 4.5. D18 WI-12 (Stage 4, agent-ops#415): only atagent-merges-all, and only for a pull requestlanding_protected_path_controls_ok(lib/landing.sh) itself re-confirms still touches a protected path — gate 2 above already deferred, rather than refused, that case. Three controls must hold — the two compensating controls §7 risk 1 names, plus the head-match that is what makes the second of them measurable here: the approving engagement ran at the Critical tier (requirement 8b’s owncritical_reason; read from this round’s own in-process fact on the round that first approved the pull request, or from the fleet log’sapprover-verdictevent,landing_retry_tier, on a landing-retry sweep re-arm outside that round — acceptance check 8u); the standing review’s owncommit_id(gate 4’s own read) still matches a fresh read of the pull request’s currentheadRefOid; and the configurablelanding_cool_off_hours(default 24,0disables) has elapsed since gate 4’s ownsubmitted_at, re-read fresh every time this gate runs rather than cached anywhere. A push after approval movesheadRefOidwithout touching the standing review at all — nothing in this pipeline dismisses a stale review on push — so acommit_idmismatch refuses on its own, regardless of how much of the cool-off has otherwise elapsed: there is no freshersubmitted_atto measure from until the Approver reviews the new head, which is the sense in which a fresh push restarts the wait rather than merely pausing it. Any control unmet refuses, naming the tier it actually found, the mismatched commits, or the remaining cool-off time; an unreadable re-check of the changed-file list or of the pull request’s current head isunknown, never a pass. A pull request that does not touch a protected path at all clears this gate immediately, since none of the three controls applies to it. -
merge_budget_decide/merge_budget_apply_decision(lib/merge-budget.sh, requirement 2.3c) — onlyarmproceeds.hold(the budget is exhausted) andrefuse(the count could not be established) are applied — loggingmerge-budget-hold, or awarningforrefuse— and stop here; neither arms anything, and this call itself does not queue a retry of its own. The landing-retry sweep (acceptance check 8u, “## The Landing Gate”) is what re-enters this whole gate sequence for such a pull request on a later cycle, rather than this gate doing so itself.merge_budget_decidereads an ALREADY_ARMED count from its own caller and discounts it from the live merged-PR count before comparing to the cap — GitHub’s own record only ever shows a pull request as merged once the merge has actually landed, never the moment this gate arms its enqueue or auto-merge, so any two calls into this gate within one cycle must share a running tally or each reads the same not-yet-merged count and both arm (requirement 8u’s own bound; PR #557 review round 2 widened this from a tally private to the landing-retry sweep’s own pass tolanding_armed_by_repo, a cycle-scoped map keyed by repository slug that this gate’s two call sites — the sweep and this stage’s own gate 0 — both read and grow, since either can run first within one cycle process). -
merge_queue_probe(lib/merge-queue.sh) — the pull request must not already be queued, and must not have been queued and removed without being re-queued since. “Could not read” is “possibly queued or dequeued” (the same rule the merge-queue-awareness discipline already applies elsewhere in this document), so it refuses too. A dequeue this stage finds is never its own to retry (PR #557 review round 2):merge_queue_dequeue_actionable(lib/merge-queue.sh) only ever chooses the refusal’s wording, never whether it refuses — amanualremoval is the maintainer’s own deliberate act, reversing it would silently undo their click every cycle for as long as the pull request stays open, and any other reason (chieflyfailed_checks) is exactly whatscripts/gather-dequeued.sh’s owndequeuedsource exists to diagnose and fix before a human re-queues — arming it blindly here instead would re-run the same failing merge group once per cycle indefinitely, for no forward progress.
Any read above that cannot be answered is a refusal — logged
landing-refused (requirement 33) — never a pass, and every refusal
path costs exactly that: one log event, never a blocked pull request,
never a withheld claim, the same “a missing action costs a missing
action, never a stranded PR” contract 8b already establishes for the
Approver stage. Only once every gate above clears does landing_arm
(lib/landing.sh) perform the one write: merge_queue_for_branch
(lib/merge-queue.sh, beside merge_queue_probe) reads whether the pull
request’s base branch itself carries an active merge queue — where it
does, enqueuePullRequest (GraphQL); where it does not, gh pr merge --auto --squash. Both run under the Approver App’s own minted
installation token, as a leading one-invocation GH_TOKEN="$token" gh …
assignment — never export, exactly as approver_post_review already
does and for the same reason: never the pipeline’s own authoring
identity — the owner’s GH_TOKEN, or, once provisioned, the forge
authoring App (D25, component 14g) — which would collapse the
two-identity audit trail §5.3 exists for into the same account
authoring, approving and landing every pull request. A successful arm
logs landing-armed
exactly once, naming the method actually used (enqueued or
auto-merge), and never withholds anything requirement 8b already did.
auto-merge names the call made (gh pr merge --auto --squash), not a
guarantee it armed anything to fire later: with the gh CLI version the
node image installs, that call merges the pull request immediately from
CLEAN/UNSTABLE rather than deferring, and only genuinely arms
auto-merge from BLOCKED (agent-ops#553; lib/landing.sh’s own header
carries the full finding).
The fleet-wide kill switch and a per-repository downgrade (setting
merge_autonomy back to human or agent-approves) both disarm
cleanly: merge_autonomy_effective_level is what gate 1 above reads,
never the raw configured value, so the very next round this function
runs for a repository at or below agent-approves refuses at gate 1
before any other read — no separate switch, no partial disarm.