# RUN: try, fix, and roll back

import { Steps } from "@astrojs/starlight/components"

**RUN** tries a flow that BUILD saved. Your coding agent starts a run with sample input and follows it to the end. When
a step fails, it fixes the TypeScript, saves, and runs again. After a good run, it can save a checkpoint, and it
restores an earlier checkpoint when you ask.

## When to use

- BUILD saved the flow and you want to try it, debug a failed run, or roll back.
- Prefer [THINK: discover and design](../think-discover-and-design/) when the plan itself must change.
- Prefer [Manage version and deployments](../../../operate/manage-version-and-deployments/) in Studio to promote a flow
  to Live, pin a version, or delete.

Before you begin, let BUILD save the flow from the same application folder. RUN can follow BUILD in the same chat.

## Guide

### Start a run

The agent picks how the run starts from the flow's trigger, using sample values only, never secrets:

- **Schedule, or no trigger:** a manual run with no input.
- **Webhook:** the agent opens a test session on the deployment, then sends a sample JSON body to the flow's webhook.
  When the webhook requires an API key, the agent asks you to trigger the flow once instead.
- **Any trigger, after an earlier run:** a replay of that run.
- **Flowhook or chat trigger with no earlier run:** the agent asks you to start it once, from its caller or Studio, then
  replays it.

1. **Ask to try the flow.** Name the input you want to try, or let the agent propose sample values.
2. **Answer the agent's question when steps write.** When a step that creates, updates, sends, or deletes runs for real,
   the agent asks first: run, change the input, or stop. Flows that only read run without that question.
3. **Confirm the run.** Mindflow asks you to confirm the run in the agent's own dialog when the agent can show one
   (Claude Code can). Otherwise, the agent's usual approval prompt applies. If you decline, the run does not start.
4. **Follow the run.** In agents that support MCP background tasks, such as Claude Code, the run shows as a background
   task, and stopping that task stops the run. Other agents check the run until it ends, and offer to stop it if it is
   still running after several checks. When the run waits for a person on a resume step, the agent says where to act.

### Fix a failing step

When a run fails, the agent reads the failing step's input and output, fixes the TypeScript, saves, and replays the
failing run with the same input.

1. **Read the cause.** The agent names the failing step and the cause. When the flow hides execution data, the agent
   works from the step's setup and says so.
2. **Let the agent fix and save.** The agent saves a checkpoint once per session before its first change, compiles,
   and saves the fix.
3. **Replay.** The agent replays the failing run. After three failed fixes on the same step, it stops and reports.

### Save a checkpoint or roll back

A checkpoint is a named flow version you can restore later.

1. **Save a checkpoint after a good run.** When a run completes, the agent summarizes what each step did and offers to
   save a checkpoint named **Verified: …**.
2. **Roll back on request.** Ask the agent to restore. It lists the checkpoints it saved and asks you to confirm one.
   Mindflow first saves the current canvas as an **Autosave** version, then restores the one you picked.

### Close the test session

A webhook test session stays open for hours. While it is open, real webhook events also run the flow's latest version.
When you tell the agent that testing is done, it offers to close the session. Mindflow asks you to confirm, because
Studio shares the same session. For how test sessions work, see [Choose Test or Live](../../../operate/choose-test-or-live/).

## Example

The SOC analyst tries **Triage malicious webhook IPs** in the same Claude Code chat, right after BUILD.

1. **Ask to try it.** They ask the agent to try the flow with an IP their threat feed already marks as malicious. The
   agent opens a test session and prepares a sample webhook body with that IP.
2. **Confirm.** The Slack step posts a message, so the agent asks before the run. Claude Code then shows Mindflow's
   **Run this deployment now?** dialog, and they accept.
3. **Follow it.** The run shows as a background task in Claude Code and completes. Slack receives the alert.
4. **Save a checkpoint and close.** They accept the **Verified: …** checkpoint, say testing is done, and confirm
   closing the test session.

## Keep in mind

- A run calls the real services its steps use, with the deployment's credentials.
- Run data stays in chat. The agent does not copy step input or output into project files.
- Never put secrets in a sample payload.
- RUN never deletes anything, changes a deployment's Test or Live mode, or repoints a deployment pinned to a fixed
  version. Do those in Studio.

## Related

[BUILD: write, compile, and save](../build-the-automation/) ·
[Manage version and deployments](../../../operate/manage-version-and-deployments/) ·
[Choose Test or Live](../../../operate/choose-test-or-live/)
