A ForEach node initializes its iterator once and completes on an empty list
The rule
Normative: this is the rule
- A ForEach node initializes its iterator on the round where the state carries none, and requires items to iterate.
- A value that is not a list is wrapped as a single item, and the items are re-indexed so that iteration is positional.
- An empty list completes the node immediately rather than entering the loop.
- On completion the node emits its defined output set, including the results collected across the rounds it ran.
What it means
An empty list is not a loop that runs zero times — it is completion on the first round, with the node's whole defined output set produced immediately, current item included as absent rather than left unset. A value that is not a list at all is not refused either: it is wrapped as the one item a single round iterates, re-indexed the same way any list would be, so a round that receives a bare scalar behaves exactly like a round over a one-item list.
Example
{"items": []}{"loop_active": false, "current_item": null, "total_count": 0, "collected_results": []}{"items": "scalar_value"}{"current_item": "scalar_value", "current_index": 0, "total_count": 1, "is_first": true, "is_last": true}Rule identifiers are permanent and are never renumbered. Each implementation publishes its own standing against these rules; this specification does not.spec 1.0-draft · SG-4 · changed in spec 1.0