Sub topic 12
Cancelling Runs Manually
This chapter assumes you know basic workflow syntax and have read the earlier chapters on concurrency groups and cancel-in-progress. Here you will see how to cancel a run yourself, and how that differs from automatic cancellation.
When manual cancellation helps
cancel-in-progress only acts when a newer run joins the same group. Some runs need to stop for other reasons:
- A run was started with the wrong inputs through
workflow_dispatch. - A long job is stuck or waiting on a resource that will never respond.
- A run has no concurrency group, so nothing cancels it automatically.
- You want to free runner capacity for more urgent work.
Manual cancellation gives you the same result as cancel-in-progress. The run stops and ends with the status cancelled.
Cancelling from the GitHub UI
- Open the repository and select the Actions tab.
- Select the workflow run you want to stop.
- Select Cancel workflow at the top right of the run page.
A run that is still waiting in the queue can be cancelled the same way. For a run in a concurrency group, this can be the pending run. Cancelling it removes it from the group, so the next run pushed to that group is not affected by it.
Cancelling with the GitHub CLI
The GitHub CLI (gh) is useful when you want to script cancellation or avoid opening a browser. First list the runs that are still going, then cancel one by its ID.
gh run list --workflow ci.yml --status in_progress
gh run cancel <run-id>Replace <run-id> with the number in the first column of the list output. This is the manual equivalent of what cancel-in-progress does automatically.
Cancelling through the REST API
The same action is available as an API call. The request needs a token with write access to Actions.
gh api --method POST repos/OWNER/REPO/actions/runs/RUN_ID/cancelThe API also has a force-cancel endpoint, /actions/runs/RUN_ID/force-cancel. Use it only when a normal cancel does not take effect, for example because a job is stuck and ignores the cancel signal. Force-cancel skips the conditions that normally let always() and cancelled() steps run, so cleanup steps may not execute.
What happens after you cancel
Cancellation is not instant. GitHub sends a cancel signal to the run, and the following happens:
- Jobs that have not started are skipped.
- Running steps receive the signal and are given a short time to stop.
- Steps whose
ifcondition evaluates to true for a cancelled run, such asif: ${{ cancelled() }}orif: ${{ always() }}, still run.
This is the same behavior as automatic cancellation, so the cleanup step you wrote for the job-level example applies here too.
The diagram below shows the sequence from the user's side.
Interaction with concurrency groups
Cancelling a run frees its place in the group. If one run was running and another was pending, cancelling the running one lets the pending run start. Cancelling a deployment this way does not cancel the pending deployment, so a queued run may begin right after you stop the first one. If you want to stop all deployments, cancel the pending run first, then the running one.
Common mistakes
| Mistake | Result |
|---|---|
| Cancelling the running run first in a serialized group | The pending run starts immediately |
| Relying on force-cancel for normal stops | Cleanup steps are skipped |
| Using a token without Actions write access | The API returns a permission error |
| Expecting a completed run to cancel | The request fails because the run already finished |
Exercise
A deployment group has one running and one pending run, both with cancel-in-progress set to false. You cancel only the running run from the UI. What happens next, and how would you stop both?
Show answer
The pending run leaves the queue and starts, because the group slot is now free. To stop both, cancel the pending run first, then cancel the running run.