# Join branches, merge values and repeat safely

Choose explicit branch completion rules and bounded Repeat / Until bodies without cyclic wires.

Canonical URL: https://opennodeflow.dev/wiki/control-flow/
JSON reference: https://opennodeflow.dev/wiki/control-flow/index.json
Source snapshot: 2026-10-23

Ordinary ONF nodes wait for all incoming predecessors to settle and use OR selection across control wires. Explicit control-flow operations provide different completion rules. Graph wires still form a directed acyclic graph; repetition uses a container with a published body.

## Choose the correct join

| Join | Eligibility |
| --- | --- |
| Join all branches | Every incoming branch finishes successfully and selects its connected route |
| Join first completion | First successful selected route or actual branch failure |
| Join first success | First successful branch selecting its connected route |

Connect branch endings to the join's exec input. First joins admit downstream work as soon as a winner exists. Skipped, cancelled and unselected routes cannot win. `winnerNodeId` identifies the source and `winnerStatus` records its status; all-branches uses an empty winner ID and success.

Other branches **continue running**. A first join does not cancel requests or undo writes. An unhandled losing-branch failure still fails the overall run, and the run becomes terminal only after remaining active branches settle. Use explicit handled error routes when a failure should be absorbed.

## Merge mutually exclusive data

Merge selected branch pairs branch control with value inputs. A pair is eligible only after its selected successful control route and its wired value are both available. The first eligible completed pair emits `value`, one-based `branch`, `winnerNodeId` and next. Missing data on unselected alternatives does not block it.

The shipped dynamic merge supports eight pairs. Create typed merge publishes two to eight alternatives with one exact primitive or custom type/version. Optional value inputs remain optional; the selected output is required and validated. Pair related control/data deliberately—the merge does not infer business correlation.

## Repeat / Until

Publish a subflow with a carry input, result output of the **identical exact type/version**, and separate boolean stop output. Optionally expose a numeric index input. Other required body inputs need defaults. Create Repeat / Until pins that body and chooses a maximum between 1 and 1,000 iterations.

The body runs at least once. Index starts at zero; result becomes the next carry. Boolean true stops. Outputs include final `value`, executed `iterations` and `stopped`. Reaching the maximum is a successful bounded result with `stopped:false`; a missing result, nonboolean stop or unhandled failure fails the container.

## Bounds and recovery

One absolute outer deadline includes nesting, queue admission and execution. Collections/repeats in the tree share 10,000 item/iteration and 50,000 body-node visit budgets. Recursive bodies and durable waits anywhere inside Repeat are rejected. Whole-container retries are also rejected; individual body nodes retain their chosen retry policy.

On cancellation, further iterations stop and active workers are aborted. An external effect already accepted elsewhere may remain uncertain. Interruption does not automatically replay the container. Inspect retained iteration progress and storage provenance before any deliberate retry.

Safe debugging pauses before an unmocked container. A real step executes the bounded body normally. Put [durable waits](/wiki/durable-waits/) outside these containers and inspect [run storage history](/wiki/run-storage-history/) to reconcile committed mutations.

---

## Documentation provenance

- `docs/CONTROL-FLOW.md`
- `docs/SUBFLOWS.md`
- `docs/COLLECTIONS.md`
- `docs/AUTHORING.md`

This page describes maintained source, not a live inventory or an authorization to perform actions.
