Repository navigation
Description
Describe the bug
gh run cancel turns every HTTP 409 from the cancel endpoint into Cannot cancel a workflow run that is completed and drops the error message returned by the API. The REST API also returns 409 for runs that are not completed. For example, for runs left in queued with zero jobs around a GitHub Actions incident, it returns Cannot cancel a workflow run that has not been queued yet. In that case gh tells the user that a queued run is completed, which is false and sends troubleshooting in the wrong direction.
gh already has the run at that point (shared.GetRun is called before cancelling, and run.Status is queued), but it does not use it to build the message. gh run cancel --force goes through the same translation. In interactive mode, gh only offers runs that are not completed, and still reports "completed" if the API returns 409.
pkg/cmd/run/cancel/cancel.go, lines 125-129 on trunk and in v2.104.0 (lines 126-131 in v2.100.0, with errors.As):
cli/pkg/cmd/run/cancel/cancel.go
Lines 124 to 132 in 3d5a9e3
| if err != nil { | |
| if httpErr, ok := errors.AsType[api.HTTPError](err); ok { | |
| if httpErr.StatusCode == http.StatusConflict { | |
| err = fmt.Errorf("Cannot cancel a workflow run that is completed") | |
| } | |
| } | |
| return err | |
| } |
if httpErr, ok := errors.AsType[api.HTTPError](err); ok {
if httpErr.StatusCode == http.StatusConflict {
err = fmt.Errorf("Cannot cancel a workflow run that is completed")
}
}The inconsistent run state itself is an Actions issue and is out of scope here. This issue is only about the message gh prints.
Affected version
gh version 2.100.0 (2026-09-03)
https://github.com/cli/cli/releases/tag/v2.100.0
The same code is in trunk and in v2.104.0.
Steps to reproduce the behavior
I don't know how to create such a run on demand. Runs created around the GitHub incident of 2026-11-11 (https://www.githubstatus.com/incidents/dvy0t3mvh1lg) stayed queued with jobs.total_count == 0; see also https://github.com/orgs/community/discussions/196717. An httpmock stub that returns 409 with any other message shows the same output.
- Take a workflow run in
status: queuedthat the API refuses to cancel. - Run
gh run cancel <run-id> -R OWNER/REPO. - See the error:
$ gh run view <run-id> -R OWNER/REPO --json status,conclusion
{"conclusion":"","status":"queued"}
$ gh run cancel <run-id> -R OWNER/REPO
Cannot cancel a workflow run that is completed
- Compare with the raw API response:
$ gh api -X POST repos/OWNER/REPO/actions/runs/<run-id>/cancel -i
HTTP/2.0 409 Conflict
{"message":"Cannot cancel a workflow run that has not been queued yet.","documentation_url":"https://docs.github.com/rest/actions/workflow-runs#cancel-a-workflow-run","status":"409"}
Expected vs actual behavior
- Expected:
ghshows the message returned by the API, or only says "completed" when the run is actually completed (run.Status == completed). For example:Cannot cancel workflow run <id> (status: queued): Cannot cancel a workflow run that has not been queued yet. - Actual:
Cannot cancel a workflow run that is completed, for a run whose status isqueued.
Logs
GH_DEBUG=api gh run cancel <run-id> -R OWNER/REPO on 2026-11-13, trimmed to the relevant lines. Owner, repository, run ID and headers are redacted.
* Request to https://api.github.com/repos/OWNER/REPO/actions/runs/<run-id>?exclude_pull_requests=true
> GET /repos/OWNER/REPO/actions/runs/<run-id>?exclude_pull_requests=true HTTP/1.1
< HTTP/2.0 200 OK
"status": "queued",
"conclusion": null,
* Request to https://api.github.com/repos/OWNER/REPO/actions/runs/<run-id>/cancel
> POST /repos/OWNER/REPO/actions/runs/<run-id>/cancel HTTP/1.1
< HTTP/2.0 409 Conflict
{
"message": "Cannot cancel a workflow run that has not been queued yet.",
"documentation_url": "https://docs.github.com/rest/actions/workflow-runs#cancel-a-workflow-run",
"status": "409"
}
* Request took 464.975934ms
Cannot cancel a workflow run that is completed
The GET right before the POST returns "status": "queued", and the last line still says the run is completed.
Activity
cli-triage commentedon Nov 13, 2026
Reproducible on 2.100.0.
Using test data for a queued workflow run whose cancel endpoint returned HTTP 409 with a different API message:
Exit status:
1.The same result occurred on release 2.104.0 and source commit
3d5a9e3. The run lookup reportedqueued, but the API messageCannot cancel a workflow run that has not been queued yet.was discarded. This confirms the CLI error is misleading for non-completed 409 responses.Supporting reports
Duplicate analysis
Label reasoning
Reproduction log
Investigation notes
Generated by issue triage.
muadzhdz commentedon Nov 14, 2026
Hi @cli/code-reviewers, I'd like to work on this if you're open to an external contribution (
help wanted).Proposed fix: in
runCancel(pkg/cmd/run/cancel/cancel.go), when the API returns HTTP 409, returnhttpErr.Messagedirectly if it is non-empty, and fall back to the existing"Cannot cancel a workflow run that is completed"only when the message is empty. This surfaces the real API error (e.g."Cannot cancel a workflow run that has not been queued yet.") while keeping the existing message as a fallback for empty-body 409 responses.Does this match the acceptance criteria you have in mind?
BrianKYildirim commentedon Nov 20, 2026
Hello @cli/code-reviewers,
I noticed that PR #15103, which attempted to address this issue, was recently closed without merging.
I've independently reproduced the reported behavior and implemented a local fix with regression tests covering both standard and forced cancellation. My approach preserves the API-provided error message for HTTP 409 responses, with a fallback for responses without a message.
Before submitting anything, I'd like to confirm whether this issue is open to external contributions and, if so, what acceptance criteria you'd prefer.
I'm happy to adjust my implementation based on your guidance or coordinate with anyone already working on the issue.
Thanks!
codex/gpt-6-luna: fix cleaner heredoc wedge and classify ghost runs […