> ## Documentation Index
> Fetch the complete documentation index at: https://docs.canary.effectiveai.app/llms.txt
> Use this file to discover all available pages before exploring further.

# parallel node

> Run a fixed set of independent branches at the same time, and continue when all of them finish.

A `parallel` runs two or more heading bodies, its branches, at the same time. The run continues
past it only when every branch has finished: this is the join. Use it for independent work over
the same inputs, such as reading billing while underwriting reviews the policy. Use
[`for-each`](https://docs.canary.effectiveai.app/procedures/reference/nodes/for-each) to run the same steps over a list.

## Syntax

```yaml parallel id=check-in-parallel theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
branches:
  billing: '#confirm-balance'
  underwriting: '#underwriting-review'
join: all
on_branch_failure: fail-fast
outputs:
  balance:
    schema: balance
  uw_decision:
    schema: uw-decision
```

## Fields

| Field | Type | Required | Default | What it does |
| - | - | - | - | - |
| `branches` | mapping | Yes | None | At least two entries. Each key is a branch ID in kebab-case; each value is a quoted `'#block'` child heading |
| `join` | string | No | `all` | When the parallel finishes. Only `all` is accepted: it finishes when every branch has finished |
| `on_branch_failure` | string | No | `fail-fast` | What a failing branch does. Only `fail-fast` is accepted: the first failure fails the run |
| `outputs` | mapping | Yes | None | The values later steps can read, each with a `schema`. Each one is bound by exactly one branch |

The fence takes no attributes after `id`, and its body takes no other fields.

### The join

There is no join fence and no list of branches to wait for. The join is part of the `parallel`
itself and always covers every declared branch, so adding a branch can't leave it out of the join.

When a branch finishes, its outputs are held back. No other branch, and no later step, can read
them yet. When the last branch finishes, all declared outputs become visible together, and the run
continues at the next heading.

### Branches

* Branch IDs are your stable names for the branches. Reordering the mapping or moving the
  headings doesn't change the identity of the branches or of the steps inside them.
* Each branch is a direct child heading of the section, following the same
  [heading rules](https://docs.canary.effectiveai.app/procedures/reference/nodes/choice.md#heading-bodies) as a `choice`. The
  `parallel` is the last fence in its section.
* Two branches can't use the same heading.
* A branch can hold any steps, including tasks, agents, waits, and nested `choice`, `repeat`,
  `for-each` or [module](https://docs.canary.effectiveai.app/procedures/reference/nodes/include.md#modules) inclusions. Several of them
  can be waiting at once.
* A branch can read values from before the `parallel`, but not another branch's values. Branches
  may reuse the same local names.
* `complete` isn't allowed in a branch, including through a choice case that ends the run. Route
  on the joined outputs after the `parallel` instead.

### Outputs

Each declared output is owned by one branch. That branch must bind it on every path through the
branch, and no other branch may bind it. Values a branch binds that aren't declared outputs can't
be read after the `parallel`.

A task or agent output is an envelope. To hand on only the answer, bind it with a
[`value`](https://docs.canary.effectiveai.app/procedures/reference/nodes/value) node, as in the example below.

## Example

Before cancelling a policy, confirm the balance in billing and ask underwriting whether anything
blocks the cancellation. The two don't depend on each other, so they run at the same time. The
host, group and policy values are illustrative.

````markdown cancellation-prep.procedure.md theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
---
kind: procedure@v0
id: cancellation-prep
inputs:
  policy_number: { type: string }
outputs:
  result: { schema: prep-result }
---

# Cancellation prep

Confirm the balance and get underwriting's view at the same time.

## Check billing and underwriting

The billing read and the underwriting review don't depend on each other, so
they run at the same time. The next section starts when both are done.

```yaml parallel id=check-in-parallel
branches:
  billing: '#confirm-balance'
  underwriting: '#underwriting-review'
join: all
on_branch_failure: fail-fast
outputs:
  balance:
    schema: balance
  uw_decision:
    schema: uw-decision
```

### Confirm the balance {#confirm-balance}

```yaml call id=call-billing
function: '@local.read-balance'
input:
  policyNumber: $inputs.policy_number
output: balance
```

### Underwriting review {#underwriting-review}

```yaml task id=uw-review
assignees: [group:underwriting]
title: 'Any reason not to cancel {{ $inputs.policy_number }}?'
instructions: Check for open claims or a pending endorsement on the policy.
result:
  schema: uw-decision
output: uw_review
```

```yaml value id=bind-uw-decision
schema: uw-decision
output: uw_decision
value: $uw_review.value
```

## Combine the results

```yaml complete id=finish
value:
  amountDue: $balance.amountDue
  proceed: $uw_decision.proceed
```

## Resources

```yaml schema id=policy-request
type: object
additionalProperties: false
required: [policyNumber]
properties:
  policyNumber: { type: string }
```

```yaml schema id=balance
type: object
additionalProperties: false
required: [amountDue]
properties:
  amountDue: { type: string, format: decimal }
```

```yaml schema id=uw-decision
type: object
additionalProperties: false
required: [proceed]
properties:
  proceed: { type: boolean }
  note: { type: string }
```

```yaml schema id=prep-result
type: object
additionalProperties: false
required: [amountDue, proceed]
properties:
  amountDue: { type: string, format: decimal }
  proceed: { type: boolean }
```

```ts effect id=read-balance input=policy-request result=balance uses=fetch
async (request, { fetch }) => {
  const response = await fetch(
    `https://billing.northwind.example/balances/${request.policyNumber}`
  );
  if (!response.ok) throw new Error(`Billing returned ${response.status}.`);
  return { amountDue: '412.50' };
};
```
````

The effect returns a fixed amount to keep the example short. A real effect would parse the
response from your billing system.

The billing read usually finishes long before underwriting answers. Its `balance` stays held back
until the task is answered. Then both outputs appear and the run completes.

## On retry and resume

* **Each branch is its own step.** The same step in two branches has two identities, so each
  branch's calls, tasks and agent sessions run once for that branch.
* **Finished work isn't repeated.** On resume, branches keep the results they recorded, and only
  unfinished work continues. Results that arrive in any order are matched to the step they belong
  to.
* **All or nothing.** Outputs appear only when every branch has finished, all together. If any
  branch fails, the run fails with that first failure: the other branches stop, their pending
  steps accept no more results, and no output appears. A write that another branch already sent
  may still reach your system; failing the run doesn't undo it.
* **Expected problems are data.** A branch that might hit an expected problem, such as a policy
  that billing can't find, should return it as data, for example a `status` member, and let a
  `choice` after the `parallel` route on it.

## Common errors

| Code | Cause | Fix |
| - | - | - |
| `PROC-PARALLEL-001` | Fewer than two branches, a branch ID that isn't kebab-case, an unquoted target, two branches using one heading, empty `outputs`, or a `join` or `on_branch_failure` other than `all` and `fail-fast` (`join admits only "all"`) | Declare at least two branches with their own headings, and leave out `join` and `on_branch_failure` or set the defaults |
| `PROC-PARALLEL-003` | A branch can end the run (`complete is not permitted inside a parallel branch.`) | Complete after the `parallel` |
| `PROC-PARALLEL-004` | An output is bound by no branch or by several (`Output "balance" is bound by more than one branch (billing, underwriting).`), or its branch doesn't bind it on every path | Bind each output in exactly one branch, on every path |
| `PROC-REGION-001` to `PROC-REGION-003` | A branch heading is missing, misplaced or used by another construct | Follow the [heading rules](https://docs.canary.effectiveai.app/procedures/reference/nodes/choice.md#heading-bodies) |

## See also

* [for-each node](https://docs.canary.effectiveai.app/procedures/reference/nodes/for-each.md): the same steps for every item of a list
* [choice node](https://docs.canary.effectiveai.app/procedures/reference/nodes/choice.md): route on the joined outputs
* [fragment and module nodes](https://docs.canary.effectiveai.app/procedures/reference/nodes/include.md)
* [task node](https://docs.canary.effectiveai.app/procedures/reference/nodes/task.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.