> For the complete documentation index, see [llms.txt](https://docs.appfarm.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.appfarm.io/library/action-nodes/manage-flow.md).

# Manage flow

The Manage Flow action node manages a Flow run that was started from an [app](https://docs.appfarm.io/reference/apps.md) with [Run Flow](https://docs.appfarm.io/library/action-nodes/run-flow.md). It stops the run, together with every Flow the run started. It is only available in apps.

{% hint style="info" %}
Showroom: [Manage Flow example](https://showroom.appfarm.app/action-nodes/manage-flow), with its setup in Appfarm Create ([register](https://showroom.appfarm.app/sign-up) for access).
{% endhint %}

## Usage

This action node is useful in the following cases:

* When a user should be able to cancel a long-running Flow, for example with a Stop button next to a report that takes minutes to generate.
* When a Flow started with **Run asynchronously** should be stopped before it reaches its timeout.

## Stop a Flow run

To stop a Flow run, the run needs an ID that another action can use while the run is still going:

1. In the Run Flow action node that starts the Flow, bind **Run ID** to a String property, for example an app variable. The ID is stored before the Flow starts.
2. In the action that should stop the run, for example the On Click action of a Stop button, add a Manage Flow action node.
3. Set **Operation** to `Stop` and bind **Run ID** to the same property.
4. Optionally, bind **Result** to a String property to find out what happened.

A run that was started without **Run ID** can't be stopped.

{% hint style="info" %}
**Good to know**

Only the user who started a run can stop it. Anonymous users can't stop runs.
{% endhint %}

## What happens to the run

When the stop reaches the run, the run ends at its next cancellation point:

* A running Web Request, Streaming Web Request or Sleep action node is cancelled. So is the model call of a running Agent action node.
* Any other action node, including data operations that write data, finishes first. The run then stops before the next action node.

Nothing the run has already done is rolled back.

The stop also reaches every Flow the run started, including Flows started with **Run asynchronously**. A stop that arrives after the last action node leaves the run completed, but still ends its asynchronous Flows.

The Run Flow action node that started the run fails with error `17036` (FlowRunStoppedError). To handle it in the calling action, add a [Catch Exception](https://docs.appfarm.io/library/action-nodes/catch-exception.md) node with `17036` in **Appfarm Error Codes**.

## Result

**Result** stores one of the following values. They are results, not errors, so the action node doesn't fail when the run had already ended.

| Value         | Description                                                                                                              |
| ------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `stopped`     | The stop reached the run. The run ends at its next cancellation point, and if it was just ending, it may have completed. |
| `not_running` | The run had already ended.                                                                                               |
| `lost`        | The run can't be stopped. The server running it is gone, or the run was started without being registered.                |

## Errors

The action node fails, without sending a stop, when **Run ID** is empty. Make sure Manage Flow runs after Run Flow has started.

The action node also fails with error `14404` when no run with that ID was started by the current user.

## Properties

| Property      | Description                                                                                                                    |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| **Operation** | The operation to run on the Flow run. `Stop` stops the run and every Flow it started. A data write in progress finishes first. |
| **Run ID**    | *Required.* The ID that Run Flow stored for the run, from a String property. You can stop only runs that you started.          |
| **Result**    | Optionally bind a String property to store the outcome: `stopped`, `not_running` or `lost`. See [Result](#result).             |


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.appfarm.io/library/action-nodes/manage-flow.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
