Skip to content

feat(actions): add force-cancel workflow run API - #38756

Draft
Zettat123 wants to merge 9 commits into
go-gitea:mainfrom
Zettat123:force-cancel-api
Draft

feat(actions): add force-cancel workflow run API#38756
Zettat123 wants to merge 9 commits into
go-gitea:mainfrom
Zettat123:force-cancel-api

Conversation

@Zettat123

Copy link
Copy Markdown
Contributor

Add POST /repos/{owner}/{repo}/actions/runs/{run}/force-cancel, the counterpart of
GitHub's force-cancel endpoint.

It cancels a run like POST .../cancel, but bypasses the graceful cancelling handshake with the runner and stops running tasks immediately.

Permissions and responses match the /cancel endpoint.

References:

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 3, 2026
@github-actions github-actions Bot added topic/gitea-actions related to the actions of Gitea type/feature Completely new functionality. Can only be merged if feature freeze is not active. labels Aug 3, 2026
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Aug 3, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Aug 3, 2026
@wxiaoguang

Copy link
Copy Markdown
Contributor

Related to Fix allow cancelling runs without running jobs - #35842 ?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Actions REST API endpoint to force-cancel workflow runs (POST /repos/{owner}/{repo}/actions/runs/{run}/force-cancel), mirroring GitHub’s behavior by bypassing the graceful runner cancellation handshake and immediately stopping running tasks, while keeping permissions and responses aligned with the existing /cancel endpoint.

Changes:

  • Introduces ForceCancelWorkflowRun API route/handler and wires it into the v1 router.
  • Extends the cancellation pipeline with a “force” mode (ForceCancelRunForceCancelJobs), causing running tasks to be stopped as cancelled instead of entering the cancelling handshake.
  • Adds model- and integration-level tests for force-cancel behavior and updates generated Swagger/OpenAPI specs.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/integration/api_actions_run_test.go Adds an integration test validating force-cancel behavior vs normal cancel handshake.
templates/swagger/v1-swagger.generated.json Documents the new force-cancel endpoint in Swagger v2 output.
templates/swagger/v1-openapi3.generated.json Documents the new force-cancel endpoint in OpenAPI v3 output.
services/actions/cancel.go Adds ForceCancelRun and factors shared logic into cancelRun(..., force).
routers/api/v1/repo/actions_run.go Adds ForceCancelWorkflowRun handler and shares logic with CancelWorkflowRun.
routers/api/v1/api.go Registers the /force-cancel route under workflow run endpoints.
models/actions/run_job.go Adds ForceCancelJobs and threads a force flag into job cancellation to stop tasks immediately.
models/actions/run_job_test.go Adds unit tests for force-cancelling running and already-cancelling tasks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wxiaoguang
wxiaoguang marked this pull request as draft August 3, 2026 12:28
@wxiaoguang

Copy link
Copy Markdown
Contributor

Related to Fix allow cancelling runs without running jobs - #35842 ?

Waiting for the answer to this question.

@Zettat123

Copy link
Copy Markdown
Contributor Author

Related to Fix allow cancelling runs without running jobs - #35842 ?

Waiting for the answer to this question.

Thank you for the information. I missed #35842 in my initial research. I'll analyze how it relates to the current PR.

@Zettat123

Zettat123 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

#35842 resolves the issue where the run status is inconsistent with its jobs' statuses (not just force-cancel, normal cancel needs this fix too). My suggestion is merging #35842 first (with a backport), after which this PR can apply the fix on the force-cancel path.

@wxiaoguang
wxiaoguang marked this pull request as ready for review August 4, 2026 04:47
@Zettat123
Zettat123 marked this pull request as draft August 4, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/gitea-actions related to the actions of Gitea type/feature Completely new functionality. Can only be merged if feature freeze is not active.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants