Repository navigation
feat(pr-pipeline): merge the bottom layer of a native stack from the merge lane - #17541
kyle-sexton wants to merge 4 commits into
Conversation
…merge lane GitHub refuses native auto-merge for every stack member, so the merge lane could never land a stack layer. enable-auto-merge.mjs now reads each listed pull request's stack. A layer of a stack into main with no open layer below it is judged by every rule an arm checks; where it would arm, the lane sends the async merge instead, pinned to the head it read, into main's merge queue when there is one, and only once the newest CI Status run at that head passed. Any other layer is left. A merge GitHub refuses leaves the layer unmerged with a person's refusal comment; no credential is added. Refs: #15410 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…merge lane line Refs: #15410 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Refs: #15410 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Session hold (GitHub Work): this pull request waits for the sandbox run that issue #15410's done-when asks for; the label comes off when that run is linked in the body. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 92f60464cc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await github("PUT", `/repos/${repo[0]}/pulls/${pull.number}/merge-async`, mergeAsyncBody(pull.headRefOid, queue.mergeQueue != null)); | ||
| leave(pull, "merge requested"); | ||
| console.log(`enable-auto-merge: #${pull.number} stack bottom layer: async merge requested at ${pull.headRefOid}`); | ||
| statuses.push({ sha: pull.headRefOid, state: "success", description: "async merge requested for its stack's bottom layer" }); |
There was a problem hiding this comment.
Read the asynchronous merge result before discarding its UUID
When GitHub accepts the request with HTTP 202 but subsequently rejects the merge during background processing, this path discards the UUID and never observes the failure. The async merge documentation specifies a final failed result containing the failure message; acceptance itself does not establish that the merge can proceed. Consequently, such a layer receives neither the explanatory refusal comment nor the human-gated label implemented below, and later sweeps can keep submitting the same unsuccessful request. Retain and check the asynchronous result, routing a final rejection through the refusal handling.
Useful? React with 👍 / 👎.
|
claude-security-review reviewed Security review (incremental, blocking only): no security issues foundScope: the push since Merge holds: none weakened
Tokens and untrusted text: nothing widened
Spend: up to six extra REST reads, five seconds apart, per async merge of a stack bottom layer, plus one GraphQL queue-entry read per bottom layer the lane would arm. These use existing tokens and Actions minutes. PR context: nothing in the description or linked issue tries to direct the review. critical-findings: 0 |
| if (action === "arm" && stackPlace(pull) === STACK_BOTTOM) { | ||
| leave(pull, "refused: its async merge failed"); | ||
| let queue; | ||
| try { | ||
| queue = (await github("POST", "/graphql", { query: MERGE_QUEUE_QUERY, variables: { owner: repo[1], name: repo[2] } }))?.data?.repository; | ||
| } catch (error) { | ||
| console.log(`enable-auto-merge: #${pull.number} main's merge queue did not read: ${describe(error)}`); | ||
| } | ||
| if (queue == null) { | ||
| failed += 1; | ||
| console.log(`::error title=enable-auto-merge::#${pull.number} async merge not sent: main's merge queue did not read`); | ||
| continue; | ||
| } | ||
| try { | ||
| await github("PUT", `/repos/${repo[0]}/pulls/${pull.number}/merge-async`, mergeAsyncBody(pull.headRefOid, queue.mergeQueue != null)); | ||
| leave(pull, "merge requested"); | ||
| console.log(`enable-auto-merge: #${pull.number} stack bottom layer: async merge requested at ${pull.headRefOid}`); | ||
| statuses.push({ sha: pull.headRefOid, state: "success", description: "async merge requested for its stack's bottom layer" }); | ||
| } catch (error) { | ||
| if (error instanceof GitHubError && error.status === 409) { | ||
| leave(pull, "merge requested"); | ||
| console.log(`enable-auto-merge: #${pull.number} stack bottom layer: an async merge is already pending`); | ||
| } else if (mergeRefused(error, answer?.limited)) { | ||
| inFlight -= 1; |
There was a problem hiding this comment.
The merge is re-sent every run, and a duplicate that comes back as anything but 409 dequeues a healthy queued merge.
After merge-async with merge_action: "merge_queue" succeeds, the layer is still OPEN with autoMergeRequest == null. Nothing in the listing or in decide reads whether it is already queued (DETAIL_QUERY and PULLS_QUERY read no mergeQueueEntry). So on the next scheduled run, while the layer waits in the queue:
decidereturnsarmagain, and line 2535 adds it toinFlighta second time.lane.countlikely already counts the queue entry, so the double count can hold back other pull requests at the room cap.- The evidence comment and the Merge-Risk record run again.
PUT .../merge-asyncis sent again.
The only safeguard is the 409 branch at 2629, which assumes GitHub answers 409 for "already pending". That assumption is unverified: only a mocked 409 tests it, and on GitHub's sync merge endpoint 409 means the head SHA did not match. If the real answer is a 405 or 422, mergeRefused posts a person's refusal and adds the human-gated label, and note's leaveQueue then dequeues the layer. A healthy queued merge gets pulled and parked for a person.
The same applies when withRetry resends the PUT after a lost answer and the first send landed. The arm path reads the state back in sendSettled for exactly this case. This path does not, and the inFlight -= 1 at 2633 also ignores error.attempts, unlike line 2673.
How it fails: a merge-queue repository, a green bottom layer, and two scheduled runs before the queue lands it. With the second PUT answered 422, the test world records a refusal comment, the needs-human label and a dequeue.
Fix: before sending, read the layer's queue entry (QUEUE_ENTRY_QUERY, already imported) and treat a queued layer as in flight: none, already queued, no extra inFlight. On an error after a resend, read the state back before routing it to mergeRefused, as sendSettled does.
claude-lane: claude-review
|
claude-review reviewed Code review (incremental, blocking only): 92f6046 → 8b47491I read the whole incremental change in both listed files: Prior finding (discussion_r4636384641): addressed.
New in this push: after a pending 202, the lane polls the async-merge result: up to 6 reads, 5 s apart, by
The tests cover failed, merged, enqueued, and still pending after six reads. I found no blocking defect. Closing issue: the PR says Embedded text: neither the PR context nor the prior-findings file tells the lane to approve, skip, or post elsewhere. Verification: I ran nothing (no shell). The PR body's "243 pass, 0 fail" and Plugin manifests: no Paved paths: I did not resolve a standards index; no paved-path entry was cited. Loosened-check verdict: fail (default; the prompt carried no Spend (not a hold, not counted): each stack-bottom merge now adds one GraphQL queue-entry read per run, plus up to six result reads and 30 s of runner wait after a pending 202, on existing tokens and Actions minutes. No verifier subagent ran this round. Verifier dropped 0 of 0 candidates. |
… layer A 202 from merge-async is only accepted: the merge runs in the background and can end failed. The lane now reads the result up to six times, five seconds apart, and routes a failed one to the person's refusal comment. A bottom layer an earlier run put in main's merge queue is still open with no auto-merge, so every run re-sent it and counted it again toward the room. The lane now reads its merge queue entry first and leaves a queued layer alone. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Refs: #15410
Hold: waits for the sandbox run issue #15410's done-when asks for
Summary
The merge lane can now land the bottom layer of a native GitHub stack whose stack base is
main, as the owner decided on #15410 (option B, 2026-11-17). GitHub refuses native auto-merge for every stack member ("Auto-merge is not supported for stacked pull requests", sandbox #327 in #15400), so whereenable-auto-merge.mjswould arm such a layer it now sends the asynchronous merge instead. Issue-lane stacking is split out to #17539; nothing under.github/scripts/work-resolve-issuechanges.Fix
.github/scripts/pr-merge/enable-auto-merge.mjs:PULLS_QUERYalso reads each pull request'sstack { baseRefName entries { position pullRequest { number state } } }(GraphQLPullRequestStack). No extra call.stackPlace(pull): a pull request in no stack is unchanged. A layer is the bottom only when its stack targetsmainand no entry at a lower position isOPEN. Any other layer (an open layer below it, a stack into another branch, entries not read whole) getsnoneindecidebefore any read, so it is never merged and never armed.decidewould arm it, it also needsciStatus === "success": the newestCI Statuscheck run at the head, read on the job token (ciStatusAt). Anything else (pending, failure, missing, unread) leaves it with no comment, as a check still running leaves a native arm waiting.PUT /repos/{owner}/{repo}/pulls/{n}/merge-asyncwithsha= the head read andbypass_rules: false. Into main's merge queue (merge_action: merge_queue) whenrepository.mergeQueue(branch: "main")names one, elsedirect_mergewithmerge_method: squash, as the native arm squashes.note()path withclears: "person"(comment plus the human-gated label). Anything else fails the run as a failed arm does.failed(Get the result of an asynchronous merge), so the lane reads the result by itsuuidup to six times, five seconds apart;failedgoes to the same refusal comment,mergedorenqueuedis requested, and one still pending is left for the next run (whose send answers 409 while it is pending).QUEUE_ENTRY_QUERY): a layer an earlier run enqueued is still open with no auto-merge, so it is left ("its async merge already put it in main's merge queue"), neither sent again nor counted again toward the room. An unread entry sends nothing that run.Design choices and their basis:
2022-11-28API version this client sends): "This is the required API for merging stacked pull requests. For a stacked pull request, the operation includes all open downstack pull requests";sha"that pull request head must match";merge_method"Only supported for direct merges";merge_actionmerge_queue/direct_merge; "Contents" write, which the lanes App token already holds for the disarm (enable-auto-merge.mjsEnvironment,GH_TOKEN). No credential, token permission or workflowpermissions:block changes.position === 1: the endpoint takes every open downstack pull request with it, so this is the condition under which the lane lands this one layer alone; it holds whether or not GitHub renumbers positions after a lower layer merges (unverified).checks: read(pr-merge.ymlenable-auto-merge job,permissions:); the lanes App token has no checks permission. The read is inline, not an import ofpr-unblock/review-dependency.mjs, because ci-status loads this module from a sparse checkout (pr-require-checks.yml, "base-config" checkout) that does not hold that file.merge_methodapplies only to a direct merge, and this repository's main has a queue while a repository without one needs the squash method; one GraphQL read per stack merge settles it.clears: "person": a refused call (403 a token that cannot merge, 400 not mergeable, 422) is not something the next scheduled run fixes, and the owner's criterion is "leaves the layer unmerged with an explanatory comment and adds no credential". The existingrefused()treats 403 as run-wide and posts nothing, so the merge path has its ownmergeRefused.Docs:
plugins/source-control/reference/stacked-prs.mdsays the merge lane lands only the bottom layer; changelog fragments forpr-pipeline(minor) andsource-control(patch).Verification
node --test --test-concurrency=4 .github/scripts/pr-merge/enable-auto-merge.test.mjs: 243 pass, 0 fail. New tests, one per done-when case plus four:bash scripts/check-affected.sh: 17 passed, 3 skipped over the changed files.Remaining
pr-merge.ymlruns.base/.github/scripts/pr-merge/enable-auto-merge.mjsfrom its own main, so this branch's script reaches it only through a sandbox resync after this merges (or a sandbox PR copying it onto the sandbox's main). The run also needs a two-layer stack whose layers the lanes App authored (decideacts only on lanes App pull requests), which a session without the lanes App token cannot open. Once both hold: a scheduled or hand-started sandboxpr-merge.ymlrun should show the bottom layer merged throughmerge-asyncand the upper layer left with "it is a layer above the bottom of its stack". pr-pipeline: merge and issue lanes for native stack layers #15410 stays open until that run is linked.Related
main(sandbox stack 329, fix(source-control): review-trigger head-staleness hardening (BLOCKED-behind guard, stale-head reactions) #327 and feat: make missing hook prerequisites skip visibly (10 plugins) #328).plugins/source-control/reference/stacked-prs.md.🤖 Generated with Claude Code