Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
CI: only cancel superseded pull request runs, never dispatches or schedules (#11977)
Daniel Han393db423fef3
diff --git a/.github/workflows/clean-machine-install-ci.yml b/.github/workflows/clean-machine-install-ci.ymlindex d7d7ec0c2b4..0e9cade61d9 100644--- a/.github/workflows/clean-machine-install-ci.yml+++ b/.github/workflows/clean-machine-install-ci.yml@@ -123,7 +123,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/consolidated-tests-ci.yml b/.github/workflows/consolidated-tests-ci.ymlindex c0aa673c0a4..40a743050b6 100644--- a/.github/workflows/consolidated-tests-ci.yml+++ b/.github/workflows/consolidated-tests-ci.yml@@ -87,7 +87,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/cross-platform-parity-ci.yml b/.github/workflows/cross-platform-parity-ci.ymlindex 3ba5c71a847..ba2f5be54c5 100644--- a/.github/workflows/cross-platform-parity-ci.yml+++ b/.github/workflows/cross-platform-parity-ci.yml@@ -211,7 +211,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/desktop-app-clean-machine-ci.yml b/.github/workflows/desktop-app-clean-machine-ci.ymlindex 3f8290a0463..a149353c048 100644--- a/.github/workflows/desktop-app-clean-machine-ci.yml+++ b/.github/workflows/desktop-app-clean-machine-ci.yml@@ -65,7 +65,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:# Drafts are listed only to a token with push access. Clean-machine CI intentionallydiff --git a/.github/workflows/interrupted-install-ci.yml b/.github/workflows/interrupted-install-ci.ymlindex 974b9514546..f7c0cd83452 100644--- a/.github/workflows/interrupted-install-ci.yml+++ b/.github/workflows/interrupted-install-ci.yml@@ -84,7 +84,7 @@ concurrency:# cannot cancel a pending run (see studio-backend-ci.yml). On a PR branch the group is# the ref, so a new push cancels the run for the previous one.group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}-${{ github.ref == 'refs/heads/main' && github.sha || '' }}- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/local-agent-guides-ci.yml b/.github/workflows/local-agent-guides-ci.ymlindex 035ab6dc027..e47730c8f07 100644--- a/.github/workflows/local-agent-guides-ci.yml+++ b/.github/workflows/local-agent-guides-ci.yml@@ -115,7 +115,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/notebooks-ci.yml b/.github/workflows/notebooks-ci.ymlindex 1408f12b235..2a4da4ed13f 100644--- a/.github/workflows/notebooks-ci.yml+++ b/.github/workflows/notebooks-ci.yml@@ -61,7 +61,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/pester-guard-ci.yml b/.github/workflows/pester-guard-ci.ymlindex 295c45ff4ea..c69f7d7be0d 100644--- a/.github/workflows/pester-guard-ci.yml+++ b/.github/workflows/pester-guard-ci.yml@@ -21,7 +21,7 @@ on:concurrency:group: ${{ github.workflow }}-${{ github.ref }}- cancel-in-progress: true+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/security-audit.yml b/.github/workflows/security-audit.ymlindex 86adbb16a5b..aa5340fb7f8 100644--- a/.github/workflows/security-audit.yml+++ b/.github/workflows/security-audit.yml@@ -103,7 +103,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/startup-profile-ci.yml b/.github/workflows/startup-profile-ci.ymlindex 9084c33be99..13b4636475e 100644--- a/.github/workflows/startup-profile-ci.yml+++ b/.github/workflows/startup-profile-ci.yml@@ -73,7 +73,7 @@ on:concurrency:group: ${{ github.workflow }}-${{ github.ref }}- cancel-in-progress: true+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studio-api-smoke.yml b/.github/workflows/studio-api-smoke.ymlindex 369df1be24f..b831fea4e77 100644--- a/.github/workflows/studio-api-smoke.yml+++ b/.github/workflows/studio-api-smoke.yml@@ -93,7 +93,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studio-composer-compatibility.yml b/.github/workflows/studio-composer-compatibility.ymlindex d7c6c15ae01..6ce6276f832 100644--- a/.github/workflows/studio-composer-compatibility.yml+++ b/.github/workflows/studio-composer-compatibility.yml@@ -37,7 +37,7 @@ permissions:concurrency:group: ${{ github.workflow }}-${{ github.ref }}- cancel-in-progress: true+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}jobs:composer:diff --git a/.github/workflows/studio-export-capability-ci.yml b/.github/workflows/studio-export-capability-ci.ymlindex 8070d81d24a..a1b68f7a024 100644--- a/.github/workflows/studio-export-capability-ci.yml+++ b/.github/workflows/studio-export-capability-ci.yml@@ -45,7 +45,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studio-inference-smoke.yml b/.github/workflows/studio-inference-smoke.ymlindex 851bec2c3cc..e7024a739b6 100644--- a/.github/workflows/studio-inference-smoke.yml+++ b/.github/workflows/studio-inference-smoke.yml@@ -109,7 +109,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studio-inline-images.yml b/.github/workflows/studio-inline-images.ymlindex eb7e801e55f..1bf0db994e2 100644--- a/.github/workflows/studio-inline-images.yml+++ b/.github/workflows/studio-inline-images.yml@@ -34,7 +34,7 @@ permissions:concurrency:group: ${{ github.workflow }}-${{ github.ref }}- cancel-in-progress: true+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}jobs:images:diff --git a/.github/workflows/studio-mac-install-matrix.yml b/.github/workflows/studio-mac-install-matrix.ymlindex 809e7247695..c6ffae308ea 100644--- a/.github/workflows/studio-mac-install-matrix.yml+++ b/.github/workflows/studio-mac-install-matrix.yml@@ -94,7 +94,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studio-mac-ui-smoke.yml b/.github/workflows/studio-mac-ui-smoke.ymlindex 68235a247f8..4e8e887a502 100644--- a/.github/workflows/studio-mac-ui-smoke.yml+++ b/.github/workflows/studio-mac-ui-smoke.yml@@ -129,7 +129,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studio-ui-smoke.yml b/.github/workflows/studio-ui-smoke.ymlindex 8a780bdb0fb..40215166399 100644--- a/.github/workflows/studio-ui-smoke.yml+++ b/.github/workflows/studio-ui-smoke.yml@@ -108,7 +108,7 @@ concurrency:# in 37 minutes cancelled three consecutive main runs of this workflow and none# completed. Detection survives on the tip, since the tree is cumulative;# per-commit attribution does not.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studio-update-smoke.yml b/.github/workflows/studio-update-smoke.ymlindex e5a9c78d7e9..92a129a446e 100644--- a/.github/workflows/studio-update-smoke.yml+++ b/.github/workflows/studio-update-smoke.yml@@ -108,7 +108,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studio-windows-api-smoke.yml b/.github/workflows/studio-windows-api-smoke.ymlindex 7d1473f3723..a3f509ba659 100644--- a/.github/workflows/studio-windows-api-smoke.yml+++ b/.github/workflows/studio-windows-api-smoke.yml@@ -82,7 +82,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studio-windows-inference-smoke.yml b/.github/workflows/studio-windows-inference-smoke.ymlindex 543a6b95fdc..33ab41c7f6a 100644--- a/.github/workflows/studio-windows-inference-smoke.yml+++ b/.github/workflows/studio-windows-inference-smoke.yml@@ -104,7 +104,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studio-windows-ui-smoke.yml b/.github/workflows/studio-windows-ui-smoke.ymlindex 31c8252da06..8a27a022ec5 100644--- a/.github/workflows/studio-windows-ui-smoke.yml+++ b/.github/workflows/studio-windows-ui-smoke.yml@@ -84,7 +84,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studio-windows-update-smoke.yml b/.github/workflows/studio-windows-update-smoke.ymlindex fafa7aa30b3..b69fee63d18 100644--- a/.github/workflows/studio-windows-update-smoke.yml+++ b/.github/workflows/studio-windows-update-smoke.yml@@ -88,7 +88,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/studiobench-ci.yml b/.github/workflows/studiobench-ci.ymlindex 9cff0882c28..23c3e1a9c66 100644--- a/.github/workflows/studiobench-ci.yml+++ b/.github/workflows/studiobench-ci.yml@@ -96,7 +96,7 @@ concurrency:# Unique per commit on main, so a merge burst cannot cancel a pending run# before it starts. Matches studio-ui-smoke.yml, for the reasons documented there.group: ${{ github.workflow }}-${{ github.ref }}-${{ github.ref == 'refs/heads/main' && github.sha || '' }}- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/version-compat-ci.yml b/.github/workflows/version-compat-ci.ymlindex 8ef1e928281..bd750ca5bd0 100644--- a/.github/workflows/version-compat-ci.yml+++ b/.github/workflows/version-compat-ci.yml@@ -50,7 +50,7 @@ concurrency:# a RUNNING main job being killed, but GitHub cancels any PENDING run in the group# the moment a newer one is queued, so a merge burst still leaves only the tip.# See studio-backend-ci.yml, which is grouped per commit on main for that reason.- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/windows-amsi-defender-differential-ci.yml b/.github/workflows/windows-amsi-defender-differential-ci.ymlindex 7d3b8fe10f6..bdefd892e0a 100644--- a/.github/workflows/windows-amsi-defender-differential-ci.yml+++ b/.github/workflows/windows-amsi-defender-differential-ci.yml@@ -50,7 +50,7 @@ permissions:concurrency:group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}- cancel-in-progress: true+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}jobs:measure:diff --git a/.github/workflows/windows-application-control-ci.yml b/.github/workflows/windows-application-control-ci.ymlindex 0da8053d829..ac69babced9 100644--- a/.github/workflows/windows-application-control-ci.yml+++ b/.github/workflows/windows-application-control-ci.yml@@ -90,7 +90,7 @@ on:concurrency:group: ${{ github.workflow }}-${{ github.ref }}-${{ github.ref == 'refs/heads/main' && github.sha || '' }}- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/windows-arm64-ci.yml b/.github/workflows/windows-arm64-ci.ymlindex 09dc630b6d5..d94351259b1 100644--- a/.github/workflows/windows-arm64-ci.yml+++ b/.github/workflows/windows-arm64-ci.yml@@ -46,7 +46,7 @@ on:concurrency:group: ${{ github.workflow }}-${{ github.ref }}-${{ github.ref == 'refs/heads/main' && github.sha || '' }}- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/windows-installer-differential-ci.yml b/.github/workflows/windows-installer-differential-ci.ymlindex bd8637e21c6..4a5b6afa94e 100644--- a/.github/workflows/windows-installer-differential-ci.yml+++ b/.github/workflows/windows-installer-differential-ci.yml@@ -70,7 +70,7 @@ concurrency:# `installer-differential` now share a group of their own, so they cancel each other and never a# measurement.group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ (github.event.action == 'labeled' && github.event.label.name != 'installer-differential') && 'unrelated-label' || 'measure' }}- cancel-in-progress: true+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}env:UNSLOTH_STUDIO_DISABLE_PUBLIC_CHECK: '1'diff --git a/.github/workflows/windows-no-compiler-ci.yml b/.github/workflows/windows-no-compiler-ci.ymlindex 645cd310d7f..132fbf9dc1e 100644--- a/.github/workflows/windows-no-compiler-ci.yml+++ b/.github/workflows/windows-no-compiler-ci.yml@@ -95,7 +95,7 @@ on:concurrency:group: ${{ github.workflow }}-${{ github.ref }}-${{ github.ref == 'refs/heads/main' && github.sha || '' }}- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/.github/workflows/windows-vt-preflight.yml b/.github/workflows/windows-vt-preflight.ymlindex e54c1b626d9..3d52a331f0a 100644--- a/.github/workflows/windows-vt-preflight.yml+++ b/.github/workflows/windows-vt-preflight.yml@@ -32,7 +32,7 @@ permissions:concurrency:group: ${{ github.workflow }}-${{ github.ref }}- cancel-in-progress: true+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}jobs:measure:diff --git a/.github/workflows/workflow-trigger-lint.yml b/.github/workflows/workflow-trigger-lint.ymlindex fdd6d43afc6..c88a80e8a3f 100644--- a/.github/workflows/workflow-trigger-lint.yml+++ b/.github/workflows/workflow-trigger-lint.yml@@ -31,7 +31,7 @@ on:concurrency:group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}-${{ github.ref == 'refs/heads/main' && github.sha || '' }}- cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}permissions:contents: readdiff --git a/tests/python/test_installer_differential_comparer.py b/tests/python/test_installer_differential_comparer.pyindex f8827cb7104..08c892163e7 100644--- a/tests/python/test_installer_differential_comparer.py+++ b/tests/python/test_installer_differential_comparer.py@@ -1422,7 +1422,7 @@ def test_an_unrelated_label_does_not_restart_the_two_installs() -> None:Reading the PR's whole label list meant that adding any label to a PR that already carried`installer-differential` evaluated true and started the lane again, which with- `cancel-in-progress: true` cancels a measurement that is already running. The `labeled` event+ `cancel-in-progress` on a pull request cancels a measurement that is already running. The `labeled` eventhas to look at the label that was just applied; `synchronize` still reads the full list, becausethere no single label was applied."""@@ -1449,7 +1449,8 @@ def test_an_unrelated_label_does_not_restart_the_two_installs() -> None:"the concurrency group does not distinguish the label, so an unrelated label still cancels ""a measurement in progress before this gate can run")- assert "unrelated-label" in group and "cancel-in-progress: true" in group+ assert "unrelated-label" in group+ assert "cancel-in-progress: ${{ github.event_name == 'pull_request' }}" in groupdef test_installer_output_that_looks_like_a_runner_header_survives() -> None:diff --git a/tests/studio/test_pull_requests_cancel_superseded_runs.py b/tests/studio/test_pull_requests_cancel_superseded_runs.pyindex 9608ef6aa7c..18a77c680bb 100644--- a/tests/studio/test_pull_requests_cancel_superseded_runs.py+++ b/tests/studio/test_pull_requests_cancel_superseded_runs.py@@ -25,9 +25,15 @@ request land in the SAME group. Neither is the whole invariant:So this file asks the remaining question, of every pull-request-triggered workflow ratherthan of the main-push ones: on a pull request ref, does ``cancel-in-progress`` evaluate-true? ``cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}`` is the repo's usual-form and it is an expression, not a literal, so it is rendered rather than grepped -- the-reversed form is the same substrings in the same order and means the opposite.+true? ``cancel-in-progress: ${{ github.event_name == 'pull_request' }}`` is the repo's+usual form and it is an expression, not a literal, so it is rendered rather than grepped --+the reversed form is the same substrings in the same order and means the opposite.++It also asks the converse: every run that is NOT a superseded pull request push must finish.+Pushes to main, schedules, and manual or repository dispatches share their group with the+next run of the same kind, and a truthy ``cancel-in-progress`` there lets a second dispatch+on a branch, or a dispatch on main, kill a run somebody started on purpose. Keying the+setting on the event rather than on the ref is what keeps those runs alive on every ref.Three workflows are exempt and each says why at its own ``concurrency:`` block. They arelisted below with the reason restated, because an exemption whose justification lives only@@ -102,19 +108,24 @@ def _condition(text: str, context: dict[str, str]) -> bool:return left == right if match.group(2) == "==" else left != right-def _context(ref: str) -> dict[str, str]:+def _context(ref: str, event_name: str = "pull_request") -> dict[str, str]:return {"github.workflow": "a-workflow","github.ref": ref,"github.sha": "a" * 40,- "github.event_name": "pull_request",+ "github.event_name": event_name,"github.repository": "unslothai/unsloth","github.ref_name": ref.rsplit("/", 1)[-1],}-def _cancels(value, *, ref: str) -> bool:- """Whether ``cancel-in-progress: <value>`` is truthy for a run on ``ref``.+def _cancels(+ value,+ *,+ ref: str,+ event_name: str = "pull_request",+) -> bool:+ """Whether ``cancel-in-progress: <value>`` is truthy for a ``event_name`` run on ``ref``.A literal ``true`` is a bool once YAML has read it. Everything else in this repo is anexpression, and an expression is the case worth evaluating: the whole of@@ -129,7 +140,7 @@ def _cancels(value, *, ref: str) -> bool:if not match:raise Unparsed(text)body = match.group(1).strip()- context = _context(ref)+ context = _context(ref, event_name)ternary = _TERNARY.fullmatch(body)if ternary:taken = ternary.group(2) if _condition(ternary.group(1), context) else ternary.group(3)@@ -201,7 +212,7 @@ def test_every_pull_request_workflow_cancels_the_superseded_run():assert not offenders, (f"{offenders} do not cancel in progress on a pull request ref, so a push that "f"supersedes a RUNNING job leaves it holding its runners to completion. Either set "- f"cancel-in-progress: ${{{{ github.ref != 'refs/heads/main' }}}}, or add the file to "+ f"cancel-in-progress: ${{{{ github.event_name == 'pull_request' }}}}, or add the file to "f"EXEMPT in {Path(__file__).name} with the reason it must not be cancelled.")@@ -221,13 +232,64 @@ def test_cancelling_is_still_gated_off_main():if not (isinstance(push, dict) and "main" in (push.get("branches") or [])):continuetry:- if _cancels(_cancel_setting(document), ref = MAIN):+ if _cancels(_cancel_setting(document), ref = MAIN, event_name = "push"):offenders[name] = _cancel_setting(document)except Unparsed:continueassert not offenders, (f"{offenders} also run on pushes to main and cancel in progress there, so a merge "- f"burst kills the main run mid-flight. Gate it on github.ref != 'refs/heads/main'."+ f"burst kills the main run mid-flight. Gate it on github.event_name == 'pull_request'."+ )+++# Where each non-pull-request trigger can run. schedule and repository_dispatch always run on+# the default branch. workflow_dispatch runs on whatever ref the person picked, a tag included.+# push is taken from the workflow's own branch filter.+_DISPATCH_REFS = ("refs/heads/main", "refs/heads/a-feature-branch", "refs/tags/v2026.9.1")+_DEFAULT_BRANCH_ONLY = ("schedule", "repository_dispatch")+++def _non_pull_request_runs(triggers: dict):+ for event in _DEFAULT_BRANCH_ONLY:+ if event in triggers:+ yield event, MAIN+ if "workflow_dispatch" in triggers:+ for ref in _DISPATCH_REFS:+ yield "workflow_dispatch", ref+ push = triggers.get("push")+ if "push" in triggers:+ branches = (push or {}).get("branches") if isinstance(push, dict) else None+ tags = (push or {}).get("tags") if isinstance(push, dict) else None+ for branch in branches or ["main", "a-feature-branch"]:+ yield "push", f"refs/heads/{branch}"+ for tag in tags or []:+ yield "push", f"refs/tags/{tag}"+++def test_only_a_superseded_pull_request_run_is_cancelled():+ """The converse of the rule above: nothing a person or a clock started is killed.++ A push to main, a nightly, and a manual dispatch are each the only run of their kind that+ somebody is waiting on. ``github.ref != 'refs/heads/main'`` kept main pushes alive but was+ still truthy for a dispatch on a branch or a tag, and a literal ``true`` also cancelled a+ running nightly when someone dispatched the same workflow on main. Rendered per trigger and+ per ref the trigger can actually run on.+ """+ offenders = {}+ for name, document in _scanned().items():+ triggers = document.get(True) or document.get("on") or {}+ if not isinstance(triggers, dict):+ continue+ try:+ for event, ref in _non_pull_request_runs(triggers):+ if _cancels(_cancel_setting(document), ref = ref, event_name = event):+ offenders.setdefault(name, []).append(f"{event}@{ref}")+ except Unparsed:+ continue # Reported by test_every_cancel_expression_is_understood.+ assert not offenders, (+ f"{offenders} cancel a running job that is not a superseded pull request push. Use "+ f"cancel-in-progress: ${{{{ github.event_name == 'pull_request' }}}} so pushes to main, "+ f"schedules and dispatches always run to completion.")@@ -266,6 +328,16 @@ def test_the_evaluator_reads_the_direction_of_the_comparison():assert not _cancels(False, ref = A_PULL_REQUEST)assert not _cancels(None, ref = A_PULL_REQUEST), "absent means false, which is the default"+ # Keyed on the event: true for a pull request on any ref, false for everything else,+ # main included.+ by_event = "${{ github.event_name == 'pull_request' }}"+ assert _cancels(by_event, ref = A_PULL_REQUEST)+ assert not _cancels(by_event, ref = MAIN, event_name = "push")+ assert not _cancels(by_event, ref = "refs/heads/a-feature-branch", event_name = "workflow_dispatch")+ assert not _cancels(by_event, ref = MAIN, event_name = "schedule")+ # ... which the ref-keyed form gets wrong for a dispatch off main.+ assert _cancels(gated, ref = "refs/heads/a-feature-branch", event_name = "workflow_dispatch")+# The ternary form, which renders to a string rather than to a bool.ternary = "${{ github.ref == 'refs/heads/main' && 'false' || 'true' }}"assert _cancels(ternary, ref = A_PULL_REQUEST)