# Running workflows

What you can do with a workflow once it is live: pause it, see why a run failed, and undeploy it. Each works the same from the screens, the `xenise` CLI, the API and the MCP server.

## Pausing a workflow

Pause a workflow to stop it starting new runs without undeploying it: the **Pause** button at the top of its page, `xenise pause <workflow>`, `POST /api/workflows/:workflow/pause` or the MCP tool `pause_workflow`. The pause is recorded with when and who (the signed-in person, or the token's owner) and shown on the workflow's page and the list of workflows (`paused` in `GET /api/workflows`). While paused:

- its schedule is skipped and workflows that follow it don't start (neither counts as a failure);
- webhooks get HTTP 409 `{"code":"workflow_paused"}`, its form says it isn't taking answers, mail to it is rejected, and starting it by hand is refused with the same 409;
- runs already going carry on, and their questions can still be answered;
- its Workers, trigger, page and history stay as they are, and a new version can still be deployed.

**Resume** (`xenise resume`, `POST /api/workflows/:workflow/resume`, `resume_workflow`) lets it start runs again. Nothing that came in while it was paused is replayed. Undeploying a paused workflow clears the pause.

## Why a run failed

A failed run says why everywhere it is shown: under its status on the list of workflows, in a "Why it failed" column on the workflow's **All runs** tab (with a **Failed** filter), in a bar above the map when the run is open on it, and on the run's own page. The reason is the run's own error, or else that of the first step that failed; `GET /api/runs` gives it as `error` with `failed_step`, and takes `?status=failed`.

## Undeploying a workflow

Undeploy a workflow you no longer want running with the **Undeploy workflow** button at the top of its page (it asks you to confirm), `xenise undeploy <workflow>` (`delete` is the old name and still works), or `DELETE /api/workflows/:workflow`, which answers `{ "workflow": "<name>", "undeployed": true }`. Undeploying:

- stops its schedule and any other trigger, so no new runs start;
- lets runs already going finish (a run waiting on a question keeps its Workers until the question is answered or closes);
- then removes its Cloudflare Workers. The platform's minute cron does this, and retries if Cloudflare fails. `xenise undeployed` shows where each one's cleanup is;
- keeps its run history and decisions, and its source in Git.

Undeployed workflows don't appear on the screens, and the screens offer no way back. Until a workflow is restored, deploying it is refused. Restoring is an operator action: once cleanup is complete, `xenise restore <workflow>` (`POST /api/workflows/:workflow/restore`, which answers `{ "workflow": "<name>", "restored": true }`, or 409 while cleanup is unfinished) lets it be deployed again. Restoring doesn't deploy it.

Its connections leave the Connections page with it, because that page lists only the connections that live workflows use. Undeploying doesn't change the outbound Worker's Composio settings or disconnect anything in Composio: remove its entries from `COMPOSIO_CONNECTED_ACCOUNTS` / `COMPOSIO_ALLOWED_TOOLS` in `src/cloudflare/wrangler.outbound.jsonc`, and disconnect the account in Composio, if nothing else uses them.

`GET /api/undeployed` (`xenise undeployed --json`, MCP tool `list_undeployed`) lists the workflows undeployed and not restored, so a workflow repository's CI can spot source for a workflow that is no longer live. It needs the same token as `GET /api/workflows`. The answer is HTTP 200 with a JSON array, sorted by name, of exactly:

```json
[{ "workflow": "smoke", "cleanup": "complete" }]
```

`cleanup` is `"pending"`, `"failed"` (retried) or `"complete"`; only `"complete"` can be restored. An empty array means nothing is undeployed. `xenise undeployed --json` writes that array to stdout and exits 0; without `--json` it prints one line per workflow. A restored workflow leaves the list. `GET /api/workflows` and `xenise workflows --json` are unchanged and never include undeployed workflows.

For an explicitly undeployed workflow, `POST /api/versions` returns HTTP 409 with `{"code":"workflow_undeployed","error":"<human message>"}`. `deploy --json` writes exactly one `{"status":409,"code":"workflow_undeployed","error":"<human message>"}` object to stderr, nothing to stdout, and exits 1. Without `--json` the message is human-readable on stderr and the exit code is still 1. Successful `deploy --json` writes JSON to stdout and exits 0. No other failure uses `workflow_undeployed`; CI should treat unrecognized failures as failures.

Deploying, undeploying, runtime republish and cleanup share a per-database lock. A concurrent mutation can be retried. If a Worker invocation is forcibly terminated and leaves the lock held, recovery requires an operator to verify no deployment or cleanup mutation is still in flight before clearing `deployment_lock`; it does not expire automatically because an outstanding Cloudflare write could otherwise finish after restore.
