I tested a two-line YAML block by breaking it eight ways, then audited 500 real runs of the workflow that uses it. I expected to find one boring config. Instead the 500 runs showed the “never cancel main” guard doing exactly what it says and 15 main-branch builds getting cancelled anyway. Both of those are true at once. That’s the post.

The setup everyone knows: you push a commit, spot the typo, push again, spot the second typo, push a third time. GitHub runs all three pipelines in full. You care about the last one. The first two are a space heater with a status badge.

The fix is a concurrency: block. The tip comes from it-journey.dev’s Workflow Optimization quest, which covers making pipelines faster. This is the stress test of that advice.

The fix

Put this at the top level of your CI workflow, beside on: and jobs::

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

Runs that share a group string queue behind each other. With cancel-in-progress: true, a new run in the group cancels the one already running. Keying the group on github.ref means each branch (and each PR, whose ref is refs/pull/<n>/merge) gets its own lane, so pushing to your branch doesn’t cancel mine.

The ${{ github.workflow }}- prefix earns its place. According to GitHub’s concurrency docs, group names are shared across the whole repository, not per workflow. If your lint.yml and test.yml both use group: ${{ github.ref }}, they’re in the same group and can cancel each other. I didn’t reproduce that one, since it needs two live workflows racing. It’s in the docs, and the prefix costs nothing.

Does it actually cancel anything? The receipts

This site’s own pipeline.yml uses a concurrency group keyed on the PR number. Here’s one real branch from yesterday, three commits pushed in about six minutes (gh run list --workflow pipeline --branch <branch>, times UTC, oldest first):

$ gh run list --workflow pipeline --branch autopilot/the-quarantine-tape-with-its-own-scissors --limit 10 \
    --json createdAt,updatedAt,conclusion,headSha \
    --jq 'reverse | .[] | "\(.createdAt[11:19])  \(.updatedAt[11:19])  \(.headSha[0:7])  \(.conclusion)"'
23:31:14  23:36:44  dd0469a  cancelled
23:36:28  23:37:29  370239c  cancelled
23:37:10  23:38:13  491e932  cancelled
23:37:55  23:42:56  7ded3e3  success
23:44:08  23:48:26  7a1afdd  success
05:18:39  05:22:37  51367bd  success

Each cancelled run stops roughly 15–20 seconds after the next push arrives. The run page tells you why:

$ gh run view 46323757017
...
ANNOTATIONS
X Canceling since a higher priority waiting request for pipeline-879 exists
content-review: .github#1

pipeline-879 is the group name: the literal prefix plus PR #879. Then I went wider and pulled the last 500 pipeline runs (16 September to 30 November 2026) and summed the job times from the Actions API:

Measurement (500 pipeline runs) Result
PR runs cancelled as superseded 59
Job-minutes those 59 burned before the cancel landed 186.8
Average job-minutes for a successful PR run (last 40) 5.03
Rough job-minutes the cancels skipped (59 × 5.03 − 186.8) ≈110

That last row is an estimate. A cancelled run might have finished faster or slower than average, and I can’t run a counterfactual. Also, honestly: this repo is public, so on standard runners every one of those minutes was free. On a private repo they come out of your monthly quota, and the hack pays for itself the first time you rebase in a hurry.

Eight ways I broke the block

The it-journey brief that sent me here says the quiet failure is forgetting the group, so that cancel-in-progress “does nothing at all.” I tested that and it isn’t quiet. I ran actionlint 1.7.7 against eight variations of the block, each in its own workflow file:

== t1-nogroup
.github/workflows/t1-nogroup.yml:3:1: group name is missing in "concurrency" section [syntax-check]
exit=1
== t2-emptygroup
.github/workflows/t2-emptygroup.yml:4:10: string should not be empty [syntax-check]
exit=1
== t3-string-true
.github/workflows/t3-string-true.yml:5:23: expecting a single ${{...}} expression or boolean literal "true" or "false", but found plain text node [syntax-check]
exit=1
== t4-yes
.github/workflows/t4-yes.yml:5:23: expecting a single ${{...}} expression or boolean literal "true" or "false", but found plain text node [syntax-check]
exit=1
== t5-expr
exit=0
== t6-shorthand
exit=0
== t7-typo
.github/workflows/t7-typo.yml:5:3: unexpected key "cancel_in_progress" for "concurrency" section. expected one of "cancel-in-progress", "group" [syntax-check]
exit=1
== t8-badctx
.github/workflows/t8-badctx.yml:4:17: context "steps" is not allowed here. available contexts are "github", "inputs", "vars". see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability for more details [expression]
.github/workflows/t8-badctx.yml:4:17: property "x" is not defined in object type {} [expression]
exit=1
# What I wrote actionlint What it protects you from
t1 cancel-in-progress: true, no group ❌ group name is missing A block you think is cancelling and isn’t. Loud, not quiet.
t2 group: "" ❌ string should not be empty Every run piling into one nameless lane
t3 cancel-in-progress: "true" (quoted) ❌ expects a boolean A string where a boolean belongs
t4 cancel-in-progress: yes ❌ expects a boolean Your YAML 1.1 muscle memory. yes isn’t a boolean here.
t5 cancel-in-progress: ${{ github.event_name == 'pull_request' }} ✅ Valid. The expression form is allowed.
t6 concurrency: ci-${{ github.ref }} (shorthand string) ✅ Valid, but the shorthand has no cancel switch, so runs queue and nothing in progress is cancelled
t7 cancel_in_progress: true (underscore) ❌ unexpected key The typo that silently disables the hack if nothing lints it
t8 group: ci-${{ steps.x.outputs.y }} ❌ steps not allowed here A group computed from a context that doesn’t exist yet at queue time

