Skip to content

Gate standard merge on the newest pull_request Check run - #3

Merged
mapringg merged 5 commits into
developfrom
gate-merge-on-newest-pr-check
Nov 16, 2026
Merged

mapringg merged 5 commits into
developfrom
gate-merge-on-newest-pr-check

Conversation

@mapringg

@mapringg mapringg commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

standard merge refused when any Check run on the head commit was not green. GitHub keeps every run per commit. So one run cancelled by cancel-in-progress, or one skipped on a draft or closed event, blocked the merge forever. Two adopting repos had to drop cancellation or add a side workflow because of this.

The gate now counts only Check runs from pull_request workflow runs on the exact head commit, and the newest run decides:

  • The newest run is the pull_request run of the workflow that holds Check whose latest attempt started last (run_started_at, then the higher run id). A re-run moves that time forward. A run that waits in a concurrency group has that time before its Check run exists. So an older success cannot stand in for a newer run.
  • The gate reads the workflow runs, then the check runs, then the workflow runs again. If the newest run's id, attempt or status differs between the two workflow reads, it refuses with retry:. When both reads show the same completed attempt, that attempt ended before the check runs were read, so the Check that GitHub lists for its check suite belongs to that attempt or was carried into it.
  • While any pull_request workflow run on the head commit is unfinished in either workflow read, the gate refuses with wait:. This covers a workflow whose Check run does not exist yet, which the gate cannot otherwise tell apart from a workflow without Check. It also covers a re-run that carries a green Check from an earlier attempt. So a merge waits for every pull_request workflow on the head, not only the one that holds Check. After that, success merges, and any other conclusion refuses and names it. Older cancelled or skipped runs do not block.
  • A push or pull_request_target run on the same commit no longer counts.
  • The Check run must start after the last ready_for_review event. The gate reads the start time of the Check run itself, because a re-run of failed jobs copies that time from the earlier attempt.
  • Each gh api read projects only the fields the gate uses with --jq, and the output buffer is 256 MiB.

The README now says that pr-size needs both issues: write and pull-requests: write. It also gives the recommended CI types and concurrency with cancel-in-progress: true. The release is 0.5.3, on top of the 0.5.2 hook fix.

Evidence

The old and new mergeDecision ran on live runs from public repos. The new side read them through the same --jq filters that the source uses. Each repo's aggregate job was read as Check. This repo has no CI runs of its own to replay.

Case Before After
nodejs/node#67460, older run cancelled, newer run green refuse, Check ... concluded cancelled merge
nodejs/node#67517, older run cancelled, newer run green refuse, Check ... concluded skipped merge
nodejs/node#67515, draft-time run skipped, ready_for_review run green refuse, Check ... concluded skipped merge
nodejs/node 4b6fe8b, older run green, newer run red refuse, failure and skipped refuse, ... the newest on 4b6fe8b, concluded failure.
vitejs/vite#24068, newest run started 05:41:31, ready_for_review at 05:42:31 merge refuse, ... started at 2026-11-11T05:41:31Z, before the pull request left draft at 2026-11-11T05:42:31Z.
vitejs/vite#23837, pull_request run cancelled, push run on the same commit refuse, skipped and cancelled refuse, ... the newest on 5926a2a, concluded cancelled.

Two independent verifier rounds ran adversarial cases through the CLI against a fake gh. Its fake pipes each page through real jq with the --jq filter that the source passes.

Before: at 44c82c1, 32 cases, 4 mismatches. A rerun that started between the reads merged. A re-run that was queued or in progress and carried a green Check merged. 106 workflow runs at about 12 KB each failed with spawnSync gh ENOBUFS. At 047e5cd, 10 fresh cases, 1 mismatches. A newer queued run of a second workflow that holds Check was ignored, so an older green Check merged.

After: at this head, 32 cases, 0 mismatches and 10 fresh cases, 0 mismatches. All 42 cases are also in test/merge.test.mjs. node --test gives 193 pass and 0 fail, and tsc --checkJs --strict is clean. On nodejs/node 6c7c893, the workflow run response is 276,922 bytes in full and 5,708 bytes projected for 23 runs.

Merge Danger

Door: two-way

Blast Radius: merges. standard merge now makes four gh api reads after pr view. With a fine-grained token, the workflow runs read needs actions: read. Every pull_request workflow run on the head must finish before a merge, including jobs after Check and workflows without Check. A green Check with a later failing job in the same run still merges, as before. A repo whose CI does not run on ready_for_review has to run Check again after a draft becomes ready, and the refusal message says so.

@mapringg
mapringg force-pushed the gate-merge-on-newest-pr-check branch from 44c82c1 to 047e5cd Compare November 16, 2026 20:54
@mapringg
mapringg merged commit 90e3854 into develop Nov 16, 2026
@mapringg
mapringg deleted the gate-merge-on-newest-pr-check branch November 16, 2026 21:05
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