Skip to content

Cancel superseded pull request runs, and guard that they stay cancelled - #11345

Merged
danielhanchen merged 1 commit into
mainfrom
ci-cancel-superseded-pr-runs
Sep 20, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci-cancel-superseded-pr-runs

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What this fixes

runner-pool-probe.yml carried no concurrency: block at all. It is triggered by pull_request and fans out to a ten-runner matrix, four of them macOS at 10x the minute rate, so a second push to the same pull request left a full ten-runner matrix measuring a commit nobody will merge.

Superseding does not weaken what the probe measures. It compares labels within one dispatch, the ten cells leaving the queue in the same second, so a cancelled older matrix takes a whole self-contained measurement with it rather than half of the current one. Two dispatches were never comparable to each other anyway, because the queue they sampled is not the same queue.

Why this is more than a three-line fix

I audited all 57 workflows here. 43 of the 46 pull-request-triggered ones already cancel correctly, and the two Kaggle exemptions are deliberate and documented. The probe was the only real gap. The question is why nothing caught it.

tests/studio/test_main_runs_survive_merge_bursts.py covers the neighbouring question and stops short of this one in two ways:

  1. Its scan starts from push: branches: [main]. A workflow triggered only by pull_request is outside it entirely, which is how runner-pool-probe.yml reached main with no block.
  2. It asks whether two commits on a pull request share a group. That is necessary and not sufficient. GitHub discards a pending run when a newer one takes its group, but a run that has already started is only cancelled when cancel-in-progress is truthy, and the started run is the one holding the runners.

The guard

tests/studio/test_pull_requests_cancel_superseded_runs.py asks the remaining half of every pull-request-triggered workflow: rendered on a pull request ref, does cancel-in-progress evaluate true?

Rendered rather than grepped. ${{ github.ref != 'refs/heads/main' }} and ${{ github.ref == 'refs/heads/main' }} are the same tokens in the same order and mean the opposite, so a substring test calls them both fine. The evaluator refuses to guess, and test_every_cancel_expression_is_understood makes a refusal fail loudly rather than skip.

It also asserts the other direction. test_cancelling_is_still_gated_off_main requires that a workflow which pushes to main does not cancel there, so fixing this half cannot re-create the merge-burst incident on the way past.

The two Kaggle workflows stay exempt, with the reason restated at the exemption rather than only at their own concurrency: block: cancelling the runner cannot stop a kernel it has already pushed, and an orphaned kernel bills quota to its own ceiling with nobody left to read the result.

It runs from workflow-trigger-lint.yml, the one job with no paths filter, because a pull request that edits only a workflow collects no other test that reads one. test_this_guard_runs_on_a_workflow_only_pull_request keeps it there.

Verification

tests/studio/test_pull_requests_cancel_superseded_runs.py            8 passed

Negative control, with the runner-pool-probe.yml fix stashed:

FAILED test_every_pull_request_workflow_declares_concurrency
1 failed, 7 passed

The existing workflow-policing guards are unaffected:

test_workflow_guards_run_unfiltered.py, test_short_job_absorption.py,
test_absorbed_lanes_still_run.py, test_main_runs_survive_merge_bursts.py,
test_macos_slots_per_commit.py, test_cache_budget_discipline.py,
test_pull_requests_cancel_superseded_runs.py          137 passed in 57.24s

scripts/lint_workflow_triggers.py
OK: scanned 57 workflow file(s)

Not in scope

unslothai/unsloth-zoo has the same shape and no gap: three of its four pull-request workflows cancel, and gemma4-audio-probe.yml declines deliberately because it is types: [labeled] only and concurrency is claimed before the job-level if. unslothai/notebooks is clean. unslothai/llama.cpp has one instance of this defect in unsloth-pr-set-lint.yml; its heavyweight upstream workflows all carry upstream's own cancel-in-progress: true.

runner-pool-probe.yml carried no concurrency block at all. It is triggered
by pull_request and fans out to a ten-runner matrix, four of them macOS at
10x the minute rate, so a second push to the same pull request left a full
ten-runner matrix measuring a commit nobody will merge.

Superseding does not weaken what the probe measures. It compares labels
within one dispatch, the ten cells leaving the queue in the same second, so
a cancelled older matrix takes a whole self-contained measurement with it
rather than half of the current one. Two dispatches were never comparable
to each other anyway, because the queue they sampled is not the same queue.

The guard is the reason this is more than a three-line fix.
test_main_runs_survive_merge_bursts.py already covers the neighbouring
question and stops short of this one in two ways. Its scan starts from
push: branches: [main], so a workflow triggered only by pull_request is
outside it entirely, which is how runner-pool-probe.yml reached main with
no block. And it asks whether two commits on a pull request share a group,
which is necessary and not sufficient: GitHub discards a pending run when a
newer one takes its group, but a run that has already started is only
cancelled when cancel-in-progress is truthy, and the started run is the one
holding the runners.

