Skip to content

Add --force flag to gh run cancel <run-id> #11073

Description

@stepankuzmin

Describe the feature or problem you’d like to solve

Sometimes, a workflow run could not respond to regular cancellation, so we should be able to force it as outlined in https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#force-cancel-a-workflow-run

Proposed solution

gh run cancel --force <run-id>

Additional context

https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#force-cancel-a-workflow-run

Activity

  1. babakks commented on Jun 10, 2025

    @babakks
    Member

    Thanks for submitting this, @stepankuzmin! 🙏

    Not surprisingly, @BagToad brought this up in a recent conversation we had. I'm wondering if there's any issue/discussion in the past, because I couldn't find similar requests among our old issues. @BagToad, in case you know some issue, could you please link this to it?

    I think this is actually a good suggestion. So, I'm going to put down the A/C for it.

    Let's first discuss the experience. See my comment below.

  2. stepankuzmin commented on Jun 10, 2025

    @stepankuzmin
    Author

    Hey @babakks 👋

    I've also tried to find any related information in the existing issues, but I didn't see anything.

  3. babakks commented on Jun 10, 2025

    @babakks
    Member

    Before jumping to the A/C, I think we need to investigate the experience a bit more.

    Currently, gh run cancel does not prompt for confirmation. But as of the force-cancel endpoint docs:

    You should only use this endpoint to cancel a workflow run when the workflow run is not responding to POST /repos/{owner}/{repo}/actions/runs/{run_id}/cancel.

    It's probably because force-cancelling a run might have side effects which wouldn't incur if the user goes through the ordinary cancel. So, I think at the CLI side, we should ask the user to confirm the forced cancel. And if there's a confirmation prompt, we might also want to have a way of bypassing it, e.g. with an extra --yes option to make it usable in automation use cases.

    So, the TLDR is we have these three options:

    1. run cancel --force does not prompt and works just like normal cancel.
    2. run cancel --force prompts for confirmation.
    3. run cancel --force prompts for confirmation, with an optional --yes flag for bypassing.

    Out of these, I'm more into the 3rd option, but let's see what other folks think.

    @BagToad @andyfeller @williammartin What are your thoughts?

  4. added
    coreThis issue is not accepting PRs from outside contributors
    gh-runrelating to the gh run command
    and removed on Jun 10, 2025
  5. stepankuzmin commented on Jun 10, 2025

    @stepankuzmin
    Author

    run cancel --force with an optional --yes flag looks good 👍

  6. BagToad commented on Jun 11, 2025

    @BagToad
    Member

    Thanks for pinging me on this @babakks ❤ I have been meaning to open an issue for this because it's a straightforward feature that only has API access right now. Thanks for opening this @stepankuzmin! It puts the CLI in a bit of a unique position to provide a better way to access this feature 😃

    Now to the point, I actually don't want a --yes. This is a double confirmation since the user has already told us they'd like to force it with --force.

    Another reason I'm not really worried is that the impact of a force-cancel is not that much different than a cancel. The difference in particular is that it overrides any conditionals in the workflow that may make it immune to a typical cancellation. The big one being the inclusion of if: always() as a job condition which makes the workflow continue to run despite a cancellation.

    Most workflows will actually be cancellable without this flag, and besides most people are just running a straight API call to force cancel when they need to without really thinking about it, because they just want to cancel it.

    And, the impact of an accidental job cancellation is contextual based on what a user is doing, but in general it simply means the workflow needs to be re-ran. It's not the end of the world, which is why we don't have a confirmation for a typical cancellation.

  7. added
    help wanted candidateIssue may be marked as help-wanted but not yet ready to accept PR
    on Jul 28, 2025
  8. BagToad commented on Jul 28, 2025

    @BagToad
    Member

    Acceptance Criteria

    • Given I have a workflow run in progress
      When I run gh run cancel --force <run-id>
      Then the workflow run is force-cancelled using the GitHub API’s force-cancel endpoint

    • When I run gh run cancel --help
      Then I see documentation for the --force flag describing its use

  9. added and removed
    help wanted candidateIssue may be marked as help-wanted but not yet ready to accept PR
    coreThis issue is not accepting PRs from outside contributors
    on Jul 28, 2025
  10. ankddev commented on Aug 15, 2025

    @ankddev
    Contributor

    I'm working on this

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

Metadata

Metadata

Assignees

Labels

enhancementa request to improve CLIgh-runrelating to the gh run commandhelp wantedContributions welcome

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions