--- id: SG-21 family: RT-SG level: core profiles: [runtime] posture: normative-target added: "1.1" changed: "1.1" source: https://flowdrop.io/spec/rules/rt-sg/sg-21 specification: FlowDrop Workflow Specification 1.0 licence: CC BY 4.0 --- # SG-21 — A job carries its round, and a job its round can no longer satisfy is skipped *RT-SG (Part II) · level: core · profiles: runtime · added in 1.1* Every job inside a loop reads its own round's values, early or late. When a round ends, a job of that round still waiting on inputs that can no longer come is skipped, so an untaken arm inside a loop ends cleanly with its round, rather than hanging, failing, or running on another round's values. ## The rule > **Normative.** This is the rule. > > 1. A job created by following an edge MUST carry, on each loop its node shares with the source job's node, the source job's round. > > 2. On each other loop of its node it MUST carry that loop's current round, or round 0 where the source job's round is behind the current rounds on a loop enclosing that one. > > 3. The current rounds are the run's round counters (SG-17), and rounds are ordered as SG-19 orders them. > > 4. A job created by following a loopback edge MUST instead carry the advanced round on the loop that the edge takes round again (SG-7). > > 5. All the loopback edges that one job follows into one loop MUST take that loop round again once, and each of their heads MUST get a job on the advanced round. > > 6. The loopback edges of different jobs MUST be taken one job at a time, each job's edges checked against the current rounds as the job before left them. > > 7. A dispatch MUST NOT be absorbed by a job of another round, so SG-6's single dispatch per target holds within one round. > > 8. An implementation MAY create a job before any edge into it is followed. > > 9. Such a job MUST carry no round, and MUST take no part in readiness, in liveness or in this rule's skip until an edge into it is followed; the first dispatch to its node for which no job of that round exists MUST then give it that round, exactly as a job created at that moment would carry. > > 10. A job no edge ever reaches stays outside this rule, and BR-7 collects it when the run ends. > > 11. A job of a node with no incoming execution dependency (DATA-5) MUST carry the current rounds when the run starts. > > 12. A round of a loop (SG-17) has ended once it is behind the current rounds, as it is once the loop or a loop enclosing it has gone round again, or once no live job on that round can still reach a tail of the loop for that round. > > 13. A round that has ended stays ended, whatever runs later. > > 14. A job's round has ended once its round of any of its loops has ended. > > 15. A job reaches a node for a round over the forward graph and over the loopback edges of every loop that the round does not name, and a node reaches itself; a job whose round has ended reaches over the forward graph only, since its loopback edges are not followed. > > 16. A job is live while it has not reached a terminal status (completed, failed, cancelled or skipped) and, where it is not yet ready (DATA-4, ERR-10), while it can still be satisfied. > > 17. An edge into a job can still be satisfied when it is satisfied, or when a live job on that job's round (SG-19) reaches the edge's source for that job's round. > > 18. A job that is not yet ready can still be satisfied when one of its error edges can, or, whatever its error edges, when it would be ready if every edge into it that can still be satisfied were: one trigger edge for a job with an incoming trigger edge, and otherwise one edge on every data port, for a job that has one. > > 19. Loopback and tool edges take no part in this test, as they take none in readiness (DATA-5), and a job whose other incoming edges are all error edges can still be satisfied only through those. > > 20. Liveness and satisfiability are the least that meet these definitions: a job that is not yet ready counts as live only through jobs that are ready or have started. > > 21. A job MUST NOT count as finished for this rule before the jobs its followed edges create exist. > > 22. A job that has not reached a terminal status, is not yet ready, can no longer be satisfied, and whose round has ended MUST be skipped before the next scheduler pass begins. > > 23. This MUST hold before every scheduler pass, including the first after a run resumes, and not only at the moment a round ends. > > 24. A job that is ready belongs to its round and MUST NOT be skipped on this ground, even after its round has ended. > > 25. The skip MUST be announced and recorded as BR-7 requires of a skip, with the reason `SUPERSEDED_ROUND` in place of `BRANCH_NOT_ACTIVE`. > > 26. The job's entry (PIPE-7) MUST carry that reason in its `metadata` as `skip_reason`. > > 27. Where BR-7's end-of-run collection meets a job this rule has skipped, the job MUST keep that reason. > > 28. A loopback edge leaving a job whose round has ended MUST NOT be followed. > > 29. That job's other edges MUST still be followed, and the jobs they create carry their rounds like any job created by following an edge: the late job's round on every loop they share with it. ## What it means A loop runs its body once per round, and every job carries the round it belongs to (SG-17). Two things can go wrong at the edge of a round. A job of round N that runs late, after the loop has gone round again, could read the values round N+1 has since produced. And a job of round N whose input was routed away could wait for ever, or be filled by round N+1's value, or be failed. This rule, with SG-19 and SG-8, settles all of them: a job inside a loop reads its own round's values, early or late, and a job its round can no longer satisfy is skipped when that round ends. It has five parts, and one guarantee about job creation. **A job belongs to one round.** A job created by following an edge takes the source job's round on every loop the two share, and the loop's current round on any loop it enters, or round 0 there if the source job is late. SG-19 and SG-8 then bind every input to that round: neither behind it nor ahead of it. A dispatch is never absorbed by a job of another round, so each round gets its own job of a node. **When a round ends, what it can no longer satisfy is skipped.** A round of a loop ends when the loop, or a loop around it, goes round again. It also ends when nothing live on that round can still reach one of the loop's tails: the loop has stopped, whether a tail declined to go round, the head routed out of the loop, or the round simply cannot get any further. At that point every job of the round that is still waiting on inputs, and can no longer get them, is skipped with the reason `SUPERSEDED_ROUND`, visible on the job. "Can no longer get them" is the readiness test of DATA-4, with error edges first (ERR-10), asked of the future: could each missing input still arrive, on this job's round, from something still live? A live job on another round does not count; a live job outside every loop the consumer is in does. **A job that is ready runs.** A job whose inputs are all there belongs to its round, even if the loop has moved on. A slow input from outside the loop, a triggered error handler, a branch that finished after the tail: all of these run, late, on their own round's values. **A late job does not drive its loop.** A loopback edge leaving a job whose round has ended is not followed: that round has had its turn. An ended round stays ended, so nothing that finishes later can reopen it. The late job's other edges are followed, and what they create belongs to the late round too. Two tails finishing together are taken one job at a time: the first takes the loop round, and the second then finds its round already left. One job is different: where it follows two loopback edges into one loop, as a merged loop's shared tail does, the loop goes round once and both heads start the new round. **It does not depend on when jobs are made.** An implementation may create every job up front or only when an edge reaches it. A job made early carries no round and is invisible to this rule until an edge reaches it, and then takes the round that edge gives it, so both kinds of implementation skip and run the same jobs. **It always holds.** The skip is not an event that happens once, at the moment a loop goes round. It holds before every scheduler pass, so a run resumed after a crash or a pause applies it again on its first pass. "Could still arrive" follows the graph as the round sees it: forward edges, plus the loopback edges of loops the round does not name. A job inside a nested loop reaches the outer tail through the nested loop's loopback edge, so the outer round does not end while the nested loop is still turning. A separate loop upstream, still building a value the consumer needs, keeps the consumer waiting until it has finished. A late job no longer turns its loops, so it reaches over forward edges only. And a waiting job counts as live only through jobs that are ready or already running: two waiting jobs cannot keep each other alive. ## Example A loop whose gateway sends each round down one of two arms. Arm `a` runs `src`, whose value `C` needs alongside `x`; arm `b` goes straight to a second tail: ```json title="Two arms, two tails, one loop" { "edges": [ {"source": "trigger", "target": "head"}, {"source": "head", "target": "gw"}, {"source": "gw", "target": "src", "branch": "a"}, {"source": "gw", "target": "tail2", "branch": "b"}, {"source": "src", "target": "C", "port": "p1"}, {"source": "head", "target": "x"}, {"source": "x", "target": "C", "port": "p2"}, {"source": "C", "target": "tail1"} ], "loopbacks": [ {"source": "tail1", "target": "head"}, {"source": "tail2", "target": "head"} ] } ``` With a budget of three rounds and the gateway choosing `a`, `b`, `a`, the round-1 job of `C` has `x` but not `src`. When `tail2` takes the loop round again, nothing live on round 1 can produce `src`, so the job is skipped: ```json title="C's jobs, by round" verdict="skipped" { "0": {"status": "completed", "reads": {"p1": "src, round 0", "p2": "x, round 0"}}, "1": {"status": "skipped", "skip_reason": "SUPERSEDED_ROUND"}, "2": {"status": "completed", "reads": {"p1": "src, round 2", "p2": "x, round 2"}} } ``` Gating only sources that are behind the consumer would instead have let the round-1 job wait, and run once `src` completed on round 2, reading round 2 on both ports. With the gateway choosing `a`, `a`, `b`, the round-2 job of `C` is skipped the same way on the last round, where the loop stops instead of going round: nothing live on round 2 reaches a tail once `tail2` has finished. It is not failed. Had `tail1` been the loop's only tail, round 1 could not have gone any further without `C`: the round ends there, the job is skipped all the same, and the loop stops. Nothing fails; the blocked job is the place to look, and its `SUPERSEDED_ROUND` reason says why it never ran. A slow input from outside the loop: ```json title="A loop body that needs a slow value from outside" { "edges": [ {"source": "trigger", "target": "cfg"}, {"source": "trigger", "target": "head"}, {"source": "head", "target": "C", "port": "item"}, {"source": "cfg", "target": "C", "port": "cfg"}, {"source": "C", "target": "w"}, {"source": "head", "target": "tail", "port": "p"}, {"source": "w", "target": "tail", "port": "p"} ], "loopbacks": [{"source": "tail", "target": "head"}] } ``` The loop runs all three rounds before `cfg` completes. Each time it goes round, the waiting job of `C` can still be satisfied, since `cfg` is live and shares no loop with it, so none is skipped. When `cfg` completes, all three run, each on its own round's item: ```json title="C's jobs once cfg completes" verdict="late" { "0": {"status": "completed", "reads": {"item": "head, round 0", "cfg": "cfg"}}, "1": {"status": "completed", "reads": {"item": "head, round 1", "cfg": "cfg"}}, "2": {"status": "completed", "reads": {"item": "head, round 2", "cfg": "cfg"}} } ``` The same holds when `cfg` is the result of a ForEach upstream that is still turning: its tail reaches `cfg` through its own loopback edge, which the consumer's round does not name. A routed failure whose handler is slower than the loop: ```json title="An error handler inside the loop" { "edges": [ {"source": "trigger", "target": "head"}, {"source": "head", "target": "X"}, {"source": "X", "target": "handler", "kind": "error"}, {"source": "head", "target": "tail", "port": "p"}, {"source": "handler", "target": "tail", "port": "p"} ], "loopbacks": [{"source": "tail", "target": "head"}] } ``` `X` fails on round 0 and its failure is routed. The handler's round-0 job is ready, so when the loop goes round before it has run, it is not skipped: it runs, on round 0, after the loop has moved on. On rounds where `X` succeeds, a handler job, where one exists, can no longer be satisfied and is skipped when its round ends. ## Why Recorded under [OPEN-60](https://flowdrop.io/spec/rulings/open-60), [OPEN-50](https://flowdrop.io/spec/rulings/open-50). ## Related rules - Names: SG-6, SG-7, SG-16, SG-17, SG-18, SG-19, DATA-4, BR-7, ERR-10 - Referenced by: ERR-10, ORC-9, BR-6, BR-7, DATA-4, INT-6, SG-7, SG-8, SG-17, SG-18, SG-19, SG-20 --- Rule identifiers are permanent and are never renumbered. This specification carries no implementation status: each implementation publishes its own standing against these rules. Licensed CC BY 4.0.