tests/studio/test_pull_requests_cancel_superseded_runs.py asks the
remaining half of every pull-request-triggered workflow: rendered on a pull
request ref, does cancel-in-progress evaluate true. Rendered rather than
grepped, because the repo's usual form and its reversal are the same tokens
in the same order and mean the opposite; the evaluator refuses to guess and
a refusal fails loudly. It also asserts the other direction, that a
workflow which pushes to main does not cancel there, so fixing this half
cannot re-create the merge-burst incident on the way past.

The two Kaggle workflows stay exempt with the reason restated in the file:
cancelling the runner cannot stop a kernel it has already pushed, and an
orphaned kernel bills quota with nobody left to read the result.

It runs from workflow-trigger-lint.yml, the one job with no paths filter,
because a pull request that edits only a workflow collects no other test
that reads one.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-20T00:51:39.254688Z 16fb93e PR opened
🔒 Security Review ✅ Completed 2026-09-20T00:52:20.857100Z 16fb93e PR opened
ℹ️ 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.

@danielhanchen
danielhanchen merged commit 04c9951 into main Sep 20, 2026
30 of 33 checks passed
@danielhanchen
danielhanchen deleted the ci-cancel-superseded-pr-runs branch September 20, 2026 00:50

@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: 16fb93eb0b

ℹ️ 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".

