A loop's budget counts rounds of the loop, not executions of a node
The rule
- A loop goes round again when one of its loopback edges is followed: its round advances by one.
- A loopback edge MUST NOT be followed unless its branch is active and the loop still has budget: either the edge's head is a ForEach node whose iterator has more items (SG-4), or the number of rounds the loop has run is below the configured maximum.
- The rounds a loop has run are counted since its round number (SG-17) was last 0, so they are its round number plus one, and a reset by an enclosing loop (SG-18) gives the loop its whole budget again.
- That bound MUST be kept per loop, keyed by the loop's head.
- The bound MUST count rounds, not executions of any one node in the body.
- The two coincide only on a body where every node runs every round; on a body with a conditional arm, a node that runs on some rounds only lags behind, and counting its executions would let the loop keep going round after the author's budget was spent.
- The round counters MUST be restored when a paused run resumes, so the bound holds across a pause.
What it means
A loop goes round again at one exact moment: when one of its loopback edges is followed. That is when its round advances, and it is the moment the other round rules (SG-18's reset, SG-21's skips) hang on. The budget decides whether it may happen at all.
The budget belongs to the loop, not to any node inside it. A loop with a conditional arm can have a node that only runs on some rounds; counting that node's own executions would under-count the rounds actually spent, and the loop would keep going round after the budget the author set was gone. The round count is kept per loop, identified by the loop's head, precisely so a lagging node inside it cannot buy the loop extra rounds.
The rounds counted are those since the loop's round number was last 0, so a reset by an enclosing loop gives the loop its whole budget again.
The count survives a pause. A run paused mid-loop and resumed later does not start the loop's counter over: the round each loop had reached is recovered, so the same budget that would have applied without the pause still applies after it.
Example
A loop paused mid-run has left five jobs behind for its one loop head, each carrying the round it was stamped with — one carrying no stamp:
[
{"id": 11, "metadata": {"loops": {"reason": 2}}},
{"id": 1, "metadata": {"loops": {"reason": 0}}},
{"id": 12, "metadata": {"loops": {"reason": 3}}},
{"id": 2, "metadata": {"loops": {"reason": 0}}},
{"id": 3, "metadata": {}}
]{"reason": 3}The job with no stamp at all contributes nothing and resets nothing.