GitHub Actions concurrency: cancel-in-progress, queue and groups
Cancel superseded runs with cancel-in-progress, serialize deploys, and queue up to 100 pending runs with queue: max. Concurrency group keys and gotchas.
In this series26 guides, you're on Concurrency
You push a commit to your pull request, spot a typo, and push again ten seconds later. GitHub happily starts a brand new workflow run for the second push — while the first one is still churning through your test suite. Do that three or four times while iterating on a PR and you’ve got a stack of runs grinding away on code nobody cares about anymore, each one burning real CI minutes.
The concurrency ↗ keyword fixes this. It lets you group runs together and tell GitHub what to do when a new one shows up: cancel the stale one, wait behind it, or (since May 2026) queue up to 100 runs with queue: max. Used well, it cuts wasted compute on PRs and protects your production deploys from getting killed mid-flight. Here are its three keys at a glance before we dig in:
| Key | What it does | Default |
|---|---|---|
group | Runs and jobs whose group resolves to the same string run one at a time. A string or an expression; case-insensitive. | Required |
cancel-in-progress | true cancels the one in progress when a new run or job joins the group. Can be an expression. | false: the one in progress finishes, and the new one waits as pending |
queue | max lets up to 100 pending runs wait their turn, instead of one. Can’t be combined with cancel-in-progress: true. Since May 2026; not on GitHub Enterprise Server. | single: one pending run at most, replaced by a newer one |
The problem: redundant runs pile up#
By default, every triggering event starts its own independent workflow run, and GitHub runs them in parallel. That’s usually what you want — but not for the rapid back-and-forth of an active pull request. Each force-push, each fixup commit, each rebase fires another pull_request event, and the previous run keeps going even though its results are already obsolete.
If your CI takes 15 minutes and you push 5 times in quick succession, you’ve potentially paid for 75 minutes of compute to learn about exactly one commit. The concurrency keyword lets you say “only one run per branch matters at a time — cancel the rest.”
Workflow-level concurrency#
Add a concurrency block at the top level of your workflow. It takes a group (a string that identifies which runs belong together) and two optional keys: cancel-in-progress and, since May 2026, queue (see below). A plain string such as concurrency: production is shorthand for group: production with the defaults.
name: CI
on: pull_request:
concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true
jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - run: echo "Running tests..."Any two runs that resolve to the same group string are treated as one concurrency group, and only one run per group executes at a time. With cancel-in-progress: true, the moment a new run enters the group, the in-progress run for that group is cancelled and the new one takes over.
Understanding the group key#
The group is just a string, so the magic is entirely in how you build it. A common, sensible default is:
concurrency: group: ${{ github.workflow }}-${{ github.ref }}github.workflowis the workflow’sname:(or its file path when it has none). It keeps each workflow in its own bucket, so your “CI” runs don’t cancel your “Lint” runs, as long as no two workflows share a name.github.refscopes the group to a single branch or PR ref (for examplerefs/pull/42/mergefor a PR, orrefs/heads/mainfor a push to main).
Together they mean: “at most one CI run per branch.” Push twice to the same PR and the second push cancels the first. Push to a different branch and nothing gets cancelled, because the group string is different. If the workflow also runs on pushes to main, though, each merge cancels the previous merge’s run if it’s still going, which you rarely want on your default branch. The run_id fallback below lets every push to main run to completion.
Why the run_id fallback matters#
You’ll often see a more defensive variant of the group key:
concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: trueHere’s the subtle part. github.head_ref is only set for pull_request and pull_request_target events — it’s the source branch of the PR. For other events (a direct push to main, a workflow_dispatch, a tag push), head_ref is empty.
If the key were ${{ github.workflow }}-${{ github.head_ref }} with no fallback, every push to main would resolve to the same group (CI- in a workflow named CI) and start cancelling each other. That’s almost never what you want: each merge to main is a distinct, meaningful event, and you don’t want commit B’s run to murder commit A’s run just because they share the CI- key.
The || github.run_id fallback solves this. Because github.run_id is unique to every single run, any event that isn’t a PR gets its own private group of one — so it can never be cancelled by a sibling. PRs still group by branch (and cancel redundant runs), while pushes and dispatches run to completion. Best of both worlds.
One catch: head_ref is only the branch name, without the fork’s owner. If your repository takes pull requests from forks, two PRs opened from branches with the same name, such as two forks’ main, share a group and cancel each other’s runs. Key PR runs on the PR number instead, which is unique: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}.
The classic “cancel superseded PR runs” pattern#
Putting it together, here’s the pattern you can drop into almost any CI workflow:
name: CI
on: pull_request: push: branches: [main]
# Cancel in-progress runs for the same PR/branch, but let# pushes to main (and other non-PR events) run to completion.concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true
jobs: build-and-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - uses: actions/setup-node@v7 with: node-version: 24 cache: npm - run: npm ci - run: npm testNow a developer can push as many fixup commits to their PR as they like — only the latest run survives, and everything older is cancelled the instant it’s superseded. The CI minutes you save here are pure waste eliminated.
Job-level concurrency#
Concurrency isn’t only a workflow-level setting — you can apply it to an individual job too. This is handy when most of your workflow can run freely in parallel, but one specific job needs to be serialized.
jobs: test: runs-on: ubuntu-latest steps: - run: echo "Tests run freely, no concurrency limits here"
deploy-preview: needs: test runs-on: ubuntu-latest # One preview deploy per branch at a time: a newer push waits, # and older pending ones are dropped. concurrency: group: preview-${{ github.head_ref || github.run_id }} cancel-in-progress: false steps: - uses: actions/checkout@v7 - run: ./deploy-preview.shThe same group / cancel-in-progress semantics apply, just scoped to that one job. Job-level groups live in the same namespace as workflow-level ones, so a workflow-level group and a job-level group with the same string will contend with each other — pick distinct names to avoid surprises.
In a matrix, each job evaluates the group on its own, so put the matrix values in it: group: e2e-${{ github.ref }}-${{ matrix.browser }}. Otherwise all the jobs of the matrix land in the same group: they run one at a time, and a pending one is cancelled when the next one arrives. With cancel-in-progress: true, each one cancels the one before it. A job-level group can use the github, inputs, vars, needs, strategy and matrix contexts, and a workflow-level group only github, inputs and vars. Neither accepts env or secrets: group: deploy-${{ env.STAGE }} fails validation.
Serializing deploys: queue instead of cancel#
Here’s where cancel-in-progress flips. For deploys and releases, cancelling an in-progress run is the last thing you want — killing a deploy halfway through can leave production in a broken, half-migrated state. Instead, you want new deploys to wait their turn.
That’s exactly what the default (cancel-in-progress: false) gives you:
name: Deploy
on: push: branches: [main]
concurrency: group: production-deploy cancel-in-progress: false # this is the default; shown for clarity
jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - run: ./deploy-to-production.shNote the group key here is a fixed string (production-deploy), not branch-scoped — because there is exactly one production, and every deploy to it must be serialized against every other. Deploy jobs usually also use an environment for approvals and secrets; it doesn’t serialize deploys by itself, so keep the concurrency group.
Groups are scoped to one repository, though: a deploy started from another repository doesn’t wait for this one. If several repositories deploy to the same target, either use a lock in your deploy tool, or send all their deploys through one workflow in one repository, which each of them starts with a dispatch. Give that workflow’s group queue: max, so that one repository’s pending deploy isn’t replaced by another’s.
What cancel-in-progress: false does: one running, one pending#
This is the part that trips people up. When cancel-in-progress is false and a deploy is already running:
- The running deploy is left alone. It always finishes.
- A newly triggered run doesn’t start. It enters the group as
pendingand waits. - By default a group holds at most one pending run. If another deploy is triggered while one is already pending, the pending one is cancelled and the newest takes its place.
So the default doesn’t mean “queue everything”. It means “never cancel the running one”. For deploys that’s usually what you want: when three merges land during a deploy, you only need the latest one deployed next.
- Merge A: deploy A starts running.
- Merge B (while A runs): deploy B becomes pending.
- Merge C (while A still runs, B pending): deploy B is cancelled, deploy C becomes pending.
- Deploy A finishes: deploy C starts. B’s state was never deployed, which is fine, since C includes it.
Queue every run with queue: max#
Sometimes every run matters: each release must be published in order, each migration applied, each tenant deployed. Since May 2026, on GitHub.com and GitHub Enterprise Cloud (not GitHub Enterprise Server), a concurrency group can keep a real queue. Add queue: max:
name: Release
on: push: tags: ["v*"]
concurrency: group: release queue: max
jobs: publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - run: ./publish.sh "$TAG" env: TAG: ${{ github.ref_name }}queue takes two values:
single(the default): at most one pending run, replaced by the newest, as described above.max: up to 100 pending jobs or runs wait in the group and run one at a time. Once 100 are waiting, further runs are cancelled.
Two rules to know:
queue: maxcan’t be combined withcancel-in-progress: true, since one says “wait” and the other says “cancel”. The workflow fails validation.- Runs leave the queue first in, first out, ordered by when each one started waiting on the group, not when it was triggered. Two runs triggered a second apart can still swap places if the first one took longer to reach the concurrency check, so don’t rely on a strict order for runs that start almost together. Push release tags one at a time: when more than three tags are pushed at once, GitHub creates no push event for them, so nothing is queued.
queue: max works at the job level too, which is handy to serialize only the deploy job of a workflow while its tests run freely.
Gotchas#
A few things that bite people in practice:
- Never use
cancel-in-progress: trueon deploy or release jobs. A cancelled deploy can corrupt state, leave a half-published artifact, or abort a database migration partway through. Deploys should wait (defaultfalse, orqueue: max), never cancel. cancel-in-progresscan be an expression. Withgroup: ${{ github.workflow }}-${{ github.ref }},cancel-in-progress: ${{ github.event_name == 'pull_request' }}cancels superseded PR runs and never cancels amainbuild once it has started. Runs onmainstill wait for each other, though, and a pending one is replaced by a newer push. Keep the group per ref: in one shared group, a new PR run would cancel a runningmainbuild. Use thegithub.head_ref || github.run_idkey if every commit onmainmust be tested.- Concurrency group names are case-insensitive.
Prodandprodare treated as the same group. Don’t rely on capitalization to separate groups — they’ll collide. - A called workflow sees its caller’s
github.workflow. In a reusable workflow,${{ github.workflow }}is the caller’s name, so a key like${{ github.workflow }}-${{ github.ref }}resolves to the same group in both files. Withcancel-in-progress: true, the called workflow then cancels its caller. Set concurrency in the caller only, or give the called workflow’s group a prefix of its own. - A missing fallback fails the run or merges groups. A
groupthat evaluates to an empty string, such as${{ github.head_ref }}on a push, is an error: GitHub fails the run instead of running it without a group. With a prefix, the group is never empty: in a workflow named CI,${{ github.workflow }}-${{ github.head_ref }}isCI-for every push and dispatch, so all of those runs share one group and cancel or replace each other. Always add a fallback that is never empty, as ingithub.head_ref || github.run_id. - The
run_idfallback doesn’t serialize dispatched runs. A run that another workflow starts with a dispatch has an emptygithub.head_ref, sogithub.head_ref || github.run_idgives each one a group of its own and nothing waits. To keep two dispatches from overlapping, use a fixed group, or one built from the inputs, such asdeploy-${{ inputs.environment }}. - A cancelled step gets about 10 seconds to stop. The runner sends SIGINT, then SIGTERM 7.5 seconds later, and kills the process tree 2.5 seconds after that. If a job or step marked for cancellation is still running 5 minutes after the cancel, GitHub forcibly ends it. Steps with
if: always()still run after a cancel, and so does a job withif: always(), though its steps whose condition is false after the cancel (such as the defaultsuccess()) are cancelled. Until they finish, the superseded run stays in progress and keeps using minutes, so useif: ${{ !cancelled() }}for reports and uploads that should run after a failure but not after a cancel. Don’t put irreversible side effects (publishing, tagging, deploying) in a job that’s eligible for cancellation.
Conclusion#
The concurrency keyword is two patterns wearing one hat. For pull requests, group by branch and set cancel-in-progress: true so rapid pushes throw away their own stale runs — the simplest CI cost win you’ll find. For deploys and releases, use a fixed group and the default cancel-in-progress: false so production work is never killed mid-flight: by default only the newest pending run is kept, and queue: max keeps up to 100 of them in order. Get the group key right — including the github.head_ref || github.run_id fallback so non-PR runs don’t cancel each other — and you’ll stop wasting minutes without ever risking a broken deploy.