Repository navigation
fix(ci): stop the release-neutral guard cancelling itself on label events - #1706
Conversation
Three red assertions for #1698: - the concurrency group keys label events on `github.run_id` and everything else on a constant, so a `labeled` event can no longer cancel the run a `synchronize` started; - `ACTIVE` gates the two label actions on `github.event.label.name`, while still reading the label SET from the pull request so an `unlabeled` event removing the lane label deactivates; - gate 6 carries a verdict marker and upserts by it, rather than appending a fresh comment on every rerun. A fourth test pins `cancel-in-progress: true` as a literal, documenting the rejected single-lane alternative: `cancel-in-progress: false` QUEUES behind the in-flight run rather than running beside it, so a label event would wait out a 90-minute vulnix extra — and the label event is exactly the one whose verdict must not be stale. Refs: #1698
…ents The guard triggers on `labeled`/`unlabeled` as well as the code events, and carried one `cancel-in-progress` concurrency lane per PR, undiscriminated by event. Every label event therefore cancelled whatever guard run was in flight — including the `opened`/`synchronize` run the label had nothing to do with. `gh pr create --label a --label b` emits two `labeled` events within a second, so a PR opened with two labels left `cancelled` guard runs on its head beside the eventual success, and GitHub never resolves a required context to its latest check run. Three changes: - the concurrency group keys label events on `github.run_id` and everything else on a constant `code`, so label events are mutually independent while code events still supersede each other; - `env.ACTIVE` scopes the two label actions to the lane's own label, making an unrelated relabel a cheap all-steps-skipped SUCCESS instead of a full gate run in its own fresh lane. The label set is still read from the pull request, so an `unlabeled` event removing `release-neutral` deactivates correctly; - gate 6 upserts one sticky verdict comment, matched by an HTML marker, rather than appending a fresh one per run — two label runs may now both reach it, and a thread of stale verdicts names files and a changelog diff that no longer exist. Matched by marker, not `gh pr comment --edit-last`, which edits the acting identity's last comment and may hijack another workflow's. The header's shape rules gain a third entry, since the file is the reference workflow consumers copy, and `docs/RELEASE_CYCLE.md`'s gate-6 row now says the verdict is sticky. Refs: #1698
Two review findings on #1698's own fix, red first: - the scope report still has two branches, so an unrelated relabel on a labelled PR reports "no `release-neutral` label" — the opposite of the truth. A `LABELLED` job env makes the middle state expressible; - per-run label lanes mean concurrent ACTIVE runs are neither cancelled nor cancelling, so the opener's `opened` + 2x`labeled` flow can leave three runs racing the marker lookup and three marked comments, of which only the newest is ever patched again. Gate 6 must prune every marked comment but the newest after upserting. Also pins the jq marker reaching the filter through `env.MARKER` rather than a shell-escaped interpolation. Refs: #1698
Two review findings on the #1698 fix itself. The scope report had two branches, so an unrelated label event on a PR that does carry `release-neutral` reported "no `release-neutral` label" — the opposite of the truth, and an invitation to add a label already there. A `LABELLED` job env holds the label set alone (`ACTIVE` folds in the event and loses the distinction), and the report now names the middle state: labelled, but this run was not started by that label. Per-run label lanes mean concurrent ACTIVE runs neither cancel nor are cancelled, and the opener's own flow — `opened` plus the two `labeled` events GitHub emits for one `gh pr create --label` — makes three concurrent ACTIVE runs the normal case. Each raced the marker lookup, found nothing and created its own comment; the upsert alone left two or three marked comments and only ever patched the newest. Gate 6 now re-lists after upserting and deletes every marked comment but the newest, so whichever run finishes last leaves exactly one verdict. `pull-requests: write` already covers the delete. The cost is now stated where the decision is: label runs duplicate the gates rather than superseding them, affordable because they are eval-only seconds (only a `.vulnixignore` PR pays the vulnix extra per run), and accepted in exchange for never leaving a cancelled run. Alternatives based on cancellation reintroduce exactly what this issue exists to remove. Also hardens the lookup: the marker reaches jq through `env.MARKER` instead of a shell-escaped interpolation, the listing is an explicit `--method GET` with `per_page=100`, and a `null` comment body no longer breaks the filter. Refs: #1698
VerificationCI run on this PR: all 15 checks green, What is verified statically: the concurrency group keys What cannot be verified here: the guard triggers only on pull requests to |
Description
release-neutral-guard.ymltriggers onlabeled/unlabeledas well as the codeevents, and carried one
cancel-in-progressconcurrency lane per pullrequest, undiscriminated by event. Every label event therefore cancelled whatever
guard run was in flight — including the
opened/synchronizerun the label hadnothing to do with.
gh pr create --label a --label bemits twolabeledeventswithin a second, so a pull request opened with two labels left
cancelledguardruns on its head beside the eventual success (run history on the last PR to
mainshows two cancelled runs stamped within the same second).The cost today is a red cancelled run, a stale verdict comment and a wasted
runner start per label event — this guard is not a required check. But GitHub
never resolves a required context to its latest check run, so a single
cancelledrun of a required name keeps a PR's status rollup red however manysuccesses land after it. The split is what keeps promoting this guard safe, and
this file is the reference workflow other repositories copy.
Type of Change
feat-- New featurefix-- Bug fixdocs-- Documentation onlychore-- Maintenance task (deps, config, etc.)refactor-- Code restructuring (no behavior change)test-- Adding or updating testsci-- CI/CD pipeline changesbuild-- Build system or dependency changesrevert-- Reverts a previous commitstyle-- Code style (formatting, whitespace)Modifiers
!) -- This change breaks backward compatibilityChanges Made
1. Two concurrency lanes per PR, split by event kind.
Code events (
opened,reopened,synchronize) share thecodelane and stillsupersede each other — only the newest head matters. Label events are keyed on
github.run_id, so they neither cancel nor are cancelled.Rejected alternative, documented in the file and pinned by a test: one lane
with
cancel-in-progress: ${{ github.event.action == 'synchronize' }}. Acancel-in-progress: falserun queues behind the in-flight run rather thanrunning beside it, so a label event would wait out an in-flight 90-minute vulnix
extra — and the label event is exactly the one whose verdict must not be stale.
The cost, stated plainly (see Additional Notes): label runs no longer
supersede each other, so a burst of activating label events runs the gates more
than once, concurrently.
2. The label-name gate folded into
env.ACTIVE.An unrelated relabel (
area:ci, a priority pass) now starts a run in its ownfresh lane, where it would pay for a full gate run. Scoping the two label actions
to the lane's own label makes it a cheap all-steps-skipped SUCCESS instead —
never a
cancelledrun. The label set is still read fromgithub.event.pull_request.labels, not fromgithub.event.label, so anunlabeledevent removingrelease-neutraldeactivates the gates correctly; the!=clauses are what letopened/synchronize(which carry nogithub.event.label) through. Theguardjob still carries no job-levelif— shape rule 1 is untouched.3. The scope report gained its missing third state.
With the label-name gate, "inactive" no longer implies "unlabelled": an unrelated
relabel is inactive on a PR that does carry the lane label, where the old
two-branch report announced "no
release-neutrallabel" — the opposite of thetruth, and an invitation to add a label already there. A
LABELLEDjob env holdsthe label set alone (
ACTIVEfolds in the event and loses the distinction), andthe report now branches three ways: active; labelled but this event is not about
it; no label at all.
4. Gate 6's verdict is one sticky comment, and it converges.
Several ACTIVE runs can now reach gate 6 at once, each finding no marker and each
creating its own comment. So the step does two things:
<!-- release-neutral-guard:verdict -->; the steplists the PR's comments, filters on the marker and
PATCHes the newest match,falling back to
gh pr commentwhen there is none. Deliberately notgh pr comment --edit-last, which edits the acting identity's last comment andfor
github-actions[bot]may hijack an unrelated workflow's. The marker isappended after the step summary is written, so the summary stays clean.
DELETEs all but the newest. However many concurrent runs posted a verdict,the last one to finish leaves exactly one.
pull-requests: write— which gate6 already held — covers the delete.
The marker reaches jq through
env.MARKERrather than a shell-escapedinterpolation, the listing is an explicit
--method GETwithper_page=100, and(.body // "")keeps anullcomment body from breaking the filter.5. Documentation. The workflow header's shape rules gain a third entry and the
concurrency block states the duplicate-run trade honestly (the file is copied by
consumers, so it stays self-explaining);
docs/RELEASE_CYCLE.md's gate-6 row nowsays the verdict is sticky.
Changelog Entry
Fixed
event (#1698)
release-neutral-guard.ymltriggers onlabeled/unlabeledas well as thecode events, and carried one
cancel-in-progressconcurrency lane per pullrequest, undiscriminated by event. Every label event cancelled whatever run
was in flight, including the
opened/synchronizerun the label had nothingto do with;
gh pr create --label a --label bemits twolabeledeventswithin a second, so a pull request opened with two labels left
cancelledguard runs on its head beside the eventual success.
github.run_id, while code events keep superseding each other. Not a singlelane with a conditional
cancel-in-progress:falsequeues a label eventbehind the in-flight run — up to a 90-minute vulnix extra — and the label
event is precisely the one whose verdict must not be stale.
activating label events runs the gates more than once, concurrently, instead
of superseding — three concurrent runs is the normal case, since the opener
emits
openedplus the twolabeledevents GitHub sends for onegh pr create --label. Affordable because the gates are eval-only seconds;only a pull request touching
.vulnixignorepays the vulnix extra per run.Accepted in exchange for never leaving a
cancelledrun behind, which everycancellation-based alternative reintroduces.
env.ACTIVEadditionally scopes the label actions to the lane's ownrelease-neutrallabel, so an unrelated relabel is a cheapall-steps-skipped success rather than a full gate run in a fresh lane. The
label set is still read from the pull request, so an
unlabeledeventremoving the lane label deactivates the gates as before.
patched in place, instead of a fresh comment per run — a stale verdict names
files and a changelog diff that no longer exist. It also converges: after
upserting, the step deletes every marked comment but the newest, so however
many concurrent runs posted one, the last to finish leaves exactly one
verdict.
relabel for something else is inactive on a pull request that does carry
the lane label, where the old two-branch report claimed there was no
release-neutrallabel at all.Testing
just test)just testis left unticked: it includestest_image.py/test_integration.py, which need a freshly built image and fail off a stale local:devimage. What ran ispytest tests/with those two excluded (1149 passed, 1 skipped) plus the workflow-shape suite, below.Manual Testing Details
TDD throughout. Two red-then-green rounds in
tests/test_workflow_release_neutral.py:Two further tests are regression pins rather than new behaviour:
cancel-in-progress: truemust stay a literal (so the rejected single-lanealternative cannot return quietly), and the prune must run after the upsert and
keep the newest id (a prune with no exception would delete the verdict itself).
Full suite and linters:
Gate 6's shell was exercised locally against a stub
ghunderset -euo pipefail, since the interesting part is the control flow rather thanthe API:
The jq filter was checked separately: it selects every marked id in page order,
tolerates a
nullbody, and returns nothing (no error) for an unmarked or emptypage.
Left for the reviewer (needs a real PR to
main, which only the lane canopen): the issue's acceptance check — a pull request created with two labels shows
zero
cancelledguard runs on its head; a relabel produces asuccessrunwith every gate step skipped and the new middle scope message; and the verdict
converges to a single comment after the concurrent opener runs finish.
Checklist
docs/templates/, then runjust docs)CHANGELOG.mdin the[Unreleased]section (and pasted the entry above)Additional Notes
Targets
dev, so it reachesmainwith the next train rather than throughthe release-neutral lane it fixes.
The trade-off, explicitly. Per-run label lanes mean label runs neither cancel
nor are cancelled, so activating label events no longer supersede each other: the
opener's normal flow (
openedplus the twolabeledevents GitHub emits for onegh pr create --label release-neutral) leaves three concurrent ACTIVE runs,not one. This is accepted, not overlooked:
exception is a PR touching
.vulnixignore, which pays the vulnix extra onceper run;
exists to remove. Queueing (
cancel-in-progress: false) is worse still: thelabel event would wait out the in-flight run it is meant to correct.
Scope: nothing left to sweep.
grep -rn labeled .github/workflows assets/returns only this workflow's own trigger and comments (plus unrelated prose in
assets/smoke-test/README.mdand changelog history). This guard is the onlyworkflow in the repo or the consumer scaffold with a
labeled/unlabeledtrigger, so the defect class has exactly one instance and it is fixed here.
Follow-up candidate, deliberately not fixed here (reviewer's observation):
gate 6 has no
if: always(), so when gate 2 or the vulnix extra fails, theverdict step is skipped and the last positive verdict comment stays standing
on the PR — now more prominently, since it is sticky rather than buried under
later comments. A reviewer reading the comment would see a pass the current run
did not grant. Worth its own issue: the fix is a gate-6 that always runs and
writes a refusal verdict, which changes what the comment means and needs its own
tests. Out of scope for #1698.
Refs: #1698