Skip to content

A loop's extent is fixed at launch and every execution carries its rounds

The rule

Normative: this is the rule
  1. A run MUST compute its loops once, when it starts, and MUST work from that result, and from the graph it was computed on, for the rest of its life.
  2. Terms used by every round rule: a loop's round number counts, from 0, how often the loop has gone round again (SG-7) since the run started or since a loop enclosing it last went round again and reset it (SG-18).
  3. A job that enters a loop from outside it takes that loop's current round number (SG-21); entering does not reset the counter.
  4. The run keeps each loop's current round number as that loop's round counter; together the counters are the current rounds.
  5. A job's stamp gives its round number on each loop of its node, and a job's round is its stamp.
  6. A round of a loop is that loop's round number together with the round numbers of the loops enclosing it.
  7. Every job MUST carry a stamp from the moment it has a round (SG-21), whether or not it ever runs, with one entry per loop of its node, including round 0, and an empty stamp for a node in no loop.
  8. When a paused run resumes, its round counters MUST be rebuilt outermost loop first, from the stamps of every job of the run, whether the job has run or not.
  9. Each loop's counter MUST be its entry in the greatest stamp, ordered as SG-19 orders rounds, among the stamps that name the loop and agree with the counters already rebuilt for the loops enclosing it, or 0 where no stamp does.
  10. A counter MUST NOT be rebuilt as the highest round number recorded for its loop alone.

What it means

A run's loops are computed once, at launch, and the run works from that result for the rest of its life. An author who edits the workflow mid-run cannot redraw the body of a loop that is already several rounds deep.

The graph the loops were computed on is fixed with them. SG-21 asks what a live job can still reach, and that answer must come from the same graph the bodies came from, not from an edited copy.

A loop's round number is not reset when work enters the loop from outside: only a loop around it going round again resets it (SG-18). A loop that is not nested in the loop feeding it is therefore entered at whatever round it has reached; giving each entry a fresh pass is an open question (DEFERRED.md).

Every execution of every node carries a stamp of the rounds it belongs to, one entry per loop — including an empty stamp for a node in no loop, and including round 0 explicitly, so an absent entry can never be read as either "outside every loop" or "inside one at round 0".

When a paused run resumes, its round counters come back from those stamps, every job's, run or not, outermost loop first. A head job made for a new round and not yet run when the run stopped still says that round has begun; without it, the run would start the same round again. For each loop, the counter is that loop's entry in the greatest stamp naming it, ordered as SG-19 orders rounds, among the stamps that agree with the counters already rebuilt for the loops around it. Where no stamp agrees, because the outer round has just advanced and the nested loop has no job in it yet, the nested counter is 0. Taking the highest round ever recorded for the loop on its own is the intuitive-looking shortcut, and it is wrong: a loop nested inside another gets reset every time the outer round advances (SG-18), so the highest figure on record can belong to an earlier outer round entirely, and resuming from it spends an inner loop's budget before the current outer round has even begun.

Taking the newest stamp in creation order is wrong too, though it usually gives the same answer. A job that was still able to run when its loop went round again runs late and keeps its own round (SG-21), and the jobs it leads to are created after the advance with the older round. The newest stamp is then a stale one; the greatest is always the current one.

Example

A run pauses after its inner loop has spent five rounds under the outer loop's round 0, the outer round then advances and resets the inner one, and the inner loop is one round into outer round 1 when the pause happens. Six executions, oldest first, each carrying the rounds it ran under:

Six executions' round stamps, oldest first
[
  {"outer_head": 0, "inner_head": 0},
  {"outer_head": 0, "inner_head": 4},
  {"outer_head": 0, "inner_head": 5},
  {"outer_head": 1},
  {"outer_head": 1, "inner_head": 0},
  {"outer_head": 1, "inner_head": 1}
]
What the resumed run restores the rounds torestored
{"outer_head": 1, "inner_head": 1}

Taking the highest inner figure on record would restore the inner loop to 5 — the budget it spent under an outer round that no longer applies — and the loop would stop rounds early for the rest of the run. Had a late job of outer round 0 been created after the sixth execution, stamped {"outer_head": 0, "inner_head": 5}, the newest stamp would restore both loops to that earlier round; the greatest stamp still gives the answer above.

Why

Recorded under OPEN-23, OPEN-25, OPEN-60.

Rule identifiers are permanent and are never renumbered. Each implementation publishes its own standing against these rules; this specification does not.spec 1.0 · SG-17 · changed in spec 1.1