missing block is not a mis-evaluated expression, and runner-pool-probe.yml reached main
as one.
"""
offenders = sorted(name for name, document in _scanned().items() if not _group(document))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require pull-request runs to share a concurrency group

For a pull-request-only workflow, group: ${{ github.sha }} together with cancel-in-progress: true passes this assertion and every other test in this file, but each synchronized commit enters a different group, so GitHub never cancels the superseded run. The existing test_a_pull_request_still_gets_latest_only cannot catch this because it scans only workflows that also push to main; render the group for two SHAs across every workflow in _scanned() and require the results to match.

Useful? React with 👍 / 👎.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 20, 2026
unslothai#11345 landed tests/studio/test_pull_requests_cancel_superseded_runs.py with one
assert the ruff-format-with-kwargs hook rewrites, so main is not a fixed point
of its own formatter. That fails tests/test_formatter_fixed_point.py, which is
in the "Repo tests (CPU, rest)" shard, and it fails pre-commit.ci on every pull
request, since pre-commit.ci runs the hook over all files and reports that it
modified one. Neither failure has anything to do with the pull request that
sees it.

Ran the hook over the file with the pinned ruff (0.6.9, from the hook's own
additional_dependencies) and committed what it produced. The file's own eight
tests still pass, tests/test_formatter_fixed_point.py goes from 1 failed / 10
passed to 11 passed, and pre-commit run --all-files passes all three hooks.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 20, 2026
unslothai#11347)

* Correct why a superseded probe matrix is expensive: slots, not minutes

The comment unslothai#11345 landed on runner-pool-probe.yml justified cancelling by
"four of them macOS at 10x the minute rate". That rate is real but it is
not what this costs. These repositories are public, standard GitHub-hosted
runners are free for public repositories, and every label in the probe's
matrix is a standard runner, so the account's included-minutes meter reads
0 of 3,000 used and will keep reading zero no matter what this workflow
does. The 3,000 included minutes apply to private repositories.

The real cost is concurrency. Four of the probe's ten cells are macOS, and
GitHub caps macOS at five concurrent jobs ACCOUNT-WIDE across every
repository -- the same cap test_macos_slots_per_commit.py already exists to
protect, and the reason it records median macOS queue waits of 245 minutes.
A superseded matrix was holding four of those five slots for up to ten
minutes, and the queue it delays belongs to the whole account rather than
to this workflow.

So the fix is unchanged and the argument for it is stronger. Only the
reason is corrected, here and in the guard's docstring, because this repo
already treats a workflow comment that claims something untrue as a defect
worth a test: see test_no_workflow_claims_a_main_protection_it_does_not_have,
written after 27 files carried a comment asserting a protection they did
not have.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Give the probe's cost claim a measured number, and guard it

* Judge the duration claim per occurrence, not per sentence

* Read the occupancy unit off the hold claim itself

* Parse what governs a duration, and check the claim against its own measurement

* Check every occupancy claim, and let a hung cell say it holds

* Recognise the duration's form, then parse it, and fail when it cannot be read

* Take the hung-cell exemption on a positive qualifier only

* Cover the past tense, and refuse a qualifier that covers one holder of several

* Say what cancelling actually saves, and read a number spelled across words

* Take the yardstick from the claim's own sentence, and the excuse from its own clause

* Read the other slot-taking verbs, and refuse a denied hang as an excuse

* Make the third guard demand a positive explanation too

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Replace the prose parser with two mechanical rules

* The cells enter the queue together; when they leave is the measurement

* A hyphen is a separator, so ten-minute is ten minutes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…ed (unslothai#11345)

runner-pool-probe.yml carried no concurrency block at all. It is triggered
by pull_request and fans out to a ten-runner matrix, four of them macOS at
10x the minute rate, so a second push to the same pull request left a full
ten-runner matrix measuring a commit nobody will merge.

Superseding does not weaken what the probe measures. It compares labels
within one dispatch, the ten cells leaving the queue in the same second, so
a cancelled older matrix takes a whole self-contained measurement with it
rather than half of the current one. Two dispatches were never comparable
to each other anyway, because the queue they sampled is not the same queue.

The guard is the reason this is more than a three-line fix.
test_main_runs_survive_merge_bursts.py already covers the neighbouring
question and stops short of this one in two ways. Its scan starts from
push: branches: [main], so a workflow triggered only by pull_request is
outside it entirely, which is how runner-pool-probe.yml reached main with
no block. And it asks whether two commits on a pull request share a group,
which is necessary and not sufficient: GitHub discards a pending run when a
newer one takes its group, but a run that has already started is only
cancelled when cancel-in-progress is truthy, and the started run is the one
holding the runners.

tests/studio/test_pull_requests_cancel_superseded_runs.py asks the
remaining half of every pull-request-triggered workflow: rendered on a pull
request ref, does cancel-in-progress evaluate true. Rendered rather than
grepped, because the repo's usual form and its reversal are the same tokens
in the same order and mean the opposite; the evaluator refuses to guess and
a refusal fails loudly. It also asserts the other direction, that a
workflow which pushes to main does not cancel there, so fixing this half
cannot re-create the merge-burst incident on the way past.

The two Kaggle workflows stay exempt with the reason restated in the file:
cancelling the runner cannot stop a kernel it has already pushed, and an
orphaned kernel bills quota with nobody left to read the result.

It runs from workflow-trigger-lint.yml, the one job with no paths filter,
because a pull request that edits only a workflow collects no other test
that reads one.
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
unslothai#11345 landed tests/studio/test_pull_requests_cancel_superseded_runs.py with one
assert the ruff-format-with-kwargs hook rewrites, so main is not a fixed point
of its own formatter. That fails tests/test_formatter_fixed_point.py, which is
in the "Repo tests (CPU, rest)" shard, and it fails pre-commit.ci on every pull
request, since pre-commit.ci runs the hook over all files and reports that it
modified one. Neither failure has anything to do with the pull request that
sees it.

Ran the hook over the file with the pinned ruff (0.6.9, from the hook's own
additional_dependencies) and committed what it produced. The file's own eight
tests still pass, tests/test_formatter_fixed_point.py goes from 1 failed / 10
passed to 11 passed, and pre-commit run --all-files passes all three hooks.
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
unslothai#11347)

* Correct why a superseded probe matrix is expensive: slots, not minutes

The comment unslothai#11345 landed on runner-pool-probe.yml justified cancelling by
"four of them macOS at 10x the minute rate". That rate is real but it is
not what this costs. These repositories are public, standard GitHub-hosted
runners are free for public repositories, and every label in the probe's
matrix is a standard runner, so the account's included-minutes meter reads
0 of 3,000 used and will keep reading zero no matter what this workflow
does. The 3,000 included minutes apply to private repositories.

The real cost is concurrency. Four of the probe's ten cells are macOS, and
GitHub caps macOS at five concurrent jobs ACCOUNT-WIDE across every
repository -- the same cap test_macos_slots_per_commit.py already exists to
protect, and the reason it records median macOS queue waits of 245 minutes.
A superseded matrix was holding four of those five slots for up to ten
minutes, and the queue it delays belongs to the whole account rather than
to this workflow.

So the fix is unchanged and the argument for it is stronger. Only the
reason is corrected, here and in the guard's docstring, because this repo
already treats a workflow comment that claims something untrue as a defect
worth a test: see test_no_workflow_claims_a_main_protection_it_does_not_have,
written after 27 files carried a comment asserting a protection they did
not have.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Give the probe's cost claim a measured number, and guard it

* Judge the duration claim per occurrence, not per sentence

* Read the occupancy unit off the hold claim itself

* Parse what governs a duration, and check the claim against its own measurement

* Check every occupancy claim, and let a hung cell say it holds

* Recognise the duration's form, then parse it, and fail when it cannot be read

* Take the hung-cell exemption on a positive qualifier only

* Cover the past tense, and refuse a qualifier that covers one holder of several

* Say what cancelling actually saves, and read a number spelled across words

* Take the yardstick from the claim's own sentence, and the excuse from its own clause

* Read the other slot-taking verbs, and refuse a denied hang as an excuse

* Make the third guard demand a positive explanation too

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Replace the prose parser with two mechanical rules

* The cells enter the queue together; when they leave is the measurement

* A hyphen is a separator, so ten-minute is ten minutes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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