Repository navigation
feat(ci): merge-queue v2 runner core in shadow mode - #4675
Merged
Merged
Conversation
scripts/merge_queue/ composes trains from ticketed queue:ready PRs (lane then age, Depends-On, one big PR first, workflow changes alone, Zuul-like window), builds them server-side on queue-build/t<id> through the merges API with Apm-Train and Queue-Base trailers, publishes queue/t<id>/p<k>-guard|full refs that merge-train.yml proves, and reads the verdict from the -full branch at the exact SHA. State is a cache under ~/.apm-queue, rebuilt from live queue refs and trailers on restart. A ShadowApi guard refuses every write outside queue refs and the merges API, so the runner logs 'would land #n at T_k' and never writes to main. tick, run --interval 60 (file lock plus heartbeat) and metrics. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 21, 2026 19:10
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical defects break Windows CI collection, allow merges targeting main, accept stale or incomplete proofs, and lose in-flight train state during recovery.
16 open issues
Preserve HTTP 204 responses when decoding gh api output · New Reject guard-only branches as full train proofs · New Order proof runs chronologically before comparing attempts · New Make runner imports and lock tests portable to Windows · New Validate merge targets by endpoint and reject queue refs · New Keep speculative build tip separate from the main merge base · New Check ref publication responses and recover partial launches · New Reconcile live trains from remote refs after restart · New Recover train membership after guard refs are deleted · New Ignore malformed dependency marker numbers · New Defer dependents when a prerequisite merge conflicts · New Paginate collection reads before admission and composition · New Compare tree SHAs instead of merge commit SHAs · New Recognize dependencies already satisfied by main or the build base · New Clean up or track build refs from unsuccessful launches · New Check dependencies before the workflow-alone fast path · New
What changed in this PR
Adds the shadow-mode runner for merge-queue v2 step 3 (#4671), building on the exact-SHA proof workflow from #4582. It composes and tests speculative trains without landing PRs; operational acceptance remains a post-merge check.
Changes:
- Adds ticket admission, dependency-aware composition, server-side builds and proof lookup.
- Adds shadow write restrictions, state recovery, locking, heartbeat and metrics.
- Adds fake-API tests and documents runner usage.
| File | Description |
|---|---|
tests/unit/scripts/merge_queue/test_runner.py |
Tests runner ticks, write restrictions, locking and metrics. |
tests/unit/scripts/merge_queue/test_core.py |
Tests tickets, composition, refs, proofs and recovery. |
tests/unit/scripts/merge_queue/_fake_api.py |
Provides a recording fake GitHub API. |
tests/unit/scripts/merge_queue/__init__.py |
Initializes the test package. |
scripts/merge_queue/train.py |
Composes trains and builds speculative merge commits. |
scripts/merge_queue/tickets.py |
Parses tickets and checks admission requirements. |
scripts/merge_queue/state.py |
Stores train state and reconstructs it from refs. |
scripts/merge_queue/runner.py |
Coordinates shadow execution, publication and polling. |
scripts/merge_queue/refs.py |
Defines ref names, train IDs and stale-ref selection. |
scripts/merge_queue/proof.py |
Selects workflow verdicts by branch and SHA. |
scripts/merge_queue/metrics.py |
Summarizes shadow events and train durations. |
scripts/merge_queue/api.py |
Wraps GitHub REST calls through gh api. |
scripts/merge_queue/__init__.py |
Describes the shadow runner package. |
docs/src/content/docs/contributing/integration-testing.md |
Documents shadow runner commands and behavior. |
Review effort: Balanced
…ows) (#4671) fcntl is POSIX-only, so importing the runner broke Windows unit collection. The lock now uses fcntl.flock on POSIX and msvcrt.locking on Windows, imported lazily. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- api: keep the real HTTP status via --include; paginate list reads - tickets: a malformed fixes/depends list is an invalid ticket - proof: only a -full ref proves a train; order runs by created_at, id, attempt - train: defer conflict dependents transitively, treat 204 as in-base, record prefix trees, keep main as Queue-Base for stacked trains - state: rebuild walks first-parent Apm-Train trailers; reconcile cache with live - runner: per-endpoint shadow write guard, publication rollback, janitor sweep, merged dependencies count as satisfied, would-land logs commit and tree Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This was referenced Nov 21, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
This is merge-queue v2 step 3: the runner core in shadow mode. It composes, builds, publishes and proves trains, but never merges.
scripts/merge_queue/:api.pyis the GitHub REST boundary (gh api, fixed argv, no shell). Everything else takes anApi, so the logic is unit-tested against a fake.tickets.pyparses the<!-- apm-queue-ticket head=... prio=P0..P3 fixes=[..] depends=[..] -->marker, where the newest ticket wins. Its admission check requires:queue:readylabel;main;gategreen and CodeQL completed at the ticketed head.train.pyhandles composition (design section 3) and the server-side build:.github/workflowstrains alone;queue-build/t<id>at the base and calls the merges API once per member, withApm-Train: t<id> k= pr=# head= base=andQueue-Base:trailers. A 409 defers that member.refs.py:queue/t<id>/p<k>-guard|fullnaming and parsing (BATCH puts-fullon the head, PIPELINE makes every prefix-full), monotonic ids across the state and live refs, the base probe ref, and the 12 h janitor.proof.py: the verdict is the newestmerge-train.ymlrun on the-fullbranch at the exact SHA, never atrain-gatelookup by SHA alone.state.py: train states (TESTING, then GREEN, RED or ABORTED, forward only). The JSON cache lives under~/.apm-queue, andrebuild()recovers in-flight trains from the livequeue/t*refs and their commit trailers.runner.py:tick,run --interval 60(with a single-instance file lock and a heartbeat) andmetrics.ShadowApiguard refuses every write except creatingqueue/*andqueue-build/*refs, merges intoqueue-build/*, and deleting those refs.would-landevents (PR, k, predicted tree), one per member of a GREEN train.metrics.py: trains published, verdicts, green rate, would-land count, deferred count, writes to main (expected 0), and mean train minutes.Docs: a short note in
integration-testing.md(Merge-train proof).Issue and approved scope
Issue: Fixes #4671 (merge-queue v2 step 3; follows slice 1 #4582)
Human scope-approval comment: #4671 (comment)
Does this PR complete the issue, or what remains? It delivers the code. The acceptance criteria are operational and are checked after the merge:
train-gateverdict;They are measured by running the shadow runner locally; the results will be posted on #4671.
Type of change
Testing
Tested locally
All existing tests pass
Added tests for new functionality (if applicable)
pytest tests/unit/scripts/merge_queue/: the first run gave 37 passed and 2 failed. The 2 failures were missing fake routes in the tests, now added. The re-run is queued on the shared host guard (all slots busy); CI covers it.urllib.parsequery assertions.ruff 0.15.12 check/format: clean.
check_complexity_ratchet.py --base-ref main: clean.check_test_assertions.py: clean.check_exact_test_duplicates.py: clean.tests.quality.taxonomy --changed: clean.Changelog
## [Unreleased]inCHANGELOG.md:user-visible effect first, 25 words or fewer, ending with
(#PR);breaking changes only under upgrade notes; no Highlights; see
.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
N/A: no
req-XXXbehaviour changes.