> ## Documentation Index
> Fetch the complete documentation index at: https://empirical.run/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Concurrency

> Control what happens when a test run is triggered while another run in the same group is still going

Every test run belongs to a **concurrency group**. Runs in the same group (within a project)
execute one at a time. When a run is triggered and its group already has an active run, the
new run's `on_conflict` policy decides what happens.

Both are set on the trigger request, so each caller says what it needs: a CI pipeline can
cancel the previous run for the same branch, a nightly schedule can wait its turn, and a
one-off run from the dashboard can opt out.

## The `concurrency` object

```json theme={null}
{
  "environment": "preview",
  "build": { "branch": "feat-x", "repo": "acme/web" },
  "concurrency": {
    "group": "preview/acme/web@feat-x",
    "on_conflict": "cancel"
  }
}
```

| Field | What it means |
| - | - |
| `group` | Free-form key, scoped to the project. Runs with the same group run one at a time. Max 512 chars |
| `on_conflict` | What the new run does when the group already has an active run (below) |

Omit `concurrency` to use the project's default (see
[Projects with a project-level setting](#projects-with-a-project-level-setting)).
Send `"concurrency": null` for no limit at all.

### `on_conflict`

| Value | What happens |
| - | - |
| `cancel` | The group's in-progress and waiting runs are cancelled and the new run starts immediately |
| `wait` | The new run enters **Pending** until the in-progress run finishes. If another `wait` run arrives, it replaces the older pending run, so at most one run waits per group |

The policy belongs to the new run. A `wait` run never cancels a running one; a `cancel` run
always does, even if the running one was itself triggered with `wait`.

Only runs created in the last 6 hours count as active, so a stuck run cannot block a group
forever.

### Choosing a group

| You want | Group | `on_conflict` |
| - | - | - |
| One run per PR; a new push supersedes the previous run | `preview/acme/web@<branch>` | `cancel` |
| One run per deployment target that cannot take two runs | the deployment URL | `wait` |
| Nightly runs on production never overlap | `production-nightly` | `wait` |
| Everything in the project strictly one at a time | any fixed string, e.g. `all` | `wait` |

Groups are plain strings compared exactly. Include whatever makes two runs "the same thing"
for you, and nothing else.

## Scheduled runs

A schedule carries its own block in `ENVIRONMENTS.yaml`:

```yaml theme={null}
environments:
  - slug: production
    name: Production
    scheduled_trigger:
      cron: "0 2 * * *"
      concurrency:
        group: production-nightly
        on_conflict: wait
```

A plain `scheduled_trigger: "0 2 * * *"` still works and uses the project default. Configure
scheduled concurrency in `ENVIRONMENTS.yaml` alongside the cron expression.

The change takes effect only after its pull request is merged into the test repository's default branch.

## What a run records

Every run stores the group and policy it was created with, so the decision stays accurate
even if settings change later. It comes back as `concurrency` on the run in the API and shows
under **Concurrency** in the run's details on the dashboard, where the group links to the list
of all runs in that group. `GET /api/test-runs?concurrency_group=<group>` filters the list.

```json theme={null}
"concurrency": { "group": "production-nightly", "on_conflict": "wait" }
```

`concurrency` is `null` when no limit applied.

Reruns reuse the source run's group and policy.

## Projects with a project-level setting

Projects created before per-run concurrency have a frozen project-level setting that applies to
triggers without a `concurrency` block. See [Deprecations](https://empirical.run/docs/deprecations.md#project-concurrency-setting)
for how it maps to a group and policy.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.