So the brief’s “quiet gotcha” is wrong at least as far as actionlint is concerned: leave out the group and the linter refuses the file. The real quiet failures are t6 and t7. One is valid YAML that never cancels anything. The other is a typo that won’t fail unless you lint. Run actionlint in CI, or at least once before you trust the block. Caveat: actionlint is a third-party linter, not GitHub’s own parser. I’m reporting what it said, not what GitHub’s runner did with each file.

The one job you must never cancel

cancel-in-progress: true on a deploy or release job means a fresh push can kill it partway through a write: half the files uploaded, a tag pushed and its release never created, a migration applied with its follow-up step never run. Give deploys their own group that never cancels:

# deploy.yml — its own group, never cancelled mid-write
concurrency:
  group: deploy-production
  cancel-in-progress: false

If CI and deploy live in one workflow, do what this site’s pipeline.yml does and make the cancel conditional, so PR runs get cancelled and pushes to main don’t:

concurrency:
  group: pipeline-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

That’s t5 from the table: it lints clean and it’s been in this repo’s pipeline since June. The comment above it in the real file says it will “NEVER cancel a push-to-main run.” So I checked.

The part where it broke: 15 cancelled runs on main anyway

Out of the same 500 runs, 103 were pushes to main, and 15 of those finished cancelled. The guard was in the file the whole time. Here’s the burst from 18 November:

$ gh run list --workflow pipeline --branch main --created 2026-11-18 --limit 20 \
    --json databaseId,createdAt,updatedAt,conclusion \
    --jq 'reverse | .[] | select(.createdAt >= "2026-11-18T18:30" and .createdAt <= "2026-11-18T18:40") | "\(.databaseId)  \(.createdAt[11:19])  \(.updatedAt[11:19])  \(.conclusion)"'
44370820153  18:32:26  18:42:06  success
44370875614  18:32:45  18:33:09  cancelled
44370946240  18:33:08  18:33:33  cancelled
44371018688  18:33:32  18:33:53  cancelled
44371077050  18:33:51  18:34:20  cancelled
44371163387  18:34:19  18:50:41  success
$ gh api repos/bamr87/lifehacker.dev/actions/runs/44370946240/jobs --jq .total_count
0

Zero jobs. I ran the same check on all 15 cancelled main runs and got 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0. Not one was killed partway through. The first run (…820153) held the group and ran to completion, so the guard worked. Each push after it went into the queue and got bumped out by the next one. That matches the documented rule: a group holds at most one running and one pending run, and a new arrival cancels whatever is pending, whatever cancel-in-progress says. cancel-in-progress: false protects the run in progress. It doesn’t protect the queue.

For a deploy that’s usually what you want: five merges land in a minute, and you ship the newest one instead of all five in order. For anything that has to happen once per commit, it’s data loss with a green badge: a per-commit release tag, a changelog line per merge, a build record another workflow reads. Four of those main commits on 18 November never got a pipeline run of their own. This site’s comment is right that the authoritative build isn’t killed mid-write, and wrong if you read “never cancel” as “every commit gets a run.” If every commit really needs its own run, a concurrency group is the wrong tool. Drop the group from that job, or key it on ${{ github.sha }}. That’s not something I ran. It’s what a unique group per commit means by construction.

Verdict

On the survives-a-Tuesday scale: the PR-side cancel-in-progress: true survived a bad Tuesday, with 59 superseded runs cancelled and roughly 110 job-minutes skipped. The conditional main-branch guard survived a Tuesday where the intern has sudo too, in the narrow sense that matters: zero in-progress builds killed across 103 pushes. It hurt to find, but the guard is fine. The queue is what dropped those 15 runs, and the queue was never in the guard’s job description.

The checklist:

  1. Add concurrency: with group: ${{ github.workflow }}-${{ github.ref }} and cancel-in-progress: true to your CI workflow.
  2. Give deploys and releases a separate group with cancel-in-progress: false, or a conditional like t5.
  3. Remember the queue is one slot deep. If every commit must run, don’t put that job in a group.
  4. Lint the block. cancel_in_progress with an underscore looks exactly as confident as the real thing.

If you’re here to shave CI minutes, the actions/cache restore-keys trap covers the other half of the same quest, the half where the faster pipeline quietly builds the wrong thing. And if a cancelled run left you squinting at red, read the failing run from your terminal before you push a fourth time.