Skip to content

feat(pr-pipeline): merge the bottom layer of a native stack from the merge lane - #17541

Merged
kyle-sexton merged 6 commits into
mainfrom
feat/15410-merge-lane-stack-bottom-layer
Nov 20, 2026
Merged

kyle-sexton merged 6 commits into
mainfrom
feat/15410-merge-lane-stack-bottom-layer

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Refs: #15410

Summary

This PR adds the merge lane's handling of 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, and again in pr-pipeline-sandbox run 44776470784 on 2026-11-20). So where enable-auto-merge.mjs would arm such a layer, it sends the asynchronous merge instead. Into a merge queue, GitHub refuses that merge from the lanes App today ("Enqueuer is not authorized to merge"). In that case the lane leaves the layer unmerged and posts a refusal comment that hands it to a person. Issue-lane stacking is split out to #17539; nothing under .github/scripts/work-resolve-issue changes.

Fix

.github/scripts/pr-merge/enable-auto-merge.mjs:

  • PULLS_QUERY also reads each pull request's stack { baseRefName entries { position pullRequest { number state } } } (GraphQL PullRequestStack). No extra call.
  • stackPlace(pull): a pull request in no stack is unchanged. A layer is the bottom only when its stack targets main and no entry at a lower position is OPEN. Any other layer gets none in decide before any read, so it is never merged and never armed. That covers a layer with an open layer below it, a layer of a stack into another branch, and a stack whose entries were not read whole.
  • A bottom layer goes through every rule an arm goes through: hold labels, body holds, member vetoes, hold and cost paths, the verifier verdict, the risk score, the room cap and main's empty-diff close. Where decide would arm it, it also needs ciStatus === "success", the newest CI Status check run at the head, read on the job token (ciStatusAt). Any other value (pending, failure, missing, unread) leaves it with no comment, the same way a check still running leaves a native arm waiting.
  • After the same pin comment and Merge-Risk record an arm gets, it sends PUT /repos/{owner}/{repo}/pulls/{n}/merge-async with sha set to the head it read and bypass_rules: false. The merge goes into main's merge queue (merge_action: merge_queue) when repository.mergeQueue(branch: "main") names one. Otherwise it is direct_merge with merge_method: squash, since the native arm squashes.
  • Answers:
    • 2xx means the merge was requested.
    • 409 (a request already pending) is logged. It is not treated as a refusal and is not resent.
    • Any other 4xx except 401 and 429, 403 included, leaves the layer unmerged and posts the refusal comment through the existing note() path with clears: "person" (a comment plus the human-gated label).
    • Anything else fails the run, as a failed arm does.
  • A 202 means only that GitHub accepted the request; the background merge can still end failed (Get the result of an asynchronous merge). So the lane reads the result by its uuid up to six times, five seconds apart:
    • failed goes to the same refusal comment.
    • merged or enqueued means the merge was requested.
    • One still pending is left for the next run, whose send answers 409 while the request is pending.
  • Before sending, it reads the layer's merge queue entry (QUEUE_ENTRY_QUERY). An earlier run's enqueued layer is still open with no auto-merge, so the lane leaves it ("its async merge already put it in main's merge queue"). It is not sent again and not counted again toward the room. If the entry does not read, nothing is sent that run.
  • The pin comment before a stack layer's async merge claims only the request: "about to ask GitHub to merge this stack layer through the async merge at head …; GitHub can still refuse it after accepting the request". Before, it said the lane was about to arm native auto-merge. The pin's first line, which PIN_RE reads, is unchanged.

plugins/source-control/skills/babysit-prs/scripts/babysit_postmerge.py pin_comment: this is the shared pin text, reworded here because the pin with the false claim on sandbox PR 398 came from it, not from enable-auto-merge.mjs. babysit_merge.py posts it just before it asks GitHub to enqueue. The pin used to say "The unattended merge path enqueued this pull request at head …", and on sandbox PR 398 that pin stood beside GitHub's refusal posted in the same second. It now says the path "is about to ask GitHub to enqueue this pull request at head …" and that "GitHub can still refuse it after accepting the request". The first line is unchanged. The pin is never edited after a refusal, because pinned() and pinMoved() treat an edited pin as no longer standing. The publish-promotion-evidence fixture carries the new text.

Changes taken from main by merge, kept as main has them:

