Skip to content

fix(ci): stop the release-neutral guard cancelling itself on label events - #1706

Merged
c-vigo merged 7 commits into
devfrom
bugfix/1698-guard-label-concurrency
Sep 25, 2026
Merged

c-vigo merged 7 commits into
devfrom
bugfix/1698-guard-label-concurrency

Conversation

@c-vigo

@c-vigo c-vigo commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Description

release-neutral-guard.yml triggers on labeled/unlabeled as well as the code
events, and carried one cancel-in-progress concurrency lane per pull
request, 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 pull request opened with two labels left cancelled guard
runs on its head beside the eventual success (run history on the last PR to
main shows 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
cancelled run of a required name keeps a PR's status rollup red however many
successes 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 feature
  • fix -- Bug fix
  • docs -- Documentation only
  • chore -- Maintenance task (deps, config, etc.)
  • refactor -- Code restructuring (no behavior change)
  • test -- Adding or updating tests
  • ci -- CI/CD pipeline changes
  • build -- Build system or dependency changes
  • revert -- Reverts a previous commit
  • style -- Code style (formatting, whitespace)

Modifiers

  • Breaking change (!) -- This change breaks backward compatibility

Changes Made

1. Two concurrency lanes per PR, split by event kind.

concurrency:
  group: >-
    release-neutral-guard-${{ github.event.pull_request.number }}-${{
    (github.event.action == 'labeled' || github.event.action == 'unlabeled')
    && github.run_id || 'code' }}
  cancel-in-progress: true

Code events (opened, reopened, synchronize) share the code lane and still
supersede 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' }}. A
cancel-in-progress: false run queues behind the in-flight run rather than
running 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 own
fresh 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 cancelled run. The label set is still read from
github.event.pull_request.labels, not from github.event.label, so an
unlabeled event removing release-neutral deactivates the gates correctly; the
!= clauses are what let opened/synchronize (which carry no
github.event.label) through. The guard job still carries no job-level
if — 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-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 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:

  • Upsert. The body carries <!-- release-neutral-guard:verdict -->; the step
    lists the PR's comments, filters on the marker and PATCHes the newest match,
    falling back to gh pr comment when there is none. Deliberately not
    gh pr comment --edit-last, which edits the acting identity's last comment and
    for github-actions[bot] may hijack an unrelated workflow's. The marker is
    appended after the step summary is written, so the summary stays clean.
  • Converge. After upserting, the step re-lists the marked comments and
    DELETEs all but the newest. However many concurrent runs posted a verdict,
    the last one to finish leaves exactly one. pull-requests: write — which gate
    6 already held — covers the delete.

The marker reaches jq through env.MARKER rather than a shell-escaped
interpolation, the listing is an explicit --method GET with per_page=100, and
(.body // "") keeps a null comment 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 now
says the verdict is sticky.

Changelog Entry

Fixed

  • The release-neutral guard no longer cancels its own in-flight run on a label
    event
    (#1698)
    • release-neutral-guard.yml triggers on labeled/unlabeled as well as the
      code events, and carried one cancel-in-progress concurrency lane per pull
      request, undiscriminated by event. Every label event cancelled whatever 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 pull request opened with two labels left cancelled
      guard runs on its head beside the eventual success.
    • Label events now get a concurrency lane of their own, keyed on
      github.run_id, while code events keep superseding each other. Not a single
      lane with a conditional cancel-in-progress: false queues a label event
      behind 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.
    • The trade: label runs neither cancel nor are cancelled, so a burst of
      activating label events runs the gates more than once, concurrently, instead
      of superseding — three concurrent runs is the normal case, since the opener
      emits opened plus the two labeled events GitHub sends for one
      gh pr create --label. Affordable because the gates are eval-only seconds;
      only a pull request touching .vulnixignore pays the vulnix extra per run.
      Accepted in exchange for never leaving a cancelled run behind, which every
      cancellation-based alternative reintroduces.
    • env.ACTIVE additionally scopes the label actions to the lane's own
      release-neutral label, so an unrelated relabel is a cheap
      all-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 unlabeled event
      removing the lane label deactivates the gates as before.
    • The gate-6 verdict is now one sticky comment, found by an HTML marker and
      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.
    • The scope report gained its missing third state. With the label-name gate, a
      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-neutral label at all.

Testing

  • Tests pass locally (just test)
  • Manual testing performed (describe below)

just test is left unticked: it includes test_image.py / test_integration.py, which need a freshly built image and fail off a stale local :dev image. What ran is pytest 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:

uv run pytest tests/test_workflow_release_neutral.py -q
  round 1 (lane split, label-name gate, sticky verdict)
    before: 3 failed, 30 passed      after: 33 passed
  round 2 (three-way scope report, verdict convergence, env.MARKER)
    before: 3 failed, 32 passed      after: 35 passed

Two further tests are regression pins rather than new behaviour:
cancel-in-progress: true must stay a literal (so the rejected single-lane
alternative 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:

uv run pytest tests/ -q --ignore=tests/test_image.py --ignore=tests/test_integration.py
  -> 1149 passed, 1 skipped          (image/integration excluded: they fail
                                      locally against a lagging :dev image)
actionlint .github/workflows/release-neutral-guard.yml           -> clean
actionlint -shellcheck=shellcheck  (same file)                   -> clean
zizmor --offline .github/workflows/release-neutral-guard.yml      -> No findings
prek run --all-files                                             -> all hooks pass

Gate 6's shell was exercised locally against a stub gh under
set -euo pipefail, since the interesting part is the control flow rather than
the API:

Marked comments present Result
none creates one, prunes nothing, exit 0
one patches it in place, prunes nothing, exit 0
three (the concurrent-run case) patches the newest, deletes the other two, exit 0

The jq filter was checked separately: it selects every marked id in page order,
tolerates a null body, and returns nothing (no error) for an unmarked or empty
page.

Left for the reviewer (needs a real PR to main, which only the lane can
open): the issue's acceptance check — a pull request created with two labels shows
zero cancelled guard runs on its head; a relabel produces a success run
with 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

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (edit docs/templates/, then run just docs)
  • I have updated CHANGELOG.md in the [Unreleased] section (and pasted the entry above)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

Targets dev, so it reaches main with the next train rather than through
the 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 (opened plus the two labeled events GitHub emits for one
gh pr create --label release-neutral) leaves three concurrent ACTIVE runs,
not one. This is accepted, not overlooked:

  • the gates are eval-only seconds, so the duplicated work is cheap. The single
    exception is a PR touching .vulnixignore, which pays the vulnix extra once
    per run;
  • the visible duplication was gate 6's, and gate 6 now converges on one comment;
  • every alternative is cancellation-based, and cancellation is what this issue
    exists to remove. Queueing (cancel-in-progress: false) is worse still: the
    label 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.md and changelog history). This guard is the only
workflow in the repo or the consumer scaffold with a labeled/unlabeled
trigger, 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, the
verdict 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

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
@c-vigo c-vigo self-assigned this Sep 25, 2026
@c-vigo

c-vigo commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

Verification

CI run on this PR: all 15 checks green, Test Summary passed. actionlint and zizmor --offline clean on the changed workflow; tests/test_workflow_release_neutral.py 35 passed (3 RED-first tests in each of the two rounds, verified failing before their fix commits); prek run --all-files green after merging dev.

What is verified statically: the concurrency group keys labeled/unlabeled on the run id and everything else on code; ACTIVE requires the moving label to be release-neutral for label events while still reading the label set from the PR; the scope report distinguishes "labelled but this event was not about the lane"; gate 6 upserts one marker-based verdict and prunes every marked comment but the newest (control flow exercised locally against a stub gh for 0, 1 and 3 existing comments).

What cannot be verified here: the guard triggers only on pull requests to main, and this PR targets dev. The live acceptance check from #1698 (a PR opened with two labels shows zero cancelled guard runs; an unrelated relabel yields a skipped-steps success; concurrent opener runs converge to one verdict comment) happens on the first release-neutral lane PR after the next train carries this to main. Reviewer follow-up about gate 6 lacking always() is filed as #1705.

@c-vigo
c-vigo merged commit 9e2cea2 into dev Sep 25, 2026
15 checks passed
@c-vigo
c-vigo deleted the bugfix/1698-guard-label-concurrency branch September 25, 2026 09:52
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