Skip to content

feat(mq): merge-queue v2 step 4 - landing loop and closure audit (dormant behind --land) - #4698

Merged
Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
p-mq4-landing
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
p-mq4-landing

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This is merge-queue v2 step 4: the landing loop and the closure audit. Landing is dormant by default: the runner stays shadow-only unless it is started with --land. Turning landing on is a separate maintainer gate, after the v0.38.0 tag and the step-3 shadow acceptance.

scripts/merge_queue/:

  • landing.py admin-merges GREEN trains in launch order, one member at a time.
    • Elevation: an admin probe with a 2-probe lapse rule. One failed probe skips the tick. Two in a row declare a lapse, which raises one needs-input event. The first good probe after that resumes landing and drains the backlog in order. Trains keep testing throughout.
    • Lease estimate: the backlog's member count x 20 s, logged before landing.
    • Pre-merge checks:
      • main has not moved outside the runner (main_seen);
      • main's tree is the tree the member was proven on (the prefix k-1, or the build tip for k=1);
      • the PR's head is the proven head, its base is main, and it is not already merged.
    • The merge is gh pr merge --merge --admin --match-head-commit <proven head>. It retries up to 3 times on rule-violation responses, then pauses; it never halts on those.
    • Post-merge checks: the merge commit has parents (old main, head) and the proven tree T_k, and it is main's head.
    • HALT: any drift, or an external merge to main, stops landing and records the reason in landing.json until a human clears it. Trains keep testing.
    • Hooks: a needs-input event per lapse, and one ejection-notice event (with a comment body for autopilot-comment) per member of a red train.
  • closure.py and the landing preflight:
    • Before any member of a train merges, the issues GitHub will close (closingIssuesReferences plus closing keywords in the PR's commit messages) must equal the ticket's fixes. Every unlanded member also needs a valid ticket at its proven head.
    • On a failure, the train is ejected unmerged with one notice per member. If it is already partly landed, landing HALTs.
    • After the merge, the runner closes any fix GitHub left open and retargets PRs stacked on the landed branch. Every write is checked; a failed one stays pending and retries on the next tick.
  • Crash safety: a merge intent is journaled and checkpointed before each merge and cleared after it is recorded. recover() reconciles an outstanding intent against GitHub on the next tick.
  • Ordering: the landing backlog stops at the first train still TESTING. With --land, new trains stack on proven trains that have not landed yet (State.chain).
  • runner.py:
    • Adds the --land flag. Train building still goes through ShadowApi, which now also refuses PATCH.
    • Adds a LANDED state (GREEN -> LANDED or ABORTED) and Member.merged.
    • PRs aboard a GREEN, not-yet-landed train are not re-trained.
  • api.py: adds patch.

Docs: one paragraph in integration-testing.md (Merge-train proof).

Issue and approved scope

Issue: Fixes #4690 (merge-queue v2 step 4; follows step 3 #4671)

Human scope-approval comment: #4690 (comment)

Does this PR complete the issue, or what remains? It delivers the code, with landing off by default. The live acceptance criteria are checked after activation, a separate gate that comes after the v0.38.0 tag and the step-3 acceptance:

  • at least 20 runner landings with 0 tree mismatches;
  • a closure audit with 0 misses on seeded cases;
  • a simulated lapse that pauses landing and then resumes in order;
  • an external merge that HALTs the runner.

The unit tests below already cover each of these behaviours against a simulated GitHub.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally

  • All existing tests pass

  • Added tests for new functionality (if applicable)

  • test_landing.py runs against a simulated GitHub. It covers:

    • the lapse rule, and a failed probe counting as a miss;
    • landing at the proven heads and trees, with landing off unless the runner is started with --land;
    • HALT on a wrong tree and on an external merge;
    • a lapse pausing landing and resume draining the backlog in order;
    • a rule violation retried, then paused;
    • closure: a mismatch, including a commit-message "Fixes", ejecting the train before any merge; a withdrawn ticket ejecting it; a fix GitHub left open being closed, and a stacked PR retargeted; a rejected write staying pending;
    • crash recovery from the intent journal;
    • a GREEN train waiting behind an earlier train still testing;
    • ejection notices while halted, and the landing-state round trip.
  • test_runner.py adds: with --land, new trains stack on an unlanded GREEN train; the shadow guard refuses PATCH.

  • After the review fixes, test_landing.py and test_runner.py pass locally (41 tests, via the host guard).

  • Static checks, all clean:

    • ruff 0.15.12 check and format;
    • check_complexity_ratchet.py --base-ref main;
    • check_test_assertions.py;
    • tests.quality.taxonomy --changed;
    • pylint R0801.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

N/A: no req-XXX behaviour changes.

- landing.py: 2-probe elevation lapse rule, lease estimate, pre-merge tree/head/base
  checks, gh pr merge --merge --admin --match-head-commit with bounded retry on rule
  violations, post-merge parents and proven-tree check, HALT on drift or external merge,
  one needs_input per lapse, one ejection notice per red-train member
- closure.py: closingIssuesReferences vs ticket fixes; post-merge close/reopen;
  stacked-PR retarget
- runner: --land flag (default shadow); ShadowApi refuses PATCH; LANDED state

Fixes #4690

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical issues can land trains out of order, trigger false drift halts, lose merge recovery records, and allow merges without valid tickets or the required clean closure audit.

9 open issues
What changed in this PR

Adds the opt-in landing stage for merge-queue v2, extending the existing shadow runner with administrative merges and post-merge issue repair. Landing remains disabled unless --land is supplied; live acceptance follows a separate activation gate.

Changes:

  • Adds ordered landing, elevation checks, merge verification, persistent HALT records, and notification hooks.
  • Adds closure auditing, deferred issue repair, stacked-PR retargeting, and landing-state tracking.
  • Extends simulated GitHub tests, shadow-write protection, and contributor documentation.
File Description
tests/​unit/​scripts/​merge_queue/​test_runner.py Tests shadow-mode PATCH rejection.
tests/​unit/​scripts/​merge_queue/​test_landing.py Tests landing, lapse recovery, HALTs, and closure repair.
tests/​unit/​scripts/​merge_queue/​_fake_api.py Adds simulated PATCH responses and call tracking.
scripts/​merge_queue/​state.py Adds landed states, merged-member tracking, and backlog selection.
scripts/​merge_queue/​runner.py Wires opt-in landing into runner ticks.
scripts/​merge_queue/​landing.py Implements merge checks, elevation handling, recovery state, and hooks.
scripts/​merge_queue/​closure.py Audits issue references, repairs closures, and retargets stacked PRs.
scripts/​merge_queue/​api.py Adds PATCH support to the API abstraction.
docs/​src/​content/​docs/​contributing/​integration-testing.md Documents opt-in landing and its safeguards.

Review effort: Balanced

Comment thread scripts/merge_queue/landing.py Resolved
Comment thread scripts/merge_queue/landing.py Resolved
Comment thread scripts/merge_queue/landing.py Resolved
Comment thread scripts/merge_queue/runner.py Resolved
Comment thread scripts/merge_queue/runner.py Resolved
Comment thread scripts/merge_queue/state.py Resolved
Comment thread scripts/merge_queue/closure.py Resolved
Comment thread scripts/merge_queue/landing.py Resolved
Comment thread scripts/merge_queue/landing.py Resolved
- probe: a failed admin request is a failed probe (lapse rule), not a crash
- preflight: every unlanded member needs a valid ticket at its proven head and a
  clean closure audit (closingIssuesReferences + commit keywords == fixes); else
  the train is ejected unmerged (or HALTs if partly landed)
- intent journal: checkpoint before and after each merge; a crash in between is
  recovered on the next tick instead of reading as external drift
- backlog stops at the first TESTING train; with --land new trains stack on
  unlanded GREEN trains (State.chain)
- closure writes are checked; failed ones stay pending and retry
- ejection notices are emitted even while landing is halted

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 6c0cb7c into main Nov 22, 2026
50 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the p-mq4-landing branch November 22, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] ci: merge-queue v2 step 4 - landing loop (admin merge) and closure audit

2 participants