Sub topic 4
One running, one pending: what happens to the rest
This chapter assumes you can read a workflow file (on, jobs, steps) and know that a concurrency key with a group name puts runs into the same group. Here we look at what GitHub does when more than two runs arrive in one group.
The rule: at most one running and one pending
A concurrency group holds at most one running run and at most one pending run. A pending run has been queued but has not started because the group is busy.
When a new run arrives in a busy group, GitHub applies these steps:
- If nothing is running in the group, the new run starts at once.
- If one run is running and none is pending, the new run becomes pending and waits.
- If one run is running and another is already pending, the new run replaces the pending one. GitHub cancels the older pending run, and the newer run takes the pending slot.
This means the queue never grows. Intermediate runs are dropped, and only the newest waiting run survives.
A worked example
Take the deployment workflow below. It uses cancel-in-progress: false, so a running deployment is never interrupted.
name: Deploy
on:
push:
branches: [main]
concurrency:
group: deploy-production
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "Deploy to production"Suppose three commits land on main in quick succession. Call their runs A, B and C.
Run A finishes its deployment. Run B never executes, and run C deploys the newest commit. For a deployment this is usually what you want, because C contains B's changes anyway.
How this interacts with cancel-in-progress
The cancel-in-progress setting only changes what happens to the running run. It does not change the pending slot.
| Setting | New run arrives, one running | A third run arrives, one pending |
|---|---|---|
| `cancel-in-progress: false` (default) | New run waits as pending. The running run continues. | Older pending run is cancelled. Newer run becomes pending. |
| `cancel-in-progress: true` | Running run is cancelled. New run starts. | The pending slot is rarely used, because each new run replaces the running one. |
The second row shows why cancel-in-progress: true usually leaves nothing waiting. Each arrival cancels the running run and starts immediately.
Common mistakes
- Expecting a queue. Setting
cancel-in-progress: falsedoes not make GitHub run every run in order. It only protects the running one. Runs between the running and the newest pending run are cancelled. - Missing the cancelled status. A replaced pending run appears as cancelled in the Actions tab, even though no one cancelled it by hand. Do not treat that as a failure.
- Using it where every run must execute. If each commit needs its own run, such as a per-commit audit job, put the commit SHA in the group name so runs never share a group. The next chapters cover group names.
Exercise
A group has run A running and run B pending, and cancel-in-progress is false. Runs C and D arrive in that order. Which runs execute, and which are cancelled?
Show answer
Run A keeps running. When C arrives, it replaces B, so B is cancelled. When D arrives, it replaces C, so C is cancelled. Run D waits as the only pending run and starts after A finishes. So A and D execute, and B and C are cancelled.