> For the complete documentation index, see [llms.txt](https://docs.currents.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.currents.dev/getting-started/ci-setup/github-actions/cancel-runs.md).

# Cancel Runs on Workflow Cancellation

A cancelled workflow stops reporting mid-run. Currents has no way to tell that apart from a job that is still working, so the run stays in progress until it hits the project's [Run Timeouts](/dashboard/runs/run-timeouts.md). That leaves a run sitting in the feed as if it were live, for up to an hour.

Add a step that cancels the run when the job is cancelled:

```yaml
- name: Cancel the Currents run
  if: ${{ cancelled() }}
  run: npx currents cancel
```

`if: cancelled()` runs the step only when the workflow was cancelled, so it costs nothing on a normal run.

## Which credential to use

[`currents cancel`](/resources/reporters/currents-cmd/currents-cancel.md) authenticates with the [Record Key](/guides/record-key.md) the job already uses to report results, so no additional secret is needed. It identifies the run by its [CI Build ID](/guides/parallelization-guide/ci-build-id.md) or its run ID, which means the same step works on any CI provider.

{% hint style="warning" %}
Set `CURRENTS_CI_BUILD_ID` on the job, as the example below does. Without it Currents generates a CI Build ID that includes the test framework. The cancelling step cannot reconstruct that value from the environment, so it reports that there is no run to cancel.
{% endhint %}

The [cancel-run-gh-action](https://github.com/currents-dev/cancel-run-gh-action) does the same as a GitHub action and accepts either a record key or an [API Keys](/dashboard/administration/api-keys.md):

```yaml
- name: Cancel the Currents run
  if: ${{ cancelled() }}
  uses: currents-dev/cancel-run-gh-action@v1
```

With no inputs, the action reads `CURRENTS_RECORD_KEY`, `CURRENTS_PROJECT_ID` and `CURRENTS_CI_BUILD_ID` from the environment. Declare them on the job, the way the full example below does — a step's `env` is visible only to that step, so variables set on the reporting step reach the cancelling step empty.

Like the command, the action can also identify the run by its run ID, through the `run-id` input or `CURRENTS_RUN_ID`. The [action's README](https://github.com/currents-dev/cancel-run-gh-action#inputs) lists every input.

## Full example

```yaml
name: Run Playwright Tests
on:
  pull_request:
    branches: [main]

# Cancel the previous run when a new commit is pushed to the same branch.
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  run-tests:
    runs-on: ubuntu-latest
    env:
      CURRENTS_PROJECT_ID: ${{ vars.CURRENTS_PROJECT_ID }}
      CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }}
      CURRENTS_CI_BUILD_ID: ${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: "24.x"
      - run: npm ci

      - name: Playwright Tests
        run: npx playwright test

      - name: Cancel the Currents run
        if: ${{ cancelled() }}
        run: npx currents cancel
```

`concurrency` with `cancel-in-progress: true` is what makes this worth setting up: every push to a branch cancels the workflow still running for the previous commit, and each of those leaves a run behind.

## Notes

* **Parallel jobs.** Every job of a parallelized run records into the same run, and every one of them can run the cancellation step. Cancelling a run that is already cancelled succeeds.
* **Nothing recorded yet.** A workflow cancelled before the first results reached Currents has no run to cancel. The step reports that and succeeds, so it does not add a failed step to an already cancelled workflow.
* **Hard cancellations.** A job killed without running its remaining steps never reaches the step. That covers a cancelled job that does not honour `if: cancelled()`, and a runner that disappears. Those runs still end at the inactivity timeout.

See [Cancelling Runs](/dashboard/runs/cancel-run.md) for what cancelling a run affects: test statuses, plan usage, analytics and integrations.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.currents.dev/getting-started/ci-setup/github-actions/cancel-runs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
