Skip to content

fix(pr-pipeline): hold a native stack layer before the unattended pin and enqueue - #17685

Merged
kyle-sexton merged 1 commit into
mainfrom
fix/15410-gate-skip-stack-layer-enqueue
Nov 20, 2026
Merged

kyle-sexton merged 1 commit into
mainfrom
fix/15410-gate-skip-stack-layer-enqueue

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #15410

Summary

On a merge-queue base, the unattended merge gate (babysit_merge.py --unattended --merge, the unattended_enqueue path) posted its pin comment and called GraphQL enqueuePullRequest on a native stack layer on every sweep. GitHub refuses that call every time: "This pull request is part of a stack and must be enqueued using the asynchronous merge REST API." (sandbox run 44776470784, job Merge, group PR #398 at 7c2f3ca8…: exit 10; #15410 comment). The cause: the gate reads stack membership only under --stacked-prs, which the pr-merge lane does not pass.

Fix

plugins/source-control/skills/babysit-prs/scripts/babysit_merge.py unattended_enqueue: right after the "already queued or merged" hold, the gate checks whether the PR is a native stack layer. If it is, it holds with unattended merge refused: native-stack-layer: …. It posts no pin comment and calls no enqueuePullRequest.

  • No extra call. The check reads stack from inputs["pr"], the REST pull record the policy already read (babysit_merge_policy.pull_request, GET repos/{o}/{r}/pulls/{n}). That is the field pull_request_stack reads from the same endpoint. When stack is null (no stack), the PR enqueues as before.
  • No second comment or label. After feat(pr-pipeline): merge the bottom layer of a native stack from the merge lane #17541, enable-auto-merge.mjs in the same pr-merge run already hands a ready bottom layer to a person: its refusal comment plus the human-gated label. A layer above the bottom gets none, with no comment, from that script. The gate's hold posts nothing, so the two paths cannot post twice, and no new person request is added.
  • The check sits after the queue read. A layer a person has already enqueued therefore still reads as "already queued or merged", and nothing changes for it.
  • Docs: plugins/source-control/reference/stacked-prs.md now says the unattended merge path never pins or enqueues a stack layer. The module docstring says the same.
  • Changelog fragment: source-control patch.

API calls saved per sweep per stack layer

Counted from the code path skipped after the new check (unattended_enqueue):

Call Kind Saved
Pin comment POST issues/{n}/comments write 1
GET pulls/{n} for the node id (enqueue_pull_request) read 1
GraphQL enqueuePullRequest (refused) write 1
pr-merge lane closing-issue recheck (recheck_lane_issue) read at least 1
Base rules re-read (branch_rules(..., shared=False) per shared base) read at least 1
Default-branch and head-config re-reads read only when the run cache holds them

So each stack layer saves at least 5 calls per sweep (2 writes, at least 3 reads). That happens twice an hour on the :11/:41 sweeps. The merge-base check reads the local clone and makes no API call.

#15410 done-when item 1, as the owner revised it (Q112 A)

The item reads: the merge lane holds a ready stack layer for a person, with every lower layer's holds checked. It makes no enqueue or auto-merge attempt the lanes App cannot complete. It posts the refusal comment and needs-human. A person's enqueue lands the layer.

Part of the item Where it is met
Holds a ready stack layer for a person enable-auto-merge.mjs (#17541) on the bottom layer. Upper layers get none. The gate now holds every stack layer (native-stack-layer), so the gate's half is this PR.
Every lower layer's holds checked #17541: only a layer with no open layer below it is ever sent. Every hold, veto, verifier, risk and room rule applies to it, as for an arm. Any layer above it is held.
No enqueue or auto-merge attempt the lanes App cannot complete #17541 sends no native arm for a stack member. This PR stops the gate's GraphQL enqueuePullRequest, refused in run 44776470784, and the pin comment that preceded it. Tests: test_a_native_stack_layer_gets_no_pin_and_no_enqueue and test_the_lane_neither_pins_nor_enqueues_a_native_stack_layer.
Refusal comment and needs-human #17541's note(..., clears: "person"), shown on sandbox PR 398 (run 44680029102). The gate posts nothing more, so the person gets one comment.
A person's enqueue lands the layer Sandbox PR 398: the owner enqueued it at 18:23:21Z and it merged through the queue at 18:24:32Z (#15410 comment). The gate's new check sits after the "already queued or merged" hold, so a layer a person has enqueued is left alone.

The one async merge enable-auto-merge.mjs sends per bottom layer (the call GitHub refused in run 44680029102) is #17541's design under the item. This PR does not change it.

Verification

  • python3 plugins/source-control/skills/babysit-prs/scripts/tests/test_babysit_merge_unattended.py -k stack: 5 pass. New tests:
    • EachRefusalMakesNoMergeCall.test_a_native_stack_layer_gets_no_pin_and_no_enqueue: exit 10, no gh_capture write at all, and the native-stack-layer blocker.
    • EachRefusalMakesNoMergeCall.test_a_null_stack_still_enqueues: pin, then enqueue.
    • LaneMode.test_the_lane_neither_pins_nor_enqueues_a_native_stack_layer: the same hold under --authority pr-merge.
    • With the babysit_merge.py change stashed, both stack-layer tests fail (0 != 10).
  • The harness's REST pull record now carries "stack": null by default, as GitHub sends it for a PR in no stack. Every existing enqueue test therefore also covers the null case.
  • Whole file: 312 tests, 11 fail, and the same 11 fail on unchanged main in this environment (AttachEdits, HeadFileFailure, LaneEvidenceReadToken, LaneEvidenceReadTokenOutage, which are lane-evidence token reads). None of them touch this path.
  • bash scripts/check-affected.sh: 19 passed, 1 skipped over the 4 changed files.

Remaining

  • pr-pipeline: merge and issue lanes for native stack layers #15410 done-when item 2, the issue lane (#17539), stays open. That is why this PR says Refs, not Closes.
  • Not yet observed in the sandbox: a :11/:41 sweep on a stack layer after this merges that shows the gate's native-stack-layer hold, with no pin comment and no enqueuePullRequest group.
  • The attended path has the same refusal and is out of scope here. It is babysit_merge.py main() under --stacked-prs on a merge-queue base: a stack member goes to async_merge(merge_action="merge_queue"), which sends GraphQL enqueuePullRequest, and GitHub refuses that for a stack layer. Whether that path should use REST merge-async for a person's token is not decided here.

Related

🤖 Generated with Claude Code

… and enqueue

On a merge-queue base the unattended gate posted its pin comment and called
GraphQL enqueuePullRequest on a native stack layer every sweep, and GitHub
refused each time ("This pull request is part of a stack and must be enqueued
using the asynchronous merge REST API"). unattended_enqueue now reads the
`stack` field of the REST pull record the policy already holds and, on a
stack layer, holds with no pin and no enqueue. enable-auto-merge.mjs keeps
the person handoff for the bottom layer.

Refs: #15410

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 20, 2026 19:09
@chatgpt-codex-connector

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-20T19:10:42.682277Z 74b0b39 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.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 74b0b39d842453c487fea4de868146b9542cfee3: read 4 of 4 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #17685

I found no security issues.

What changed. In babysit_merge.py, unattended_enqueue gets a new early hold at L5290-L5294. When the REST pull record the policy already holds (inputs["pr"]) has a non-null stack object, the function refuses before it posts the pin comment or calls enqueuePullRequest. The rest of the diff is a changelog fragment, one docs sentence in stacked-prs.md, and tests.

Trust-control check. babysit_merge.py is a trusted path, and it sits in the babysit merge-hold path. I read its whole change and the function around it (L5245-L5299):

  • The change only adds a hold. The new branch can only return hold(...), which exits 10 with ready = False and adds a blocker. It never lets a PR through that the base code would have stopped.
  • Every existing check still runs before it, in the same order: the pinned-head check, the merge-queue-only check, the queue read error, disarming an armed auto-merge, and the already-queued-or-merged check.
  • A null or missing stack behaves exactly as before. json_object(...) and is_json_object(...) are already imported at L230-L232.
  • The new code adds no write, no token use and no new external input. stack comes from GitHub's own REST pull response, not from text a PR author writes.

No trust control is widened, no token scope changes, no merge hold is weakened, and no new untrusted text reaches a lane. No plugin manifest or instruction surface is touched.

Spend. No new spend: the change removes about 5 API calls per stack layer per sweep and adds none.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 74b0b39d842453c487fea4de868146b9542cfee3: read 4 of 4 changed file(s); 0 finding(s), 0 as inline comments.

Code review: PR #17685, hold a native stack layer before the unattended pin and enqueue

No blocking or advisory findings. I read all 4 changed files in full in the diff: the changelog fragment, stacked-prs.md, babysit_merge.py and test_babysit_merge_unattended.py.

What I checked

  • Where the new check gets its data. In unattended_enqueue the check reads inputs["pr"]. That record comes from babysit_merge_policy.pull_request (babysit_merge_policy.py#L7407), which makes an unfiltered GET repos/{o}/{r}/pulls/{n} call (L6315-L6324). So the stack field is present.
  • Same rule as the existing helper. The new check, is_json_object(json_object(...).get("stack")), decides membership the same way pull_request_stack does (babysit_merge.py#L1501-L1511). A null or missing stack still enqueues.
  • Placement. The check sits after the "already queued or merged" and disarm holds, and before the ejection, pin and enqueue steps. So nothing is written for a stack layer, and a layer a person already enqueued is left alone. This matches the PR description.
  • Tests. The new tests cover both the gate path and the pr-merge lane path: a stack layer exits 10 with no write and carries the native-stack-layer blocker, and a null stack still pins and enqueues. The harness now sends "stack": None by default, so the existing enqueue tests also cover the null case. The PR's test counts and its stash-and-fail check are the author's claims; I did not run them.
  • Closing issue. The PR says Refs #15410, not Closes, so no closing-issue section was given to check against. The description's mapping to done-when item 1 is the author's claim, and the part this diff carries matches it.
  • Docs and changelog. The docstring and stacked-prs.md describe the new hold accurately. A patch bump fits a bug fix.
  • Plugin manifests. The diff changes no plugin.json or marketplace.json, so there are no manifest lines.
  • Trusted path. babysit_merge.py is on the trusted list. The change only adds a hold: it widens nothing and adds no API call.
  • Spend. None; the change removes API calls.

Loosened checks. The change tightens the merge gate and loosens no check. Loosened checks would be marked: fail (default; the prompt gave no loosened_check_verdict: or loosened_check_patterns: line); patterns: 0. The prompt also gave no loosened_check_decision_record: line, so I did not check the citation requirement.

Verifier dropped 0 of 0 candidates.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 05cb5e7 Nov 20, 2026
80 checks passed
@kyle-sexton
kyle-sexton deleted the fix/15410-gate-skip-stack-layer-enqueue branch November 20, 2026 19:27
@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