# Loop steps

A pipeline is a DAG of typed steps. In the saved graph they are the entries of `nodes`:

```json
{ "version": 1, "nodes": [], "edges": [], "groups": [], "params": {} }
```

Every step is `{"id", "type", "title", "params": {...}}` and every edge is
`{"source", "target"}`. It must be a DAG, and it is validated strictly: a cycle, a
dangling edge or an unknown type is rejected with the reason. How to build and fire one is
in [Run a Loop](../how-to/run-loop.md).

The same graph can live on an ordinary ticket. `run_pipeline(ticket_id, graph)` starts
it there and ends the agent's turn. Optional `pipeline` on the three plan tools attaches
it before approval; Accept then starts it. `start=False` shows a graph for review before
the human presses Start. An active graph can be amended by sending a whole replacement graph: only steps that have not started may change, and a refusal names the started step.

On an owning ticket, spend caps count that ticket's recorded usage, including planning.
Run count caps cannot be exceeded because it executes once; each worker keeps its ordinary
ticket budget. A kill switch with scope `loop` stops this one execution instead of disabling
a recurring schedule that does not exist.

An owning ticket prepares its working branch before dispatch, even if its planning turn
was read only. Shell steps and tooled agent steps use that working checkout. Scheduled
runs of a scheduled Loop retain their original directory behavior.

## Step types

The `type` of a step is one of these stored values. Two of them have plain names in the
rest of the docs: a step of type `gate` is a step for you (kinds `human_approval` and
`human_task`), a review (`adversarial_review`) or a stop (`kill_switch`), and a step of type
`sink` is an output step, called the landing step when it is the `kanban` `merge` one.