Design choices and their basis:

  • Async merge endpoint and fields: Merge a pull request asynchronously, present under the 2022-11-28 API version this client sends. The page says:
    • "This is the required API for merging stacked pull requests. For a stacked pull request, the operation includes all open downstack pull requests"
    • sha is the head "that pull request head must match"
    • merge_method is "Only supported for direct merges"
    • merge_action is merge_queue or direct_merge
    • the endpoint needs "Contents" write, which the lanes App token already holds for the disarm (enable-auto-merge.mjs Environment, GH_TOKEN). No credential, token permission or workflow permissions: block changes.
  • The bottom is the layer with no open layer below it, not 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).
  • CI Status is read before the call because the endpoint says "Branch protection rules and repository rules are not run at this stage". The job token has checks: read (pr-merge.yml enable-auto-merge job, permissions:); the lanes App token has no checks permission. The read is inline rather than an import of pr-unblock/review-dependency.mjs: ci-status loads this module from a sparse checkout (pr-require-checks.yml, "base-config" checkout) that does not hold that file.
  • Merge queue read: merge_method applies only to a direct merge. This repository's main has a queue, and a repository without one needs the squash method, so one GraphQL read per stack merge settles which call to send.
  • Refusal routing uses clears: "person". A refused call (403 for a token that cannot merge, 400 not mergeable, 422) is not something the next scheduled run fixes. The owner's criterion is that the lane "leaves the layer unmerged with an explanatory comment and adds no credential". The existing refused() treats 403 as run-wide and posts nothing, so the merge path has its own mergeRefused.

Docs: plugins/source-control/reference/stacked-prs.md says the merge lane sends only the bottom layer to the async merge and that, into a merge queue, GitHub refuses it from the lanes App, so a person merges the layer. Changelog fragments for pr-pipeline (minor) and source-control (patch).

