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

# Runs

> One execution of a workflow: its lifecycle and statuses, its payload and tags, and how to find, replay, or cancel it.

A run is one execution of a workflow, with its own payload, its own saved steps, and its own status. Nelkap records every run as it happens, so you can see what any run did and why it stopped, without adding a single log line to your code.

## Lifecycle

A run moves through these statuses:

![A run goes from Pending to Ready to Running. From Running, it either ends as Completed or Failed, or pauses as Sleeping or Waiting and goes back to Pending when it wakes. A run that hasn't started, or is paused, can be Canceled.](https://mintcdn.com/holotus/wXODVU55G3H-UZVw/images/run-statuses-light.png?fit=max\&auto=format\&n=wXODVU55G3H-UZVw\&q=85\&s=5e2e41fb54505de56c78cc15d966e5e9)

| Status | What it means |
| - | - |
| Pending | The run is due, and waits for its turn to go to your app. |
| Ready | The run is on its way to your app. |
| Running | Your app is executing it. |
| Sleeping | The run is paused until its time is up. |
| Waiting | The run is paused until an event arrives with its key. |
| Completed | Your workflow returned. |
| Failed | Your workflow threw an error it didn't catch, or Nelkap stopped the run. The reason shows on the run's page. |
| Canceled | Someone canceled the run, or its workflow was removed, before it could end. |

Nelkap sends pending runs to your app every minute, so a new run starts within a minute of being created, unless it waits for room under a [concurrency limit](https://docs.nelkap.com/guides/concurrency.md). A run that wakes from a sleep or a wait goes back to Pending, and is sent to your app the same way.

## Payload

The payload is the input of the run: the value your workflow receives as its argument, on every call. It's any JSON value, up to your plan's request size of 1 to 3 MB. Where it comes from depends on how the run started:

| The run was started by | Its payload is |
| - | - |
| [`nelkap.run`](https://docs.nelkap.com/triggers/run) | The value passed as its second argument. |
| An [event](https://docs.nelkap.com/triggers/events.md) | The event's payload. |
| A [webhook](https://docs.nelkap.com/triggers/webhooks.md) | The JSON body of the call the webhook received. |
| A [schedule](https://docs.nelkap.com/triggers/schedules.md) | `null`. |
| A replay | The payload of the run it replays. |

The payload is sent as JSON, so a `Date` reaches your workflow as a string.

> [!TIP]
>
> Keep the payload small, like the ID of a user or an order, and load the rest in a step. The run then works on the latest data, and every call carries less.

## Tags

Tags are labels you give a run, so you can find it later, like the customer it works for. Pass them when you start the run:

```ts theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
await nelkap.run(onboardUser, 'user_42', {
  tags: ['team_7', 'beta'],
});
```

A run takes up to 10 tags, each up to 128 characters. An event passes its tags to every run it starts. Runs started by a schedule or a webhook have no tags. A replay keeps the tags of the run it replays.

## Triggers

Each run records how it started, shown as its trigger:

| Trigger | Started by |
| - | - |
| API | [`nelkap.run`](https://docs.nelkap.com/triggers/run) in your code. |
| Event | An event emitted with [`nelkap.emit`](https://docs.nelkap.com/triggers/events), or received by a [webhook](https://docs.nelkap.com/triggers/webhooks.md). |
| Cron | A [schedule](https://docs.nelkap.com/triggers/schedules.md). |
| Manual | A [replay](#replay-a-run) from the console. |

## Find a run

The Runs page of the console lists runs newest first, with their workflow, project, trigger, status, start, end, duration, and number of steps. Narrow the list down by:

* Workflow, tag, trigger, or status.
* Period: the last hour, 24 hours, 3 days, 7 days, 15 days, or 30 days.
* Project, chosen at the top of the page.

For example, to see the failed runs of a customer this week, filter by their tag, by the Failed status, and by the last 7 days.

The Overview page gives the big picture: the number of projects, workflows, runs, and events, the success rate of recent runs, and the last runs to start.

## Run details

Open a run to see everything about it:

* Its payload, as your workflow received it.
* Its error, if it failed: the message your code threw, or the reason Nelkap stopped it.
* Its ID, its tags, and the event that started it, if any.
* When it was created, sent to your app, started, and ended, and how long it took.
* Its status. A waiting run also shows the key it's waiting on.

Below, each step is listed in the order it was saved, with its type, its score if it's a score, when it started and ended, and how long it took. Open a step to see what it returned, or the error it threw.

## Replay a run

Replay an ended run to run it again, for example once you've fixed the bug that made it fail. Nelkap starts a new run of the same workflow, with the same payload and tags, and its trigger shows as Manual. Every step runs from the start, and the original run stays as it was, so you can compare the two.

* You can replay a run that completed, failed, or was canceled.
* Its workflow must still be registered.
* A run started by an event is replayed with the event's payload, as a run of its own. The replay doesn't start the other workflows that listened for the event.

> [!WARNING]
>
> A replay runs every step again, including the steps that sent emails or charged cards in the original run. Make those steps safe to repeat before you replay. See [Idempotency](https://docs.nelkap.com/guides/idempotency.md).

## Cancel a run

Cancel a run to make sure it never resumes. You can cancel a run that is pending, ready, sleeping, or waiting. Once canceled, it's never sent to your app again.

A running run can't be canceled, since your app is executing it. To stop all the runs of a workflow, remove the workflow from [`registerWorkflows`](https://docs.nelkap.com/concepts/workflows#add-and-remove-workflows): its runs that haven't started yet, or are sleeping or waiting, are canceled at once.

## Permissions

| Action | Role |
| - | - |
| See runs and their steps | Every member of the workspace |
| Replay or cancel a run | Member or above |

See [Members and roles](https://docs.nelkap.com/manage/members.md).

## Retention

An ended run stays in your project, with its steps, for the history of your plan:

| Plan | History |
| - | - |
| Starter | 1 day after the run ends |
| Pro | 7 days after the run ends |
| Business | 15 days after the run ends |

Runs still in progress are kept for as long as they last, even a year of waiting. To keep ended runs longer, [export them](https://docs.nelkap.com/manage/exports.md).


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