Skip to content

gh run cancel reports "Cannot cancel a workflow run that is completed" for any HTTP 409, hiding the real API error #15053

Open

Description

@hugo-lorenzo-mato

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):

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.

  1. Take a workflow run in status: queued that the API refuses to cancel.
  2. Run gh run cancel <run-id> -R OWNER/REPO.
  3. 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
  1. 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: gh shows 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 is queued.

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

  1. cli-triage commented on Nov 13, 2026

    @cli-triage

    Reproducible on 2.100.0.

    Using test data for a queued workflow run whose cancel endpoint returned HTTP 409 with a different API message:

    $ gh run cancel 1234 -R example.invalid/hello
    Cannot cancel a workflow run that is completed

    Exit status: 1.

    The same result occurred on release 2.104.0 and source commit 3d5a9e3. The run lookup reported queued, but the API message Cannot 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

    Generated by issue triage.

  2. added
    bug
    gh-run
    priority-3
    on Nov 13, 2026
  3. removed
    needs-triage
    on Nov 13, 2026
  4. muadzhdz commented on Nov 14, 2026

    @muadzhdz

    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, return httpErr.Message directly 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?

  5. BrianKYildirim commented on Nov 20, 2026

    @BrianKYildirim

    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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggh-runpriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions