Skip to main content
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 to run the same steps over a list.

Syntax

parallel id=check-in-parallel

Fields

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 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 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 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.
cancellation-prep.procedure.md
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

See also