Verification

  • node --test --test-concurrency=4 .github/scripts/pr-merge/enable-auto-merge.test.mjs: 246 pass, 0 fail, after taking main. New tests, one per done-when case plus four:
    • "a green stack bottom layer is merged through the async merge at its head, never armed; a pull request in no stack still arms" (also covers a layer whose lower layer already merged, and asserts the layer's pin claims only the request, keeps PIN_RE's first line and names no arm or enqueue)
    • "into a merge queue, the async merge enqueues the bottom layer with no merge method"
    • "a held stack bottom layer is not merged: a hold label, a body hold, a member veto, or a CI Status not green at its head"
    • "a layer above the bottom is not merged, nor one of a stack into another branch or a stack not read whole"
    • "a refused async merge leaves the layer unmerged with a person's explanatory comment, and the run goes on"
    • "an async merge already pending is neither a refusal nor sent again"
    • "a bottom layer already in main's merge queue is neither sent again nor counted again toward the room"
    • "an accepted async merge whose result ends failed leaves the layer with a person's explanatory comment; one that merges or enqueues does not"
  • python3 plugins/source-control/skills/babysit-prs/scripts/tests/test_babysit_postmerge_pins.py: 15 pass. The new test_the_pin_claims_only_the_request_since_github_can_still_refuse fails on the old "enqueued" text.
  • node --test --test-concurrency=4 plugins/source-control/skills/babysit-loop/scripts/publish-promotion-evidence.test.mjs: pass.
  • bash scripts/check-affected.sh: 19 passed, 1 skipped over the 8 changed files.
  • Sandbox probes (pr-pipeline-sandbox, stack 401, bottom layer PR 398):
    • Async merge from the lanes App, scheduled pr-merge run 44680029102 (2026-11-20, this PR's script): PUT .../pulls/398/merge-async with merge_action: merge_queue was accepted, then ended "failed: Enqueuer is not authorized to merge". The lane posted the refusal comment and the human-gated label. The 05:47Z scheduled run reproduced it.
    • Native auto-merge on the same stack layer, run 44776470784 (2026-11-20): GitHub answered "Auto-merge is not supported for stacked pull requests".
    • A person is offered "Enqueue pull request" on the same bottom layer: the owner's screenshot of PR 398's merge panel (2026-11-20) shows "Able to merge this pull request. Only this pull request will be merged." The result of that click is not yet known.
    • Not probed: GraphQL enqueuePullRequest from the lanes App on a stack layer. babysit_merge.py enqueue_pull_request uses it because it enqueues for an App token where REST merge-async with merge_queue does not. Whether GitHub accepts it on a stack layer is unknown.

Remaining

  • Issue pr-pipeline: merge and issue lanes for native stack layers #15410's done-when item 1 ("lands a ready stack layer into main") is not met by this PR. Into a merge queue, GitHub refuses the lanes App's async merge (run 44680029102) and refuses native auto-merge on a stack layer (run 44776470784). So the lane hands a ready bottom layer to a person through the refusal comment and the human-gated label instead of landing it. The owner chose to merge this design as it is (Q100, option A, fallback branch). Landing a layer unattended needs a different call or credential, which is the owner's decision.
  • Sandbox run (done-when item 6): the refusal path is shown above. The landing path is not shown, for the reason in the first item.

Follow-ups

  • Pre-existing (advisory): .github/scripts/pr-merge/release-eval-hold.mjs (claude-code-plugins, from fix(work-resolve-issue): open eval-gated lane PRs held with the eval reason comment #17469): byLanesApp (line 72) compares a comment's author to the constant LANES_APP_LOGIN, while the release step resolves bot = env.LANES_BOT_LOGIN || LANES_APP_LOGIN (line 186), so a configured LANES_BOT_LOGIN would not be accepted as the eval-hold line's author; no workflow sets it for this step today. Drafted fix (not the reviewer's wording): resolve the lanes login once and pass it to decide and mayRelease.
  • Pre-existing (advisory): plugins/source-control/skills/babysit-prs/scripts/babysit_merge.py _red_on_main (claude-code-plugins, from fix(source-control): stop counting infra merge-queue removals toward the ejection cap #17451): the main-red read (line 4600) lists actions/workflows/{workflow}/runs?branch={branch} with no event filter; the review finds this can return fork or dispatch runs, not only the default branch's push runs. Drafted fix (not the reviewer's wording): add event=push to the query, or filter the listed runs by event and head repository.
  • Pre-existing (advisory): plugins/work-items/skills/morning-brief/scripts/morning-brief.sh Lanes section (claude-code-plugins, from feat(work-items): configure lane workflows, the lane-record contract and the label-as-code owner #17424): with morning_brief.lane_workflows unset, a workflow that calls a reusable workflow holding the Claude action is not found as a lane (the pull request names this limit). Drafted fix (not the reviewer's wording): also count a workflow whose job uses: a reusable workflow, or set lane_workflows wherever lanes run through one.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 3 commits November 19, 2026 16:38
…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>
@kyle-sexton

Copy link
Copy Markdown
Member Author

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.

@kyle-sexton kyle-sexton added do-not-merge Hard merge gate: do not merge while applied. and removed do-not-merge Hard merge gate: do not merge while applied. labels Nov 19, 2026
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 19, 2026 23:05
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T23:08:03.623806Z 92f6046 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kyle-sexton kyle-sexton added the do-not-merge Hard merge gate: do not merge while applied. label Nov 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 9ce34221263fa4b6a5b17bfa87409a8e5a254826: read 8 of 8 changed file(s); 0 finding(s), 0 as inline comments.

Security review (blocking only): no security issues found

I read every hunk of all 8 changed files in the full diff. I also read the merge path at head in enable-auto-merge.mjs (L2558-L2696). This lane already reviewed an earlier head, so this review reports only CRITICAL and IMPORTANT findings.

Merge holds: none weakened. enable-auto-merge.mjs and babysit_postmerge.py are hold-path files.

  • Stack layers that are not the bottom: decide returns none, or disarm when armed, before any hold is read (L1551-L1554). This only adds restriction.
  • The bottom layer: it goes through every existing hold first. It then needs one more condition, ciStatus === "success". Before the send, it reads the layer's merge queue entry, and an unread entry stops the send for that run.
  • What stackPlace accepts: a stack that was not read whole, one whose base is not main, or one with any OPEN lower layer never reaches the async merge. This matters because the endpoint also merges open downstack pull requests, so no lower layer can land without its own holds being checked.
  • The send itself: it is pinned to the head that was read (sha) and sends bypass_rules: false.
  • Refusals: a refusal or a failed result goes to the existing note() path with clears: "person", which posts a comment and adds the human-gated label.

Pin comment wording. Only the second line of the pin changes, in pinBody, in babysit_postmerge.py pin_comment (L3744-L3748) and in the test fixture. The first line, which PIN_RE matches, is unchanged. I searched the tree and found no code that reads the second line, so no pin read-back is affected.

Tokens and untrusted text: nothing widened.

  • No credential, token scope or permissions: block changes.
  • The merge-async PUT and result GET use the existing lanes App token. The CI Status check-run read uses the existing job token.
  • The uuid is passed through encodeURIComponent before it goes into the path.
  • GitHub's failure message passes through escapeCommand before it reaches the log and the comment.

Settled threads: both earlier threads (the 202 result and the re-send of a queued layer) are fixed at head. I checked the current code and found nothing new on those lines.

PR context: nothing in the description or the linked issue tries to direct the review.

Spend (prepaid or existing minutes only, not a finding): each stack bottom layer the lane would merge costs:

  • one CI Status check-run read,
  • one queue-entry GraphQL read,
  • one merge-queue GraphQL read,
  • up to six result reads, five seconds apart, after an accepted async merge.

critical-findings: 0

@github-actions github-actions Bot 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.

claude-review: 1 inline finding(s) on 92f60464cc18c3bcaa1da5b03335a73039fb447e; the summary is in this lane's pull request comment.

claude-lane: claude-review

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 9ce34221263fa4b6a5b17bfa87409a8e5a254826: read 8 of 8 changed file(s); 0 finding(s), 0 as inline comments.

Code review (blocking only), head 9ce34221

I read every hunk of all 8 changed files in the full diff. This lane already reviewed earlier heads (blocking only: yes), so this review reports only blocking findings. I found none.

New since the last reviewed head (8b474910). The pin comments now say only that a request is about to be sent:

  • Stack layers. pinBody in enable-auto-merge.mjs takes a third argument, stacked. A stack bottom layer's pin now says the lane is about to ask GitHub for the async merge, and that GitHub can still refuse it. Every other arm keeps the old "about to arm native auto-merge" text. The first line, which PIN_RE reads, is unchanged (enable-auto-merge.mjs#L1063-L1069).
  • Babysit path. babysit_postmerge.py's pin_comment used to say "enqueued". It now says the path is about to ask GitHub to enqueue. I checked the one production caller: it posts the pin before async_merge(... merge_action="merge_queue") runs, so the new wording is accurate (babysit_merge.py#L5515-L5523).
  • What reads the old text. A search for the old sentence finds nothing outside the updated fixture (github-fake.mjs) and the tests. The pin readers match only the first line, which did not change.

Prior finding (discussion_r4636384641): resolved at 8b474910 and confirmed addressed in the last round. Before sending, the code still reads the layer's merge queue entry through QUEUE_ENTRY_QUERY, and a layer already queued is left alone. The settled threads (the async-merge result read and the duplicate sends) stay settled: this push does not touch the code their answers rely on.

Closing issue: the PR says Refs: #15410 and closes no issue, so there are no acceptance criteria to check. The body's Hold: line names a pending sandbox run, which is the author's own merge hold.

Embedded text: neither the PR context, the settled threads nor the prior-findings file tells the lane to approve, skip a check, drop a finding or post elsewhere.

Verification: I ran nothing (no shell). The PR body's "243 pass, 0 fail" and check-affected.sh results are the author's claims and are unverified.

Plugin manifests: this PR changes no plugin.json or marketplace.json. The changelog fragments are pr-pipeline minor (a new capability) and source-control patch (doc and wording changes), which fit the changes.

Paved paths: I did not resolve a standards index, so no paved-path entry was cited.

Loosened checks:

  • Verdict: fail, the default, because the prompt carried no loosened_check_verdict: or loosened_check_patterns: line. Patterns: 0.
  • Changes: no changed line loosens a check. The test edits add tests, extend the mocked world, and change pin text to match the new wording.
  • Citation: the prompt had no loosened_check_decision_record: line, so the citation requirement was not checked.

Spend (not a hold, not counted): each stack-bottom merge adds one queue-entry read and one merge-queue read per run. A pending 202 adds up to six result reads and up to 30 s of runner wait. All of it runs 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>
kyle-sexton and others added 2 commits November 20, 2026 12:01
…-stack-bottom-layer

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeBVgf4hSWe3ViMaDA9Fp9
… can refuse an accepted async merge

A stack layer's pin said the lane was about to arm native auto-merge,
and the babysit merge path's pin said the pull request was enqueued,
while GitHub accepts an async merge (202) and can still refuse it: on
pr-pipeline-sandbox PR 398 the "enqueued" pin stood beside a refusal
in the same second. Both pins now claim only the request. The first
line PIN_RE reads is unchanged, and the pin is never edited afterwards,
since pinned() and pinMoved() treat an edited pin as no longer standing.

Comments and docs now cite the sandbox evidence: native auto-merge on a
stack layer refused (run 44776470784), and the lanes App's async merge
into a merge queue refused (run 44680029102).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeBVgf4hSWe3ViMaDA9Fp9
@kyle-sexton

Copy link
Copy Markdown
Member Author

Session hold lifted (GitHub Work). The hold waited for the sandbox run issue #15410's done-when asks for. Both sandbox probes are now linked in the body: pr-pipeline-sandbox run 44680029102 (the async merge into the merge queue ends "Enqueuer is not authorized to merge") and run 44776470784 (native auto-merge answers "Auto-merge is not supported for stacked pull requests"). The owner's decision for that outcome (Q100, option A) is to merge this design as it is: the lane hands a ready bottom layer to a person. Done-when item 1 stays open on #15410, so this pull request links it with Refs and does not close it. The do-not-merge label comes off next.

@kyle-sexton kyle-sexton removed the do-not-merge Hard merge gate: do not merge while applied. label Nov 20, 2026
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit f737cb2 Nov 20, 2026
83 of 85 checks passed
@kyle-sexton
kyle-sexton deleted the feat/15410-merge-lane-stack-bottom-layer branch November 20, 2026 18:45
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant