Skip to content

feat(bin): merge native GitHub stacked pull requests through the async merge API - #94

Merged
andrewesweet merged 6 commits into
mainfrom
fm/fm-stack-merge
Oct 1, 2026
Merged

andrewesweet merged 6 commits into
mainfrom
fm/fm-stack-merge

Conversation

@andrewesweet

@andrewesweet andrewesweet commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Intent

bin/fm-pr-merge.sh cannot merge a pull request that belongs to a native GitHub stack, because GitHub accepts stacked merges only through its asynchronous merge API. The helper gains a stacked path, chosen automatically from GitHub's record of the stack, that merges one layer at a time bottom-up with a merge commit through the asynchronous API, binds the verified head into the request, keeps every existing guard, and reports a landing only after a live read-back proves the merge.

What Changed

  • bin/fm-pr-merge.sh now reads the pull request's REST stack object to tell stacked, standalone, and undeterminable PRs apart. Standalone PRs keep the existing synchronous gh pr merge path. If the stack record can't be read or has an unrecognised shape, the helper refuses before it records anything.
  • Stacked PRs merge through GitHub's asynchronous merge API, one layer at a time, from the bottom up. Each merge is a merge commit bound to the verified head. Before submitting, the helper checks that the stack's record shows every lower layer already merged and that the PR's base is the stack's base. All existing live gates still apply: mergeable state, green checks, required checks, merge-queue state, and the pipeline's validated-head rule for no-mistakes tasks. The helper also refuses a stacked merge when:
    • --squash, --rebase, or any forge flag is passed, even with --attended-override
    • the away-posture record exists (exit 2)
  • The submit's 202 response is polled until the result is final. A failed result quotes GitHub's own report and retires the merge authority. A merged result counts as landed only after a live read-back confirms the PR merged with its head still the bound one. If the result can't be read or is still pending after 300 polls, the merge authority and the armed merge poll are left in place to report the landing later. docs/architecture.md summarises the stacked path, and tests/fm-pr-merge.test.sh adds coverage for detection, ordering, refusals, submit/poll outcomes, and the head check on read-back.

🤖 Generated with Claude Code

Risk Assessment

⚠️ Medium: The stacked path is gated well and keeps the existing guards, but it adds a pipeline-validation gate the intent does not ask for, and a quote-handling bug in that gate's fallback can wrongly refuse merges. Both are worth resolving, but neither can cause an unsafe merge.

Testing

I drove the fix live on a fresh two-layer native stack in the authorised scratch repo andrewesweet/stacked-pr-lab. For the bottom layer, a descendant commit was pushed after verification and before the async submit. GitHub merged only the bound head 906d412. The script now exits 1 with a disagreement naming 906d412 and the newer commit 3451da2, prints no landing line, keeps the merge authority and publishes no outcome; in round 2 the same race was reported as a landing. The restacked top layer then merged through the async API with a two-parent merge commit and exactly one verified landing (exit 0). This shows the head comparison does not block a valid merge. All 16 stacked fixture tests pass. The new regression test fails against the previous script and passes against the fix. These fixture results are recorded below as untested scenarios because they were not run against the live product. The scratch repo was kept; the local lab directory was removed and the worktree is clean. This is a CLI change, so the evidence is transcripts rather than screenshots.

  • Live validation: ✅ go - 2 of 4 scenarios driven live against the product
