Skip to content

Workflow Post-Run Steps Not Executed When Workflow is Cancelled #36983

@bircni

Description

@bircni

Description

When a workflow run is cancelled using the cancel button in the UI, the post-run cleanup steps (defined as post: in action metadata) are not executed. This is a significant issue because post-run steps are critical for:

  • Resource cleanup (stopping containers, cleaning temporary files, releasing locks)
  • Artifact publishing (uploading logs or reports even on cancellation)
  • Notification systems (notifying external services that the workflow ended)
  • State management (ensuring system consistency)

Current Behavior

  1. User clicks "Cancel workflow run" button on the UI
  2. The Cancel() handler in routers/web/repo/actions/view.go is invoked
  3. actions_model.CancelJobs() is called, which immediately sets job status to StatusCancelled
  4. The job is marked as done, and no post-run steps are executed
  5. Cleanup tasks that should run are skipped entirely

Expected Behavior (GitHub Actions)

GitHub Actions always executes post-run steps, regardless of:

  • Workflow cancellation (user clicked cancel button)
  • Job failure
  • Timeout
  • Step failure

This ensures resource cleanup and notification always occur.

Steps to Reproduce

  1. Create a workflow with at least one regular step and one post-run cleanup step
  2. Start the workflow run
  3. While the workflow is running, click the "Cancel" button
  4. Observe that post-run steps do not execute (they are skipped entirely)
  5. Resources that should be cleaned up remain uncleaned

Expected Result

Post-run steps should execute after cancellation, allowing proper cleanup before the job terminates.

Actual Result

Post-run steps are skipped when a workflow is cancelled, leaving resources in an inconsistent state.

Proposed Solution

Implement a state transition that allows post-run steps to execute even when a workflow is cancelled:

Running → Cancelling → PostRunning → Cancelled

Gitea Version

1.25.5

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

independent of running gitea

Database

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions