Sub topic 4
One running, one pending: what happens to the rest
This chapter covers the queue behind a concurrency group: how many runs can be active, how many can wait, and what happens to the runs beyond that. It assumes you know basic workflow syntax (on, jobs, steps), common triggers such as push and pull_request, and ${{ }} expressions with the github context. You should also know that the concurrency key assigns a run to a group.
The rule: at most one running and one pending
A concurrency group is a label. Every workflow run or job that evaluates to the same label belongs to the same group. GitHub then enforces one limit on that group:
- At most one run (or job) in the group is running.
- At most one run (or job) in the group is pending. A pending run has been triggered but is waiting for the running one to finish.
The group is not a general-purpose queue. Its waiting area holds exactly one run. If a third run arrives while one is running and one is pending, the pending run loses its place.
A run's state in a group can change as follows:
- A run that starts when the group is empty becomes running.
- A run that arrives when one is already running becomes pending.
- A run that arrives when one is running and another is pending replaces the pending one. The older pending run is cancelled.
- When the running run ends, the pending run starts.
This last point matters. When a pending run is displaced, GitHub cancels it. It never starts, and it does not become a skipped or failed run in any way that would be reported as a test failure. It appears in the run list with a cancelled status.
A worked timeline
Suppose a deployment workflow uses this configuration and no cancel-in-progress setting:
name: Deploy
on:
push:
branches: [main]
concurrency:
group: deploy-production
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "Deploy commit ${{ github.sha }}"Four commits (A, B, C, D) land on main within a few minutes, and each deployment takes several minutes. The group handles them like this:
- Commit A triggers run A. The group is empty, so run A starts.
- Commit B triggers run B. Run A is still going, so run B becomes pending.
- Commit C triggers run C. The group already has a pending run, so run B is cancelled and run C becomes pending.
- Commit D triggers run D. Run C is cancelled and run D becomes pending.
- Run A finishes. Run D starts.
Runs B and C never executed. This is intentional. For a deployment, only the newest commit matters, so there is no reason to deploy B and C one after another.
What the default behavior does and does not protect
The default behavior (no cancel-in-progress) gives you two guarantees.
- No overlap. Two runs in the same group never execute at the same time. The running run is never interrupted by a newer one.
- Latest wins in the queue. Of all the runs that arrive while another is running, only the most recent one survives to run next.
It does not give you:
- A first-in, first-out queue. If you need every commit to be deployed or processed in order, the group will drop intermediate runs. Concurrency groups are the wrong tool for that requirement.
- Fairness across triggers. The pending slot is taken by whichever run arrived last, regardless of who triggered it or why.
Interaction with cancel-in-progress
The next chapter covers cancel-in-progress in depth, but the queue rules change with it, so here is the comparison.
| Setting | Running run when a new one arrives | Pending run when a new one arrives |
|---|---|---|
| Not set (default) | Keeps running | Replaced by the new run |
| `cancel-in-progress: false` | Keeps running | Replaced by the new run |
| `cancel-in-progress: true` | Cancelled | There is no waiting. The new run starts at once |
With cancel-in-progress: true, the pending slot is rarely used. The new run cancels the running one and takes its place. The one-running, one-pending rule still holds, but the queue is almost always empty.
Replacement of the pending run happens whether or not cancel-in-progress is on. Setting cancel-in-progress: false does not make the queue longer. It only means a running run is protected.
Seeing it in the Actions tab
In the Actions tab, a pending run shows a waiting status with a message that it is waiting for a concurrency group to be free. A displaced run shows as cancelled. The cancellation annotation reads along these lines: the run was canceled because a run with higher priority in the same concurrency group was queued. Read it as "a newer run took my place". It does not indicate an error in your code.
If you see cancelled runs and cannot tell why, check three things:
- Whether the workflow or one of its jobs has a
concurrencykey. - What the group expression evaluates to for the cancelled run and for its neighbours.
- Whether another workflow file uses the same literal group name.
The troubleshooting chapter extends this checklist.
Edge cases
Runs of different workflows share a group by name only
The group is identified by its string. Two different workflow files with group: deploy-production compete in the same group. This can be useful, for example when a manual workflow_dispatch deployment must not overlap with an automated one. It can also be a surprise when two unrelated workflows happen to pick the same name. The pitfalls chapter returns to this.
The group name is evaluated per run
The expression in group is evaluated when the run is created. Runs with different results sit in different groups and never affect one another. With this configuration, each branch gets its own queue:
concurrency:
group: build-${{ github.ref }}A push to feature-a and a push to feature-b can both run at once. Two pushes to feature-a follow the one-running, one-pending rule.
Pending is decided at the time of arrival
A pending run holds its place only until a newer run arrives or the running run ends. It does not retry or wait in a longer line. If you rely on a pending run starting, remember that a later trigger can remove it.
Cancelled pending runs still count as runs
A displaced run is recorded in the run history. It used no runner time, but it is visible. If you have status checks required on pull requests, a cancelled run for the latest commit would be a problem, but this does not happen in the ordinary case: the run that replaces it is for a newer commit, and that newer run reports its own status.
Job-level groups queue per job
With job-level concurrency, the one-running, one-pending rule applies to jobs, not whole runs. Other jobs in the same run are unaffected. If a job is pending, its run stays in progress while that job waits, and the jobs that depend on it through needs wait as well. If the pending job is displaced, it is cancelled, and dependent jobs are skipped unless their if conditions say otherwise.
Predicting the outcome: a short procedure
Use this procedure when you design or debug a group.
- Write down the group string for each trigger that can occur.
- Group the triggers whose strings are identical. Only these compete.
- Within each group, order the arrivals by time.
- Walk through the arrivals using the four rules from the top of this chapter.
- Check whether
cancel-in-progressis on. If it is, replace "the new run waits" with "the running run is cancelled".
You can use this to test a design on paper before pushing it.
Inspecting the queue from the command line
You can list runs of a workflow with the GitHub CLI to see which are running and which are waiting:
gh run list --workflow deploy.yml --limit 10The status column shows in_progress, queued, completed and so on. The conclusion of a displaced run shows as cancelled. Use --json status,conclusion,headSha,createdAt to get fields you can compare with your expectations.
Summary of the rules
- A group allows one running and one pending run (or job).
- A new arrival replaces the pending run. The replaced run is cancelled.
- When the running run ends, the pending run starts.
- Without
cancel-in-progress: true, a running run is never interrupted. - Only runs with identical group strings compete.
Exercise
A workflow has concurrency: { group: build-${{ github.ref }} } with no cancel-in-progress. Pushes arrive on main in this order: P1 starts and is still running when P2 and P3 arrive, then a push P4 arrives on feature-x while P1 is still running. Which runs execute, which are cancelled, and in what order do the main runs execute?
Show answer
The groups are build-refs/heads/main and build-refs/heads/feature-x. In the main group, P1 runs, P2 becomes pending, then P3 replaces P2 and P2 is cancelled. When P1 finishes, P3 runs. P4 is alone in its own group, so it starts immediately and runs alongside P1. The order on main is P1, then P3. P2 never runs.
Exercise
You change the workflow above to cancel-in-progress: true and repeat the same pushes. What happens to P1, P2 and P3 on main?
Show answer
P2 arrives and cancels the running P1, then P2 starts. P3 arrives and cancels the running P2, then P3 starts. Only P3 completes. No run is left pending, because each new run starts immediately after cancelling the one before it.