Scenario Result Live Evidence
A commit pushed onto a stacked layer after verification is reported as a disagreement naming both heads, not as a landing ✅ pass live live-round3-descendant-race-refused.txt: GitHub merged bound head 906d412 (merge commit 64ce460); PR head reads 3451da2, which diverged from main; script exited 1 with the disagreement error, no 'is m…
The next layer, restacked by GitHub, merges through merge-async with the verified head and a merge commit, and the landing is reported exactly once ✅ pass live live-round3-next-layer-lands.txt: PUT merge-async merge_method=merge sha=f8eaa7e -> pending -> merged; read-back head f8eaa7e equals the bound head; one 'is merged' line, rc=0, pr-poll-merge-notified…
Regression: the newer-head stub case fails before the fix and passes after it ⏸️ untested no The prior payload established this only with a fixture/stub test (regression-newer-head-before-fix.log fails at 8ef2141, regression-newer-head-after-fix.log passes at 40c2247), not a live result. It…
Guards that need required checks, a merge queue, protected-branch rules or away posture still refuse on the stacked path ⏸️ untested no The prior payload established this only through fixture tests (stacked-fixture-tests-round3.log: 16 test_stacked_* ok), not a live result. Driving it live needs repository admin setup of required CI c…
Evidence: Live descendant race now refused (PR #9)

Source: Live descendant race now refused (PR #9)

\### Round 3 (target 40c22470): descendant commit pushed onto r31790825820-l1 after verify, before merge-async submit
\### PR 9 before: {"baseRefName":"main","headRefOid":"906d412c9a67f2043b09736408c710492344924d","mergeStateStatus":"CLEAN","mergeable":"MERGEABLE","number":9}
$ fm-pr-merge.sh r1 https://github.com/andrewesweet/stacked-pr-lab/pull/9
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  2 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
armed: state/r1.check.sh
verified: https://github.com/andrewesweet/stacked-pr-lab/pull/9 is open and mergeable, with every unwaived required check reported and every unwaived check green at head 906d412c9a67f2043b09736408c710492344924d
error: GitHub reports the asynchronous merge request 714f222f-66ef-4c7e-96f5-ef4b005ac744 for https://github.com/andrewesweet/stacked-pr-lab/pull/9 merged, but the pull request's head reads back as 3451da2ffc131ac11503f1de4e925ae7a504d9ad, not the bound verified head 906d412c9a67f2043b09736408c710492344924d; the bound head landed but the newer pushed commit 3451da2ffc131ac11503f1de4e925ae7a504d9ad is not on the base; this is a disagreement, the merge authority stays, and the merge poll remains armed
rc=1
count of 'is merged' landing lines: see above
--- gh calls
api repos/andrewesweet/stacked-pr-lab/pulls/9
pr view https://github.com/andrewesweet/stacked-pr-lab/pull/9 --json headRefOid -q .headRefOid
pr view https://github.com/andrewesweet/stacked-pr-lab/pull/9 --json state,isDraft,mergeable,mergeStateStatus,headRefOid,baseRefName,statusCheckRollup
api repos/andrewesweet/stacked-pr-lab/branches/main
api --paginate repos/andrewesweet/stacked-pr-lab/rules/branches/main
api --paginate repos/andrewesweet/stacked-pr-lab/rules/branches/main --jq .[] | select(.type == "merge_queue") | "merge_method=" + (.parameters.merge_method // "")
api repos/andrewesweet/stacked-pr-lab/stacks/11
api --include -X PUT repos/andrewesweet/stacked-pr-lab/pulls/9/merge-async -f merge_method=merge -f merge_action=direct_merge -f sha=906d412c9a67f2043b09736408c710492344924d
[race] pushed 3451da2ffc131ac11503f1de4e925ae7a504d9ad to r31790825820-l1 just before the submit
api --include -X GET repos/andrewesweet/stacked-pr-lab/pulls/9/merge-async/714f222f-66ef-4c7e-96f5-ef4b005ac744
api --include -X GET repos/andrewesweet/stacked-pr-lab/pulls/9/merge-async/714f222f-66ef-4c7e-96f5-ef4b005ac744
api --include -X GET repos/andrewesweet/stacked-pr-lab/pulls/9/merge-async/714f222f-66ef-4c7e-96f5-ef4b005ac744
api graphql -f query=query($owner:String!,$repo:String!,$number:Int!){repository(owner:$owner,name:$repo){pullRequest(number:$number){state merged isInMergeQueue baseRefName}}} -F owner=andrewesweet -F repo=stacked-pr-lab -F number=9 --jq .data.repository.pullRequest | "state=" + (.state // ""), "merged=" + (.merged | tostring), "queued=" + (.isInMergeQueue | tostring), "base=" + (.baseRefName // "")
pr view https://github.com/andrewesweet/stacked-pr-lab/pull/9 --json headRefOid --jq .headRefOid
--- live PR 9 afterwards
{"head":"3451da2ffc131ac11503f1de4e925ae7a504d9ad","merge_commit_sha":"64ce460cd08047d012f9799eaa403e00d112f21a","merged":true,"state":"closed"}
{"parents":["c04a6668c6d375dbfcfe4ea0f976f89375e126d5","906d412c9a67f2043b09736408c710492344924d"],"sha":"64ce460cd08047d012f9799eaa403e00d112f21a"}
newer pushed commit 3451da2ffc131ac11503f1de4e925ae7a504d9ad vs main: diverged
--- r1 state files: r1.check.sh r1.merge-authority r1.meta r1.pr-poll r1.pr-poll-registration 
Evidence: Live next layer lands once (PR #10)

Source: Live next layer lands once (PR #10)

\### Round 3 (target 40c22470): next layer PR 10 after GitHub restacked it onto main; no race
\### PR 10 before: {"baseRefName":"main","headRefOid":"f8eaa7e23c06f0caf7cd942213f59c977d7011ca","mergeStateStatus":"CLEAN","mergeable":"MERGEABLE","number":10}
$ fm-pr-merge.sh r2 https://github.com/andrewesweet/stacked-pr-lab/pull/10
rc=0
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
armed: state/r2.check.sh
verified: https://github.com/andrewesweet/stacked-pr-lab/pull/10 is open and mergeable, with every unwaived required check reported and every unwaived check green at head f8eaa7e23c06f0caf7cd942213f59c977d7011ca
verified: https://github.com/andrewesweet/stacked-pr-lab/pull/10 is merged (state=MERGED, merged=true, isInMergeQueue=false)
count of 'is merged' landing lines: 1
--- gh calls
api repos/andrewesweet/stacked-pr-lab/pulls/10
pr view https://github.com/andrewesweet/stacked-pr-lab/pull/10 --json headRefOid -q .headRefOid
pr view https://github.com/andrewesweet/stacked-pr-lab/pull/10 --json state,isDraft,mergeable,mergeStateStatus,headRefOid,baseRefName,statusCheckRollup
api repos/andrewesweet/stacked-pr-lab/branches/main
api --paginate repos/andrewesweet/stacked-pr-lab/rules/branches/main
api --paginate repos/andrewesweet/stacked-pr-lab/rules/branches/main --jq .[] | select(.type == "merge_queue") | "merge_method=" + (.parameters.merge_method // "")
api repos/andrewesweet/stacked-pr-lab/stacks/11
api --include -X PUT repos/andrewesweet/stacked-pr-lab/pulls/10/merge-async -f merge_method=merge -f merge_action=direct_merge -f sha=f8eaa7e23c06f0caf7cd942213f59c977d7011ca
api --include -X GET repos/andrewesweet/stacked-pr-lab/pulls/10/merge-async/2da6e369-1cc6-4575-859f-cdca3e8b327d
api --include -X GET repos/andrewesweet/stacked-pr-lab/pulls/10/merge-async/2da6e369-1cc6-4575-859f-cdca3e8b327d
api --include -X GET repos/andrewesweet/stacked-pr-lab/pulls/10/merge-async/2da6e369-1cc6-4575-859f-cdca3e8b327d
api graphql -f query=query($owner:String!,$repo:String!,$number:Int!){repository(owner:$owner,name:$repo){pullRequest(number:$number){state merged isInMergeQueue baseRefName}}} -F owner=andrewesweet -F repo=stacked-pr-lab -F number=10 --jq .data.repository.pullRequest | "state=" + (.state // ""), "merged=" + (.merged | tostring), "queued=" + (.isInMergeQueue | tostring), "base=" + (.baseRefName // "")
pr view https://github.com/andrewesweet/stacked-pr-lab/pull/10 --json headRefOid --jq .headRefOid
--- live PR 10 afterwards
{"head":"f8eaa7e23c06f0caf7cd942213f59c977d7011ca","merge_commit_sha":"55685cad990278899e259cf414bdaaec606554ca","merged":true,"state":"closed"}
{"parents":["64ce460cd08047d012f9799eaa403e00d112f21a","f8eaa7e23c06f0caf7cd942213f59c977d7011ca"],"sha":"55685cad990278899e259cf414bdaaec606554ca"}
--- stack 11: {"layers":[{"merged_at":"2026-10-01T03:37:50Z","number":9},{"merged_at":"2026-10-01T03:38:54Z","number":10}],"open":false}
--- r2 state files: r2.check.sh r2.merge-authority r2.meta r2.pr-poll r2.pr-poll-merge-notified r2.pr-poll-registration 
Evidence: Round 3 live summary

Source: Round 3 live summary

Round 3, target 40c22470. Scratch repo andrewesweet/stacked-pr-lab (private, KEPT). New native stack #11 = PR #9 (layer 1, base main), PR #10 (layer 2).
Descendant race (fix under test): a commit 3451da2 was pushed onto layer 1 after fm-pr-merge.sh verified head 906d412 and just before the merge-async submit.
  GitHub 202 -> merged exactly the bound head 906d412 (merge commit 64ce460, parents c04a666 + 906d412); 3451da2 diverged from main.
  Script now: rc=1, "error: ... head reads back as 3451da2..., not the bound verified head 906d412...; the bound head landed but the newer pushed commit ... is not on the base; this is a disagreement, the merge authority stays, and the merge poll remains armed".
  No "verified: ... is merged" line; r1.merge-authority kept; no r1.pr-poll-merge-notified. (Round 2 at 8ef21411 reported rc=0 and a landing for the same race.)
Next layer PR #10 (restacked by GitHub onto main, head f8eaa7e) with no race: merge-async sha=f8eaa7e -> pending -> merged -> read-back head f8eaa7e == bound -> exactly one "is merged" line, rc=0, r2.pr-poll-merge-notified written. Merge commit 55685ca parents 64ce460 + f8eaa7e. Stack #11 closed.
Fixture: 16 test_stacked_* ok (stacked-fixture-tests-round3.log). New regression test fails against 8ef21411's script and passes at 40c22470 (regression-newer-head-{before,after}-fix.log).
Evidence: Stacked fixture tests (round 3)

Source: Stacked fixture tests (round 3)

ok - a stacked lowest layer merges through the asynchronous API with the verified head bound and the outcome published once
ok - a stacked pull request accepts no method, --merge or --method merge and refuses every other method
ok - a stacked pull request refuses auto-merge, admin, deletion and unknown flags even attended
ok - undeterminable stack membership refuses before anything is recorded
ok - the stacked path refuses until the pull request is the lowest unmerged layer with the stack base retargeted
ok - a stacked pull request is refused with exit 2 while the away-posture record exists
ok - a stacked pull request refuses a merge-queue base or unreadable rules before the submit
ok - a failed stacked result quotes GitHub's text, records nothing landed, and retires the authority
ok - an unreadable, vanished or still-pending stacked result keeps the authority and reports nothing landed
ok - submit answers other than 202 pending never report a landing
ok - a merged answer with a conflicting read-back is a disagreement, never a landing
ok - a stacked merge whose pull request head moved past the bound head is a disagreement, never a landing
ok - a stacked merge refuses a head the pipeline has not validated with a running ci step
ok - the stacked path keeps the red, pending and unreported-required check gates
ok - a direct-PR task merges through the stacked request without the pipeline validated-head rule
ok - --allow-red on a stacked pull request reaches the submit with the verified head bound
Evidence: Regression test fails before the fix

Source: Regression test fails before the fix

not ok - stacked-merged-newer-head: a merge that left a newer pushed head off the base must exit non-zero
Evidence: Regression test passes after the fix

Source: Regression test passes after the fix

ok - a stacked merge whose pull request head moved past the bound head is a disagreement, never a landing
Evidence: Live script output for the race
verified: https://github.com/andrewesweet/stacked-pr-lab/pull/9 is open and mergeable ... at head 906d412c9a67f2043b09736408c710492344924d
error: GitHub reports the asynchronous merge request 714f222f-... for https://github.com/andrewesweet/stacked-pr-lab/pull/9 merged, but the pull request's head reads back as 3451da2ffc131ac11503f1de4e925ae7a504d9ad, not the bound verified head 906d412c9a67f2043b09736408c710492344924d; the bound head landed but the newer pushed commit 3451da2ffc131ac11503f1de4e925ae7a504d9ad is not on the base; this is a disagreement, the merge authority stays, and the merge poll remains armed
rc=1
- Outcome: 🔧 1 issue found → auto-fixed (2) ✅ across 3 runs (40m49s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 warning
  • ⚠️ bin/fm-pr-merge.sh:1607 - Spec: the validated-head fallback is not unquoted. validated=$(fm_nm_field "$out" head_sha) keeps the TOON quotes, so head_sha: "<sha>" is read as "<sha>". When the status document has no branch_sync.pipeline.current_head (an older CLI, or a run with no branch sync), "<sha>" never equals FM_PR_MERGE_HEAD, and git rev-parse on the quoted string fails. The stacked merge then always refuses with 'has not validated the live head', even though the pipeline validated exactly that head. The sibling reader at bin/fm-dod-lib.sh:761 wraps the same call in fm_nm_strip_quotes; do the same here. The ci step state parsed by github_nm_ci_step_state (bin/fm-pr-merge.sh:1608) is also compared raw to running, so a quoted status cell would fail the same way.
  • ⚠️ bin/fm-pr-merge.sh:1591 - Spec: github_verify_pipeline_validated_head adds a new gate that the intent does not ask for. The intent requires the helper to bind the verified head and keep every existing guard. This gate goes further: for a no-mistakes task it requires a readable no-mistakes axi status whose validated head matches the live head and whose ci step is running and active. The synchronous path has no such rule. A stacked layer of a no-mistakes task therefore cannot merge once its pipeline has finished, or when the no-mistakes CLI or worktree is missing, while the same PR standing alone would merge. It also brings in new helpers (github_nm_ci_step_state and github_nm_ci_step_active, local copies of the fm-crew-state row parsing) and a new library dependency (the fm-nm-run-lib.sh source line). Suggested remedy: remove this component, or have the author confirm it is wanted as part of the stacked contract.
  • ℹ️ bin/fm-pr-merge.sh:1423 - Standards: this comment is false and the assignment it justifies is redundant. github_detect_stack_membership says 'the stacked path skips the mergeable read that otherwise sets this for it' and sets FM_PR_GITHUB_BASE. In fact the stacked path does run github_verify_mergeable (bin/fm-pr-merge.sh:1867), which overwrites FM_PR_GITHUB_BASE with the live base before github_refuse_queue_for_stack reads it. The header's own claim that every existing live gate still runs on the stacked path contradicts this comment. Remove the comment and the assignment, or correct the comment.
  • ℹ️ bin/fm-pr-merge.sh:1501 - Spec: github_verify_stack_order judges which layers are 'below' this PR by their order in the pull_requests array, not by each layer's position. FM_PR_STACK_POSITION is read but used only in an error message. If GitHub lists layers in any other order, a lower unmerged layer that appears after this PR is skipped. Only the base == stack-base check would then stop an out-of-order merge. Sort the entries by .position in the jq expression at line 1515 (or compare against FM_PR_STACK_POSITION) so the 'every lower layer merged' rule does not depend on array order. Relatedly, the base comparison at line 1525 uses FM_PR_BASE_REF from the earlier detection read, not the live FM_PR_GITHUB_BASE just verified by the mergeable read.

🔧 Fix applied.
1 warning still open:

  • ⚠️ bin/fm-pr-merge.sh:1591 - Spec: github_verify_pipeline_validated_head adds a new gate that the intent does not ask for. The intent requires the helper to bind the verified head and keep every existing guard. This gate goes further: for a no-mistakes task it requires a readable no-mistakes axi status whose validated head matches the live head and whose ci step is running and active. The synchronous path has no such rule. A stacked layer of a no-mistakes task therefore cannot merge once its pipeline has finished, or when the no-mistakes CLI or worktree is missing, while the same PR standing alone would merge. It also brings in new helpers (github_nm_ci_step_state and github_nm_ci_step_active, local copies of the fm-crew-state row parsing) and a new library dependency (the fm-nm-run-lib.sh source line). Suggested remedy: remove this component, or have the author confirm it is wanted as part of the stacked contract.
🔧 **Test** - 1 issue found → auto-fixed (2) ✅
  • ⚠️ live validation verdict: inconclusive (1 of 7 scenarios were driven live against the product); untested: The lowest layer of a stack merges through the asynchronous API with the verified head and a merge commit, and the landing is reported once after the read-back, Merging a higher layer before the lower layers have merged is refused, Existing guards still refuse on the stacked path: red, pending and unreported required checks, away posture, merge-queue base, protected flags even when attended, and methods other than merge, A pending, failed, unreadable or contradicted asynchronous result never reports a landing, When stack membership cannot be determined, the script refuses before recording anything, A head the pipeline has not validated is refused; direct-PR tasks skip that rule; --allow-red still reaches the submit
  • Live validation: ⚠️ inconclusive - 1 of 7 scenarios driven live against the product
Scenario Result Live Evidence
A real standalone GitHub pull request is classified as not stacked and stays on the normal merge path ✅ pass live live-github-stack-probe.txt: real PR #88 has no stack field, and github_stack_membership_class returns standalone
The lowest layer of a stack merges through the asynchronous API with the verified head and a merge commit, and the landing is reported once after the read-back ⏸️ untested no No live result: this ran only against a stand-in gh (test_stacked_lowest_layer_merges_through_async_api). A live run needs a disposable GitHub repository with a native stack and approval to merge ther…
Merging a higher layer before the lower layers have merged is refused ⏸️ untested no No live result: this ran only against a stand-in gh (test_stacked_refuses_until_it_is_the_lowest_unmerged_layer). A live run needs a disposable native stack on GitHub.
Existing guards still refuse on the stacked path: red, pending and unreported required checks, away posture, merge-queue base, protected flags even when attended, and methods other than merge ⏸️ untested no No live result: these ran only against a stand-in gh (test_stacked_regression_pins_keep_the_check_gates, test_stacked_refuses_while_away, test_stacked_refuses_a_merge_queue_base, test_stacked_refuses_…
A pending, failed, unreadable or contradicted asynchronous result never reports a landing ⏸️ untested no No live result: these ran only against a stand-in gh (test_stacked_submit_answers_never_report_a_landing, test_stacked_pending_or_unreadable_result_keeps_authority, test_stacked_failed_result_quotes_g…
When stack membership cannot be determined, the script refuses before recording anything ⏸️ untested no No live result: this ran only against a stand-in gh (test_stacked_membership_undetermined_refuses_before_recording). A live run would need GitHub to return an unexpected stack shape on demand.
A head the pipeline has not validated is refused; direct-PR tasks skip that rule; --allow-red still reaches the submit ⏸️ untested no No live result: these ran only against a stand-in gh and a stand-in no-mistakes status (test_stacked_refuses_a_head_the_pipeline_has_not_validated, test_stacked_direct_pr_merges_without_the_pipeline_r…
  • bash <temp runner>: tests/fm-pr-merge.test.sh limited to all 15 test_stacked_* cases plus the cases listed before them (69 ok, 0 failures)
  • gh api repos/andrewesweet/firstmate/pulls/88 then the script's own github_stack_membership_class on the real response (read-only)
  • gh api repos/andrewesweet/firstmate/stacks/1 (read-only check that the stacks endpoint exists)

🔧 Fix applied.
2 issues (1 warning, 1 info) still open:

  • ⚠️ bin/fm-pr-merge.sh:1550 - Live finding in scratch repo PR feat(bin): link routed-task traces to the routing agent and emit handoff spans #4: a descendant commit (725b384) was pushed to the layer after the script verified head f0cd64e and before the merge-async submit. GitHub answered 202 and merged exactly the bound head f0cd64e. The script then reported 'verified: ... is merged' (rc=0). The PR now shows head 725b384 and merged=true, but 725b384 is not on main. The binding worked as specified: nothing unverified landed. The difference is that the synchronous path's --match-head-commit refuses this race outright, while the stacked path reports a landing and closes the PR with a newer pushed commit left off main. Please decide whether the stacked path should compare the PR's head after merge with the bound head and report the disagreement.
  • ℹ️ Live observation: after each landing GitHub retargets the next layer to the stack base and restacks its head (for example a3115d5 became a12fbd0). If a higher layer was attempted earlier (recording pr_head), the existing fm-pr-check named-head guard (fm-dod-lib) refuses that layer until the worker copy is synced to the restacked remote head. This is existing behaviour, not part of this change, but stacked workflows will meet it after every landing.
  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
The lowest layer of a native stack merges through the asynchronous API with a merge commit bound to the verified head, and the landing is reported once after a live read-back ✅ pass live live-stack7-a-bottom-up-merges.txt: PRs #5 and #6 each go PUT merge-async (merge_method=merge, sha=<verified head>), then 202, then GET pending, then merged, then GraphQL read-back; one 'verified: ...…
Merging a higher layer before the lower layers have merged is refused and nothing is submitted ✅ pass live live-stack7-b-out-of-order.txt: PR #6 and PR #5 refused with 'pull request 4 in stack 7 has not merged'; no merge-async call; both stayed OPEN
A head that moves between verification and submit cannot land unverified content (sha mismatch) ✅ pass live live-stack7-c2-force-push-rejected.txt (non-descendant force-push: GitHub 400 'Pull request head branch was modified.', quoted, 'nothing was merged', no authority, PR stayed open); live-stack7-c-sha-m…
Methods other than merge and the protected forge flags are refused on a stacked PR before anything is recorded, even with --attended-override ✅ pass live live-stack7-guards.txt: --squash, --rebase, --method squash, --admin, --auto and --delete-branch each refused after only the PR read; pr= not recorded
A no-mistakes task whose pipeline has not validated the live head is refused before submit, while a direct-PR task skips the rule ✅ pass live live-stack7-guards.txt (mode=no-mistakes refused 'has not validated the live head', no PUT); direct-PR tasks s4, s5 and s6 merged in live-stack7-a-bottom-up-merges.txt
A pull request outside any stack still merges through the unchanged synchronous path ✅ pass live live-standalone-sync-path.txt: PR #8 (no stack key) merged via gh pr merge --match-head-commit --squash
Red, pending and unreported required checks, merge-queue base, away posture, 409, unreadable membership, and pending or unreadable poll results never report a landing ⏸️ untested no The earlier payload did not establish a live result for this scenario: it was covered only by fixture tests (15 test_stacked_* ok in stacked-fixture-tests.log). A live run would need branch protection…
  • gh api -X POST repos/andrewesweet/stacked-pr-lab/stacks with {&#34;pull_requests&#34;:[4,5,6]} (native stack #7) and pre-merge mergeable/mergeStateStatus reads
  • bin/fm-pr-merge.sh s6 https://github.com/andrewesweet/stacked-pr-lab/pull/6 and s5 .../pull/5 before the lower layers merged (live refusal)
  • bin/fm-pr-merge.sh s4 .../pull/4 -- --squash | -- --rebase | -- --method squash | --attended-override -- --admin | --auto | --delete-branch (live refusals)
  • bin/fm-pr-merge.sh s4 .../pull/4 with mode=no-mistakes and no pipeline run (live validated-head refusal)
  • bin/fm-pr-merge.sh s4 .../pull/4 with a real descendant push to layer 1 just before the merge-async PUT (bound head merged, racing commit not landed)
  • bin/fm-pr-merge.sh s5 .../pull/5 with a real non-descendant force-push to layer 2 just before the PUT (GitHub 400, quoted, nothing merged)
  • bin/fm-pr-merge.sh s5 .../pull/5 and s6 .../pull/6 bottom-up live merges via merge-async, then poll, then read-back
  • bin/fm-pr-merge.sh solo .../pull/8 standalone control on the synchronous path
  • test_stacked_* functions from tests/fm-pr-merge.test.sh (15 fixture-only scenarios, run in isolation)

🔧 Fix applied.
✅ Re-checked - no issues remain.

  • Live validation: ✅ go - 2 of 4 scenarios driven live against the product
Scenario Result Live Evidence
A commit pushed onto a stacked layer after verification is reported as a disagreement naming both heads, not as a landing ✅ pass live live-round3-descendant-race-refused.txt: GitHub merged bound head 906d412 (merge commit 64ce460); PR head reads 3451da2, which diverged from main; script exited 1 with the disagreement error, no 'is m…
The next layer, restacked by GitHub, merges through merge-async with the verified head and a merge commit, and the landing is reported exactly once ✅ pass live live-round3-next-layer-lands.txt: PUT merge-async merge_method=merge sha=f8eaa7e -> pending -> merged; read-back head f8eaa7e equals the bound head; one 'is merged' line, rc=0, pr-poll-merge-notified…
Regression: the newer-head stub case fails before the fix and passes after it ⏸️ untested no The prior payload established this only with a fixture/stub test (regression-newer-head-before-fix.log fails at 8ef2141, regression-newer-head-after-fix.log passes at 40c2247), not a live result. It…
Guards that need required checks, a merge queue, protected-branch rules or away posture still refuse on the stacked path ⏸️ untested no The prior payload established this only through fixture tests (stacked-fixture-tests-round3.log: 16 test_stacked_* ok), not a live result. Driving it live needs repository admin setup of required CI c…
  • Live, scratch repo andrewesweet/stacked-pr-lab: built native stack #11 (PR #9 at the bottom, PR #10 on top) via POST /repos/andrewesweet/stacked-pr-lab/stacks
  • Live: bin/fm-pr-merge.sh r1 https://github.com/andrewesweet/stacked-pr-lab/pull/9 with a gh wrapper that pushes a descendant commit to the layer branch just before the merge-async PUT
  • Live: bin/fm-pr-merge.sh r2 https://github.com/andrewesweet/stacked-pr-lab/pull/10 after GitHub restacked the layer onto main (no race)
  • Checked live state afterwards via gh api repos/.../pulls/N, commits/&lt;merge sha&gt;, compare/main...&lt;newer&gt;, stacks/11, plus the lab FM_HOME state files
  • Fixture: the 16 test_stacked_* cases from tests/fm-pr-merge.test.sh, run on their own
  • Regression check: test_stacked_merged_with_a_newer_pushed_head_reports_disagreement run against the script from 8ef21411 (fails) and from 40c22470 (passes)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Arma CTI tier runtime added 6 commits October 1, 2026 03:06
A pull request that GitHub's own record shows inside a stack merges one
layer at a time, lowest unmerged first, through GitHub's asynchronous
merge API instead of gh pr merge, because GitHub accepts stacked merges
only there and rewrites stacked heads on its own server.

Detection reads the pull request's REST resource before anything is
recorded: a stack object with an integer number, an integer position
and a non-empty base.ref selects the stacked path, a missing or null
stack runs the synchronous path unchanged, and an unreadable record or
unrecognisable shape refuses instead of guessing.

The stacked request is one merge commit bound to the verified head with
merge_method, merge_action and sha; every existing live gate still runs
on the stacked path, the stack's own record must show every lower layer
merged and this layer retargeted onto the stack base, a merge-queue
base or unreadable branch rules refuse, forge flags from --auto to
--delete-branch refuse even with --attended-override, and the
away-posture record refuses with exit 2 at both authority reads.

For a no-mistakes task the pipeline must have validated the live head
with its ci step running before the request is bound, while a direct-PR
task skips that rule; a 202 pending answer persists the merge authority
under the task's lock and polls the named result, a failed result
quotes GitHub's own report and retires the authority, and a landing is
reported only after a live read-back agrees, while every unreadable or
still-pending result keeps the authority and the armed merge poll to
report the landing later.

tests/fm-pr-merge.test.sh extends the gh stub with the REST pull read,
the stack read, the submit and the poll, and adds fifteen stacked cases
covering detection, bottom-up order, refusal paths, the request
outcome, and regression pins that keep the red, pending and
unreported-required check gates on the stacked path;
docs/architecture.md names the stacked path beside the synchronous one.

Verification: tests/fm-pr-merge.test.sh passes 124 of 124 cases
including the fifteen new stacked cases; bin/fm-lint.sh clean;
shellcheck -x clean on bin/fm-pr-merge.sh; bin/fm-jev-lint.sh check
clean.
…ge.sh, `github_stack_membership_class` required a non-empty `.base.ref` before it checked for a stack. A PR whose record had no stack and no `base` object was therefore classed "undeterminable", and the merge was refused. Real GitHub always returns `base.ref`, but the gh stubs in other test suites leave it out, so fm-pr-merge refused the merge in those suites. Serial shard 5 failed in tests/fm-pr-check-security.test.sh (test merge-outcome-committed) with "stack membership could not be determined ... the stack field is not a shape this script recognises". The truncated log for parallel shard 2 doesn't name its failing test; it is most likely fm-captain-hold-lifecycle, which also calls fm-pr-merge through a stub, but I haven't confirmed that. **Invariant:** a pull request whose `stack` is absent or null is classed standalone, whatever its other fields contain. The membership class is the only place where this decision is made. **Fix:** I moved the `base`/`base.ref` checks below the standalone test, so only PRs that have a stack object must have a base. Stacked shapes that are missing a base still refuse as undeterminable; tests/fm-pr-merge.test.sh covers this case. I made no test changes. **Verification:** - tests/fm-pr-check-security.test.sh passes locally (rc=0); it failed with the error above before the fix. - tests/fm-pr-merge.test.sh passes locally (rc=0). - fm-captain-hold-lifecycle, fm-branch-supervision and fm-afk-contract were still running when this result was required, so they are unverified
@andrewesweet
andrewesweet merged commit 7472867 into main Oct 1, 2026
35 of 37 checks passed
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.

1 participant