Skip to content

ci: cancel a pull request's unfinished runs when it merges - #2527

Merged
sbryngelson merged 1 commit into
MFlowCode:masterfrom
sbryngelson:cancel-merged-runs
Nov 27, 2026
Merged

sbryngelson merged 1 commit into
MFlowCode:masterfrom
sbryngelson:cancel-merged-runs

Conversation

@sbryngelson

Copy link
Copy Markdown
Member

When a pull request merges, cancels its unfinished workflow runs. The runs started by the push to master are not touched.

1. Does it solve the problem?

Command that shows it:

# the workflow's step against live runs, printing run ids in place of cancelling them
GITHUB_REPOSITORY=MFlowCode/MFC GITHUB_RUN_ID=0 BRANCH=<branch> HEAD=<owner>/MFC bash step.sh
Quantity master this PR expected
unfinished runs cancelled when a PR merges 0 all its pull request runs all its pull request runs
runs selected for an open PR branch (dry run) 11 of its pull request runs pull request runs of that branch only
runs selected for master of this repository, with master runs unfinished (dry run) 0 0
runs selected for the same branch name in another repository (dry run) 0 0

Why the new result is right (analytic solution, reference data, convergence, ...): only pull_request* events whose head repository and branch match the merged pull request are selected, so push, scheduled and follow-on runs are never candidates.

2. Does it create another one?

Check Result
Tests: command, number passed, number failed ./mfc.sh lint: 1033 passed, 0 failed; ./mfc.sh precheck passes; actionlint passes on the new file
Golden files changed: count, largest difference, why 0
Not tested the workflow running on GitHub, which needs it on master first

3. Is it slower?

N/A: no src/ or build files change.

Notes

  • Uses pull_request_target with only actions: write, so pull requests from forks are covered; it checks out and runs no pull request code.
  • Pull requests closed without merging are left running.
  • The test and benchmark workflows cancel their SLURM jobs when a run is cancelled.
  • The cancelling job needs a runner, so it can wait in a backlog.

Runs triggered by the push to master are not touched.
@sbryngelson
sbryngelson requested a review from a team as a code owner November 27, 2026 00:21
@sbryngelson
sbryngelson requested review from danieljvickers and removed request for a team November 27, 2026 00:21
@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: b88128a

No review was produced. Claude ran but wrote no review (Claude step: failure). Run and transcript: https://github.com/MFlowCode/MFC/actions/runs/45916230281

@sbryngelson
sbryngelson merged commit 5eadc8f into MFlowCode:master Nov 27, 2026
25 of 26 checks passed
@sbryngelson
sbryngelson deleted the cancel-merged-runs branch November 27, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant