ci: cancel a PR run the next push has already replaced - #877
Open
fujibee wants to merge 2 commits into
Open
Conversation
This was referenced Aug 18, 2026
Measured over the last 92 PR-branch runs of this workflow: 65 of them (71%) had been overtaken by a later push to the same branch before they finished, and each was still holding four macOS runner slots while it queued. macOS is the scarce resource, and the wait is self-inflicted. Queue time to first macOS job, across the last 40 runs: macOS median 18.6 min max 167.1 min over 20 min in 19 of 40 ubuntu median 0.3 min max 32.5 min over 20 min in 1 of 40 Every one of the thirteen runs created in the busiest two-hour window waited between 20 and 167 minutes; outside it the median is 9.3. One branch alone produced fifteen runs, fourteen of them obsolete on arrival. The group is the PR number, so a push cancels only the run for the commit it replaced. Pushes to main key on the SHA instead: each is its own group, so they are neither cancelled nor serialised behind one another.
fujibee
force-pushed
the
ci/cancel-superseded-runs
branch
from
August 19, 2026 16:32
4b64b9e to
6101089
Compare
The figures in the comment were taken before #885 raised the shard timeout from 25 to 30 minutes and moved the heavy files between shards, and they have not been re-measured since. They are kept, and now say so. What #885 does not change is the mechanism: a run still asks for four macOS jobs, and a superseded run still holds them. The 71% superseded rate and the per-run job count follow from how branches are pushed and how the matrix is shaped, not from the timeout.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CI only. One file,
.github/workflows/tests.yml, and nothing a user installs or runs changes.A superseded run keeps its macOS jobs queued, and those are the scarce ones.
The measurements below are a historical baseline
Taken 2026-08-19, over the runs of this workflow that existed at that point — before #885 raised the shard timeout from 25 to 30 minutes and moved the heavy files between shards. The queue figures have not been re-measured since.
They are kept because they are what motivated this change, and because the mechanism they describe is untouched by #885: a run still asks for four macOS jobs, and a superseded run still holds them until it is cancelled.
The wait arrived in bursts:
And what makes the burst is that nothing stops a superseded run:
Each of those 65 was still holding four macOS runner slots for a commit whose result nobody would read. One branch produced fifteen runs; fourteen were obsolete on arrival, which is fifty-six macOS jobs spent on stale answers.
Structural, and unchanged by #885: the 71% superseded rate and the four macOS jobs per run. Those follow from how branches are pushed and how the matrix is shaped, not from the timeout.
The change
Keyed on the PR number, so a push cancels the run for the commit it replaced and nothing else. Pushes to
mainfall back to the SHA, which gives each its own group: never cancelled, becausecancel-in-progressis false off thepull_requestevent, and never serialised behind one another either — which a shared group would have done, and which would be a worse failure than the one being fixed.What this does not do
It does not make a single run faster. A run nobody supersedes waits exactly as long as before. What it removes is the demand a superseded run keeps making.
Not measured
Queue times after #885. The timeout change and the shard re-placement both affect how long a macOS job occupies a runner, so the figures above should be read as the state that prompted this, not as the state today.