| Type | What it does |
| --- | --- |
| `trigger` | Entry point: a schedule, a webhook or an event. It must have no inbound edges. Optional: a run fired by hand starts at the first source anyway. |
| `source` | Reads the outside world: GitHub, Jira, Slack, or the board itself. Deterministic code, no agent. |
| `transform` | A pure filter, map or passthrough over a list of items. No agent. |
| `script` | Arbitrary Python (the `code` param), run out of process in a sandbox with the network denied by default. The escape hatch when no other step fits. See [The script step sandbox](#the-script-step-sandbox). |
| `shell` | Runs a command. The only step that may leave a detached process running (with `detach` and a `ttl_s`) for a later step to use or stop. |
| `agent` | One bounded, tool-less model turn over its upstream inputs. `for_each` fans it out over a list, bounded by `max_items` and `concurrency`; `sandbox: false` widens it to a multi-turn, fully tooled turn, which then also requires `max_turns` and `timeout_s`. |
| `subticket` | Dispatches a real child ticket run with its own worktree, branch, model and permission gate. Params: `title`, `scope` (its brief), `model`, `mode` (including `spa_plan`), `merge_into_parent`, `base`, plus `human_approval`, `repo_root`, `base_branch`, `ticket_id` and `pipeline`; see [Repositories, phases and adoption](#repositories-phases-and-adoption). |
| `gate` | By its `kind`: `human_approval` parks the run for a human, asking its `message`, with the files named in `approve_files` (left out: every file of the steps before it; `[]`: no files) and Approve or Decline; `adversarial_review` has a reviewer on a different canonical model id sign the work off before it continues; `human_task` asks a person to do a real world step in the ticket's browser and answer a typed form; `kill_switch` aborts. |
| `sink` | The output step, a terminal write-back: a comment, created tickets, a published report, or out to GitHub, Jira or Slack; `kanban` `merge` lands the run's children in a branch. It must have no outbound edges. |

Put a `human_approval` step before anything irreversible.

### Models and review verdicts

Every `agent` step, `subticket` step and `adversarial_review` can name any catalog model.
The model selects its engine, including for tooled agent steps and reviewers. Unknown
models are refused with the step id and the accepted forms. Claude aliases and ids with
the configured `gpt-`, `codex-`, `cursor/` and `agy/` prefixes are accepted too.

A reviewer must differ from **every upstream producer**, including subticket children
and producers behind transforms. The comparison uses canonical model ids: an alias and
its current catalog id are the same model, but two versions in one family may review
each other. The child's recorded run model takes precedence over its requested model.
The check runs both when saving literal models and when executing resolved models.

The reviewer returns `{"verdict":"pass","reasons":"..."}` or the same object with
`"fail"`. Only that object decides the review. Missing or invalid JSON fails closed;
mentioning failed checks in the reasons cannot turn a pass into a fail. Full reasons
are retained on the record of the review. Claude and Codex app server enforce the schema;
Antigravity uses its CLI schema option rather than ACP. Cursor and Codex exec responses
are validated by the board against the same verdict contract.

Claude review tools run in process; other engines reach the same paged, scoped tool
tables over stdio. A Codex reviewer is read only, not tool less: it may also read files
in the execution checkout. Scoped board writes still address only the owning ticket
or the scheduled Loop and its run. A scoped `request_action` parks the run and stops
the step after its turn. Dry runs do not write or park.

Settings, **Models & runs**, has one worker model picker per provider. A blank model
on a child of a lead agent uses its lead agent's provider row; a blank row inherits
the lead agent's model. Defaults are Sonnet for Claude and the newest catalog Terra
for Codex; Cursor, Gemini and Mistral Vibe inherit. Existing worker settings are migrated into the
Claude row. Explicit child models always win.

Every real agent turn, fan out item and review records usage on the execution ticket,
with its model and engine. Step records also show model, engine, tokens and reported cost.

### Usage cap fallback models

Loops inherit the existing subscription fallback settings from their board, including
the global defaults, enable switch and recovered provider return policy. The same
quota, authentication, installed model validation and saved order are used for both
ordinary ticket runs and Loop agent turns. Full subscriptions are skipped as a whole;
unknown quota is not permission to select a new provider.

To override only the model list, open **Fallback models** in the Loop graph editor,
choose **Override fallback models**, then **Save graph**. This stores
`loop_pipeline.params.fallback_models`, for example `["gpt-6.1-sol"]`. An explicit
empty list disables this Loop's fallback list; **Use board fallback settings** removes
the override. Each step's explicit model, or the board default when unset, remains its
primary preference. Changing the run's chat model does not override pipeline steps.

On a usage cap, the turn uses the shared selection and recovery mechanism, rebuilding
provider options while keeping its tools, permissions, output schema and original timeout.
This covers ordinary agents, fan out items and review turns. A reviewer cannot use
any producer's actual model, including models used by different fan out items.

There is no replay after a tool call, while waiting on a person, or on a task or
authentication error. Short term rate limits retain the existing transient retry
policy. Recovery state survives Loop checkpoints. If all eligible models are capped,
the step fails with its checkpoint intact. The run timeline records each switch and
each attempt's usage; the step record shows the actual final model and provider.
The Loop's list override does not alter child ticket runs or the run's chat.

## Edges

Edges are the execution order, and the only thing that creates it. Two `subticket` steps
with no path between them are dispatched back to back and their children run
**concurrently**. To make the pipeline wait, give them a shared downstream step: the run
parks on the join and resumes when the children land, with each child's whole
hand-off (status, repository, branch, artifacts and the full summary) bound as that step's input. Parallel by default, sequential where you draw an
edge.

An edge between two `subticket` steps also carries the **code** by default: the later
child branches off the earlier one's branch, so its worktree already contains its
predecessor's commits. A step that depends on two earlier steps takes the first as its
base and is told, in its brief, to merge the other. A step with no upstream subticket
starts from the lead agent's branch. The `base` param decides this per step:

| `base` | The step starts from |
| --- | --- |
| omitted or `chain` | The previous step's branch, inheriting its commits. |
| `orchestrator` | The lead agent's branch. It still receives its predecessors' summaries as context, but not their code. Use it for independent attempts at one problem, or a review that should read a clean tree. |
| `{"from": "<node id>"}` | The named predecessor's branch, for a step with several; the others are still listed in its brief to merge. |

A `shell` or `script` step runs in the repo checkout, not in a worktree holding the
children's unmerged work, so it cannot verify the combined result. That happens after the
children's branches are merged.

## Reviewing and landing subticket work

A `subticket` step's result is `{id, key, title, status, repo_root, branch, artifacts, summary, report_pointer, pipeline_status, model, engine}`. It is bound only
once the child is In Review **and** its verification checks passed at its latest commit
(or were overridden). `summary` is the complete report the child passed to `finish_ticket`; it is never clipped
for downstream steps, and card previews are labelled as previews.

An `adversarial_review` over subticket steps reads the same whole hand-off. Its reviewer
gets an index (each child's report size, commit count and check status) and four paged,
read-only tools: `read_handoff`, `list_commits`, `read_diff` and `read_checks`. It holds no
other tools on Claude; other engines retain their read only native tools. When it fails and an agent awaits the Loop, the run parks at the review and the
agent is woken with the findings; it answers with `answer_review(ticket_id, run_id,
action)`, where `action` is `return` (with `feedback`), `accept` or `review_again`.
On an owning ticket, `ticket_id` and `run_id` are the same ticket. Worker questions and
failed reviews wake that ticket's agent; `resume_loop_run` hands control back to the graph,
also after `answer_review` on an owning ticket.

The landing step, the `kanban` `merge` step of type `sink`, says where the finished work goes:

```json
{ "provider": "kanban", "operation": "merge", "into": "orchestrator" }
```

`into` is `orchestrator` (the owning ticket's branch for a one shot pipeline, or the
branch of the ticket above a Loop a lead agent dispatched) or a branch name.
Every child of the run in In Review or Done is merged there, in dispatch order, through
the board's integration pass; a child already contained is skipped. Merging into `main` or
`master` needs an approved `human_approval` step directly before the landing step.

For an owning ticket, the closing agent turn waits for these queued merges to actually
land, then tests the combined work. It is not another pipeline execution.

## Repositories, phases and adoption

These `subticket` params let one plan span several repositories and phases:

| Param | Meaning |
| --- | --- |
| `repo_root` | A known repository: the owner's, the board default, or a primary clone under the repos root. Unknown roots, subdirectories and linked worktrees are refused. Paths are canonicalized when the graph is saved. |
| `base_branch` | The branch the step starts from and lands in. It must exist in the selected repository. |
| `ticket_id` | Adopts that exact direct Backlog child of the owner. It keeps its identity, session and branch, takes no other step params, and is queued only when its dependencies are ready. |
| `pipeline` | An inline graph that makes the step a **phase**: its own ticket, branch and executor with no free form agent turn. It merges its workers, passes verification, then counts as done. |
| `mode: spa_plan`, `human_approval` | A worker that files an interactive plan. With `human_approval` only a human can approve it, never the lead agent. |

Work in another repository lands in that repository's target, never in the owner's branch,
and only predecessors in the same repository supply a code branch. Phases nest up to
**pipeline depth** (two levels by default). **Max orchestration children** counts steps
outstanding at once per level, with no ceiling on the graph. A graph larger than that
setting, or one naming a repository, asks once for human signoff before anything runs; an
amendment that changes it asks again.

A `human_task` step carries `instructions`, an optional `page_url`, a `checklist` and typed
`fields` (`text`, `textarea`, `number`, `boolean`, `select`). Its answers flow to every
downstream step. A repository is signed before work starts, so `repo_root` cannot read the
answer of such a step.

## The script step sandbox

A `script` step's `code` runs with these names bound, and whatever it assigns to `result`
becomes the step's output. An exception fails the step.

| Name | Holds |
| --- | --- |
| `inputs` | Every upstream step's output, by step id. |
| `input` | The output of the only upstream step. |
| `items` | `input` as a list. |
| `params` | The step's own params. |
| `result` | `None` until the script sets it. |

How it is isolated is **Loop script step sandbox** in **Settings > Features > Loops**:

| Mode | Isolation |
| --- | --- |
| `srt` (default) | Anthropic's sandbox runtime: Seatbelt on macOS, bubblewrap with a network namespace and seccomp on Linux. Falls back to `subprocess` by itself when the runtime or Node.js is missing, or fails a test run. |
| `subprocess` | A separate process with the limits below, and no filesystem or network isolation. |
| `off` | Runs inside the board's process with no isolation. Not recommended. |

Under `srt`:

| Resource | Policy |
| --- | --- |
| Network | Denied. The only domains a script may reach are the board's allow list, `loop_script_sandbox_network_domains`, which is empty by default (no network at all). It has no control in the Settings dialog: seed it with `REV0_LOOP_SCRIPT_SANDBOX_NETWORK_DOMAINS` (comma separated, for example `api.github.com,pypi.org`) or set it through the settings API. |
| Reads | Nothing under your home directory, except the step's throwaway workspace and the Python installation. |
| Writes | Only the throwaway workspace. |
| Environment | Only `PATH`, `HOME`, `TMPDIR`, `TMP`, `TEMP`, `LANG` and `LC_ALL` are passed through. No tokens. |

In every mode but `off`:

| Limit | Value |
| --- | --- |
| Wall clock | 30 seconds, or the step's `timeout_s`. The whole process group is killed on timeout. |
| CPU time | 20 seconds. |
| Memory | 512 MB, best effort (macOS often does not enforce it). |

The step's result starts with `[sandbox=` and the mode that actually ran, so a fallback to
`subprocess` is visible.

## Pipeline params

- `groups` draw visual phases in the editor.
- `params.resource_caps` bounds the Loop: max runs, tokens, cost, and wall clock per run.
- `{"from": "<node id>", "field": "<key>"}` in any step's param reads an upstream step's
  output.
- `params.goal` turns the Loop into a Goal; see [Loops and Goals](../explanation/loops-goals.md).
