# Run a Loop

A Loop is a ticket that runs a pipeline, on a schedule, when you click **Run now**, or when an
event arrives. The pipeline is a graph of steps (agents, child tickets, reviews, steps for you, commands) that
you see and edit before anything runs. Each time it fires, the Loop starts a **run**: a ticket
of its own, listed in the Loop's history.

For when a Loop is worth it at all, see [Which tool when](../explanation/which-tool-when.md);
for every type of step, see [Loop steps](../reference/loop-nodes.md).

A plan that runs once uses the same graph **on its own ticket**, not a Loop and a run of it.
Accept starts a graph carried by the plan. Execute by loop asks that ticket's agent to
draw a missing graph, then waits for you to press Start. See [Split big work](split-work.md).
Schedules, events, Goals and existing Loop histories keep their separate runs.

## Before you begin

- A working directory for the Loop if its steps touch code, as for any ticket.

## Create a Loop

1. Click **Create** and set **Type** to **Loop (runs on a cron schedule)**.
2. Set **Schedule**: **Every day**, **Every X days**, **Specific weekdays** or **Specific
   hours**, then the times (**At**) and the **Timezone** (your browser's by default).
3. Describe what each run should do in the description, as you would for a ticket.
4. Click **Create**.

**Result:** the Loop is created and drafts its pipeline from your title and description. It
fires on its schedule from then on. To create a Loop that runs only when you ask, uncheck
**Enabled** in its **Schedule** tab once it exists.

A report from the **Report library** with **Schedule** makes a Loop the same way ([Run a repo
report](reports.md)).

## Edit the pipeline

![A Loop pipeline in the full screen editor: a trigger, a source, three subticket steps side by side, an agent, a review, a step for you and an output step](img/loop-editor.png)

The **Loop pipeline** section shows on the Loop's **Schedule** tab.

1. Click **Expand** to open the full screen editor.
2. Click **+ Step** and pick a type. The step lands in the middle of the canvas.
3. Drag from one step's handle to another's to wire them. Edges are the order: two steps with
   no path between them run at the same time.
4. Click a step to edit it: its **Title**, **Type** and **Params** (**+ Add param...** lists
   the params that type takes, required ones marked). The trash icon, or Backspace, deletes it.
5. Click **Save**. **Cancel** puts the graph back as it was.

**Result:** the next run uses the saved graph. Save refuses a graph with a cycle; a graph that
saves but cannot run yet shows **Saved, but not runnable yet** with the reasons.

Two other buttons redraw the whole graph from the description: **Draft from intent** on an
empty pipeline and **Regenerate** on one that has steps. Both replace what is there, and
**Clear** deletes it.

> [!TIP]
> Put a step for you (type `gate`, kind `human_approval`) before any step that writes to the outside world (a comment on a
> pull request, a Slack post, a merge). The run parks there until you approve.

## Start from a template

The board ships three pipeline templates: **PR review** (read-only by default), **Jira
triage** (waits for your approval) and **External intake** (poll something and file the new items as
tickets). There is no template picker on the form yet: ask an agent, for example in a chat,
to "create a Loop from the pr-review template for `owner/repo`". Its `create_ticket` tool
takes the template and its parameters.

**Result:** a Loop with the template's pipeline, which you then edit like any other.

## Run it now

1. Open the Loop's **Schedule** tab.
2. Click **Run now**.

**Result:** a run starts straight away, whatever the schedule, even while the Loop is paused.
If a run is still going, the board asks first: **Run anyway** starts a second one in parallel.

## Read the run history

![A Loop's Schedule tab: the latest run banner, a tab per run, the schedule with Enabled and Run now, and the Head start and Auto-archive fields](img/loop-history.png)

Each run has a tab next to **Schedule**, newest first, with a status dot and its date. The
banner at the top links the latest one (**Open**). In a run's tab:

- **Pipeline progress** draws the graph with each step's state: done, running, approve, error or
  blocked.
- **Result** shows the report the run published, if it made one, and below it each step's
  result and the run's timeline.
- **Open full run** opens the run as a ticket, and **Resume this run** queues it again.

On the board, the Loop's card sums it up: **running**, **armed** (waiting for its next
time), **paused**, **your turn**, or how many runs are waiting on you.

**Result:** you see what every run did and which ones wait on you.

## Approve a step

A step that asks for your approval (kind `human_approval`) parks its run in Your turn and
the Loop's card reads **your turn**.

1. Open the run (from the Loop's history, or the card in Your turn).
2. Read the draft under **Approval needed:** and the title of the step.
3. Click **Approve & continue**, or **Reject**.

**Result:** approving resumes the run from that step, without re-running the steps you reviewed.
Rejecting ends the run there: nothing after that step runs.

For a pipeline on an ordinary ticket, those buttons are on that owning ticket, on the
**Activity** and **Steps** tabs. There is no run to open. A worker waiting on an answer is linked from the same graph.

## Do a human task

A task for you (kind `human_task`) asks you for the one thing only you can give, and says which with its
`ask_kind`: a sign in, a second factor, a payment, a consent, a decision, an approval or a
look at a result. It parks the run in Your turn like an approval, on the ticket (or phase)
that holds it, and you can answer it from the inbox too. Console work is never a step for
you: creating accounts, projects, databases, keys or DNS records is an agent's job, and a
pipeline whose step for you lists such chores is refused when it is saved.

1. Open the task from the owning ticket's **Steps** tab. A task inside a phase links to the phase that holds it.
2. Read the instructions. If the task has a page, click **Open page**: it opens on that
   ticket's own browser, where you sign in yourself. Never type a password or code into a field.
3. Tick the checklist, fill the fields and click **Submit**.

**Result:** the run resumes and every later step receives your answers. A refused answer
(a missing required field, a wrong type) shows under the form and keeps your draft.

## Head start and auto archive

Both are on the Loop's **Schedule** tab; click **Save schedule** after changing them.

- **Head start**: the schedule's times are when you need the result. With a head start of 30,
  each run starts 30 minutes earlier, and a due alert fires at the scheduled time. 0 means no
  head start and no alert.
- **Auto-archive**: how long after it fires a finished run leaves the board for the Loop's
  history, in minutes, hours or days. 0 keeps it on the board until the end of its day.

The board-wide default is **Archive finished Loop runs** in **Settings > Features > Loops**:
**immediately**, **end of its day** (the default), **never**, or after an hour to 30 days. A
Loop's own **Auto-archive** overrides it. A run waiting on you (Your turn or In Review)
never leaves the board by itself.

**Result:** finished runs leave the board when you want, and stay in the Loop's history.

## Fire on an event instead of a clock

A trigger step can fire the Loop when something happens instead of (or as well as) at a time:

| `source` | `event` | Fires when |
| --- | --- | --- |
| `github` | `pr_opened` | A pull request is opened. |
| `jira` | `assigned` | An issue is assigned to you. |
| `ci` | `ci_failed` | A CI run fails (webhook only). |

1. In the pipeline editor, click the trigger step (or add one with **+ Step**).
2. Add its params with **Add custom param**: `kind` set to `event`, then `source`, `event`,
   `delivery` (`poll` or `webhook`) and, optionally, a `filter` on `repo`, `branch`,
   `author`, `assignee`, `project` or `labels` (all must match).
3. Click **Save**. The Loop must stay **Enabled**: a paused Loop fires on nothing.

For example, to run on every pull request opened on one repo:

```json
{
  "kind": "event",
  "source": "github",
  "event": "pr_opened",
  "delivery": "poll",
  "filter": { "repo": "owner/repo" }
}
```

**Polling** needs nothing else: the board checks every 5 minutes (`REV0_LOOP_POLL_INTERVAL`).
A GitHub poll needs `filter.repo`.

**Webhooks** fire at once but need the board reachable from the sender and a secret to sign
with (`REV0_WEBHOOK_SECRET`, or the access token when that is unset). Each Loop gets its own
URL, `/hooks/loop/<id>/<source>/<token>`: ask an agent on the Loop for it, or read it from
`GET /loops/<id>/triggers` on the board's API. GitHub deliveries must be signed with the same
token (the webhook's **Secret** field on GitHub).

**Result:** each matching event starts one run; the same event never fires twice.

## Let an agent lead one

An agent working a ticket can split independent strands into a pipeline on that ticket,
when **Agent orchestration** is on ([Split big work into
subtickets](split-work.md#let-an-agent-orchestrate)). It calls `run_pipeline` and stops.
Workers become its direct subtickets and start from its own branch. A landing step merges
them there; the agent then gets one closing turn to test the combined result. The pipeline
renders live on the **Steps** tab of that ticket.

The older create Loop, save graph, fire a run and await Loop calls still work for scheduled
or event Loops and older split work. They are not needed for a plan that runs once.

A plan can also hold phases (a step with its own inline graph), steps in other known
repositories and adopted tickets. A graph that is larger than the concurrency setting, or
that names a repository, asks you once to press **Start** before anything starts, and asks
again after an amendment that changes it. A running graph can be amended: only steps that
have not started can change, and a refusal names the started step.

When the graph ends on the landing step (a `kanban` `merge` step of type `sink`), every
child's work is already queued into the branch that step names (usually the lead agent's
own); otherwise the lead agent lands each child itself. A step for you of kind
`human_approval` parks the run until you approve it.

## How a pipeline finishes on its own

- **A child is finished when its checks are.** Reaching In Review is not enough: the
  pipeline binds a child only once its verification checks have passed at its latest
  commit (or a human overrode them). A child sent back by a failing check is waited for.
- **The hand-off is recorded, not guessed.** A dispatched child passes its report to
  `finish_ticket`, even on a board with final summaries off. That report is the step's
  result; a later comment such as "fixed lint" does not replace it.
- **The reviewer reads everything.** An `adversarial_review` of subticket steps gets an
  index of the children and pages through each one's whole report, commits, diff and
  check results, read from the board when it runs.
- **A failed review goes to the lead agent.** When an agent awaits the Loop, a failed
  review parks the run at the review with its progress kept and wakes that agent with the
  reviewer's findings. It answers with `answer_review`: `return` sends the reviewed
  children back with feedback and reviews their next landing, `accept` passes the review,
  `review_again` re-runs the review on what the board holds now. A `return` can name the
  steps that must change, each with its own feedback: the others keep their landing and
  are reviewed again with them. With nobody awaiting, the run parks for you as before.
- **A chain is reviewed as one result.** Steps built one on the other are read as one
  diff, the last branch against the branch they land in, each with its own hand-off. A
  fix asked of an earlier step can sit on the last branch.
- **The pipeline says where its work lands.** The landing step, a `kanban` `merge` step with
  `"into": "orchestrator"` (or a branch name), merges every child of the run there. It
  only runs if the pipeline reaches it, so a failed review lands nothing.

## If something goes wrong

Each step's catalog model selects its own engine. For a review, choose a different
canonical model id from every upstream producer, even when the models share a family.
The review returns a JSON verdict; a missing or malformed verdict stops the pipeline.
Set worker defaults per provider in **Settings, Models & runs**. A blank provider row
inherits the lead agent's model. See [Models and review verdicts](../reference/loop-nodes.md#models-and-review-verdicts).

### A run is already in progress

**Run now** found a run still going. **Run anyway** starts a second one in parallel; otherwise
wait for the first to finish.

### Can't save

The graph is not a DAG, or an edge points at a step that no longer exists. The banner says
which. A trigger must have no inbound edge and an output step no outbound edge.

### Couldn't draft the Loop

Drafting a pipeline calls a model. Write a clearer description and try **Draft from intent**
again, or build the graph with **+ Step**.

### webhooks are disabled

The board has no secret to sign webhook URLs with. Set `REV0_WEBHOOK_SECRET` (or an access
token) and restart the board.

## Related

- [Loop steps](../reference/loop-nodes.md), for every type of step and its params.
- [Run a Goal until it is done](run-a-goal.md), for a Loop that runs until its objective is met.
- [Loops and Goals](../explanation/loops-goals.md), for when a Loop pays off.
