Model workflow runs in the TLA+ scheduler: needs sets, skips, per-run reservation

Generalizes the chain predecessor to needs sets, adds skipped as a terminal
step status with a transitive cascade, encodes each-step items (fail-soft,
zero items fail the step, failed items fail the run), and reserves at most
min(MaxWorkers - 1, 4) concurrent steps per workflow run inside the global
pool. Commits a run's outcome only after every step settled, so skip
propagation completes before a run is called failed.
This commit is contained in:
alex committed 2026-11-26 19:11:19 +00:00
1 parent f644224eb0
commit 6d9322d74b
3 files changed
+342 -96

No files matched your search

+1 -1
View File
@@ -141,7 +141,7 @@ npm run modelcheck
npm run smoke
```
`spec/SubagentJobs.tla` models the bounded scheduler and lifecycle. TLC checks worker bounds, legal state invariants, terminal stability, chain ordering, and cancellation/shutdown behavior. Set `TLA2_TOOLS_JAR` if `tla2tools.jar` is not at the local development fallback path.
`spec/SubagentJobs.tla` models the bounded scheduler, the lifecycle, and the workflow state machine: needs sets instead of a chain predecessor, the `skipped` status with its transitive cascade, each-step items (fail-soft, zero items fail the step), and a per-run reservation of `min(maxWorkers - 1, 4)` steps inside the shared pool. TLC checks worker and per-run bounds, needs ordering, skip propagation, run outcomes, terminal stability, and cancellation/shutdown behavior. Set `TLA2_TOOLS_JAR` if `tla2tools.jar` is not at the local development fallback path.
Tests exercise the manager interface, tool schemas/adapters, real subprocess behavior with a fake Pi executable, generated transition sequences, UTF-8 properties, and persistence. `.pi/verify.json` wires the deterministic gates.
+41 -5
View File
@@ -1,15 +1,51 @@
CONSTANT MaxWorkers = 2
\* TLC configuration for the workflow extension of the scheduler model.
\*
\* MaxWorkers = 3 is the smallest pool that exhibits the design: the workflow
\* run cap is min(MaxWorkers - 1, 4) = 2, and "flow" has three independent roots
\* (scan, audit, notify) so the reservation binds. The "parallel" job is not
\* capped (RunCapOf is MaxWorkers there), so two of its steps plus two flow steps
\* contend for three workers -- both bounds are exercised, and a fourth start is
\* correctly blocked. MaxWorkers must stay > 1 (ASSUME): with 1 the workflow cap
\* is 0 and a run could never start.
\*
\* MaxItems = 2 is the smallest fan-out that shows both halves of the each-step
\* contract: a step with one failed plus one succeeded item succeeds while the
\* run still fails. The item count is drawn from {0, MaxItems}, so the zero-item
\* failure is covered without a third fan-out size; 3+ would multiply the item
\* state space for no new behaviour.
\*
\* State-space trade-offs (this gate runs on every settle, so it must stay
\* minutes, not hours). Total reachable states grow as the product of the two
\* jobs' states times TLC's temporal-property product (48 branches for the
\* stability properties), so the instance is kept to 7 steps: "flow" carries the
\* whole workflow contract (needs set of size two, each-step, two-level skip
\* cascade, independent branch, three roots) and "parallel" exists to make the
\* global MaxWorkers bound bind across jobs. Chain mode needs no own job: a chain
\* is a needs set of size one, which "report" needs {"fan"} already models, and
\* NeedsOrdering checks it. About 300k distinct states / ~3 min before the trims
\* above; the current instance is far smaller. Adding more steps, more jobs, or
\* a longer cascade is the knob for deeper coverage -- expect the runtime to
\* grow multiplicatively.
CONSTANT MaxWorkers = 3
CONSTANT MaxItems = 2
INIT Init
NEXT Next
INVARIANT TypeOK
INVARIANT WorkerBound
INVARIANT ChainOrdering
INVARIANT RunCapBound
INVARIANT NeedsOrdering
INVARIANT SkipPropagation
INVARIANT SkipsJustified
INVARIANT CancellationDrainsQueue
INVARIANT ShutdownStopsWork
INVARIANT SuccessfulJobsHaveSuccessfulTasks
INVARIANT FailedJobsHaveFailedTasks
INVARIANT EachStepSuccessNeedsAnItem
INVARIANT EachStepOutcomeWaitsForItems
INVARIANT SuccessfulRunsHaveNoFailures
INVARIANT FailedRunsHaveFailures
INVARIANT RunOutcome
INVARIANT SettledRunsHaveTerminalSteps
PROPERTY TerminalJobStability
PROPERTY TerminalTaskStability
PROPERTY TerminalStepStability
+300 -90
View File
@@ -1,176 +1,386 @@
--------------------------- MODULE SubagentJobs ---------------------------
\* Scheduler model for the subagent manager and the workflow layer
\* (spec #4, ticket #6; ADRs 0002 and 0003).
\*
\* Modeled:
\* - Jobs are invocations. "parallel" keeps the pre-workflow fan-out job type
\* (uncapped: RunCapOf is MaxWorkers); "flow" is a workflow run whose steps
\* form a DAG. Chain mode is subsumed rather than dropped: a chain is a
\* needs set of size one, and "report" needs {"fan"} here.
\* - Steps declare Needs sets (formerly the single ChainPred), release only
\* when every need has succeeded, and are skipped -- transitively -- when
\* any need ends in a terminal non-success.
\* - Each-steps fan out over zero or MaxItems items. A failed item leaves a
\* failed slot (itemsFailed) without failing the step while at least one
\* item succeeded; zero items fail the step; a run with any failed item
\* still has a failed outcome.
\* - A workflow run reserves at most min(MaxWorkers - 1, 4) concurrent steps
\* inside the shared MaxWorkers pool.
\*
\* Deliberate abstractions:
\* - The item count of an each-step is chosen nondeterministically when the
\* step starts: the source step's output is not modeled, only the fact that
\* it may yield zero lines or a full MaxItems fan-out.
\* - Steps are the unit of both the global bound and the per-run reservation,
\* per the design. Item children are that step's fan-out and do not take
\* their own worker slots in the model.
\* - Plan validation (#5) rejects cyclic needs and cross-run needs; the
\* modeled instance states both as ASSUMEs (NeedsRank is the acyclicity
\* witness), because skip propagation terminates only on a DAG.
\* - Only safety is checked, as in the original spec. Completeness of the
\* cascade -- every dead-need step eventually skipping -- is liveness, so a
\* supervisor that lost a skip would stall the run instead of violating an
\* invariant. The safety half is checked: no step advances past a dead need
\* (SkipPropagation), skips are justified (SkipsJustified), skipped is
\* terminal (TerminalStepStability), and a run cannot settle before every
\* step is terminal (SettledRunsHaveTerminalSteps).
EXTENDS FiniteSets, Naturals
CONSTANT MaxWorkers
CONSTANTS MaxWorkers, MaxItems
Jobs == {"chain", "parallel"}
Tasks == {"chain-1", "chain-2", "parallel-1", "parallel-2"}
JobOf == [t \in Tasks |-> IF t \in {"chain-1", "chain-2"} THEN "chain" ELSE "parallel"]
NoPred == "no-predecessor"
ChainPred == [t \in Tasks |-> IF t = "chain-2" THEN "chain-1" ELSE NoPred]
JobStates == {"queued", "running", "cancelling", "succeeded", "failed", "cancelled", "interrupted"}
TaskStates == {"queued", "running", "succeeded", "failed", "cancelled", "interrupted"}
WorkflowJobs == {"flow"}
Jobs == {"parallel", "flow"}
Steps == {"parallel-1", "parallel-2",
"scan", "audit", "notify", "fan", "report"}
JobOf ==
[s \in Steps |->
CASE s \in {"parallel-1", "parallel-2"} -> "parallel"
[] OTHER -> "flow"]
\* The modeled workflow: three independent roots (scan, audit, notify) so the
\* run's reservation can bind; "fan" is the each-step and needs both scan and
\* audit (a needs set); "report" needs the each-step, so a failed scan or audit
\* skips fan and then skips report (a transitive cascade two levels deep), while
\* the unconsumed notify branch still runs to completion.
Needs ==
[s \in Steps |->
CASE s = "fan" -> {"scan", "audit"}
[] s = "report" -> {"fan"}
[] OTHER -> {}]
EachSteps == {"fan"}
\* Acyclicity witness: every need ranks strictly below its dependent.
NeedsRank ==
[s \in Steps |->
CASE s \in {"parallel-1", "parallel-2",
"scan", "audit", "notify"} -> 0
[] s = "fan" -> 1
[] OTHER -> 2] \* report
JobStates == {"queued", "running", "cancelling",
"succeeded", "failed", "cancelled", "interrupted"}
StepStates == {"queued", "running", "succeeded", "failed", "skipped",
"cancelled", "interrupted"}
TerminalJobStates == {"succeeded", "failed", "cancelled", "interrupted"}
TerminalTaskStates == {"succeeded", "failed", "cancelled", "interrupted"}
TerminalStepStates == {"succeeded", "failed", "skipped", "cancelled",
"interrupted"}
ASSUME MaxWorkers \in Nat /\ MaxWorkers > 0
VARIABLES jobState, stepState, itemCount, itemsDone, itemsFailed,
processRunning, cancelRequested, shuttingDown
vars == <<jobState, stepState, itemCount, itemsDone, itemsFailed,
processRunning, cancelRequested, shuttingDown>>
VARIABLES jobState, taskState, processRunning, cancelRequested, shuttingDown
vars == <<jobState, taskState, processRunning, cancelRequested, shuttingDown>>
StepsOf(j) == {s \in Steps : JobOf[s] = j}
\* Item counters are meaningful only for members of EachSteps; every other
\* step keeps all three at zero.
ItemCounters == [Steps -> 0..MaxItems]
TasksOf(j) == {t \in Tasks : JobOf[t] = j}
ReadyIn(state, t) ==
IF ChainPred[t] = NoPred
THEN TRUE
ELSE state[ChainPred[t]] = "succeeded"
LiveProcesses == {t \in Tasks : processRunning[t]}
Min(a, b) == IF a < b THEN a ELSE b
\* A workflow run never takes the whole pool: the parent session keeps one
\* worker, and four is the design ceiling (ADR 0002).
RunCapOf(j) == IF j \in WorkflowJobs THEN Min(MaxWorkers - 1, 4) ELSE MaxWorkers
ASSUME MaxWorkers \in Nat /\ MaxWorkers > 1 \* RunCapOf must admit one step
ASSUME MaxItems \in Nat
ASSUME \A s \in Steps :
/\ \A n \in Needs[s] : n \in StepsOf(JobOf[s]) \* needs stay in the run
/\ \A n \in Needs[s] : NeedsRank[n] < NeedsRank[s]
TypeOK ==
/\ jobState \in [Jobs -> JobStates]
/\ taskState \in [Tasks -> TaskStates]
/\ processRunning \in [Tasks -> BOOLEAN]
/\ stepState \in [Steps -> StepStates]
/\ itemCount \in ItemCounters
/\ itemsDone \in ItemCounters
/\ itemsFailed \in ItemCounters
/\ processRunning \in [Steps -> BOOLEAN]
/\ cancelRequested \in [Jobs -> BOOLEAN]
/\ shuttingDown \in BOOLEAN
LiveProcesses == {s \in Steps : processRunning[s]}
RunningSteps(j) == {s \in StepsOf(j) : stepState[s] = "running"}
NeedsMet(state, s) == \A n \in Needs[s] : state[n] = "succeeded"
\* Some need can never succeed, so this step can only be skipped.
DeadNeed(s) == \E n \in Needs[s] : stepState[n] \in TerminalStepStates \ {"succeeded"}
Init ==
/\ jobState = [j \in Jobs |-> "queued"]
/\ taskState = [t \in Tasks |-> "queued"]
/\ processRunning = [t \in Tasks |-> FALSE]
/\ stepState = [s \in Steps |-> "queued"]
/\ itemCount = [s \in Steps |-> 0]
/\ itemsDone = [s \in Steps |-> 0]
/\ itemsFailed = [s \in Steps |-> 0]
/\ processRunning = [s \in Steps |-> FALSE]
/\ cancelRequested = [j \in Jobs |-> FALSE]
/\ shuttingDown = FALSE
Start(t) ==
LET j == JobOf[t] IN
\* The item count an each-step fans out over: zero (the source produced no
\* lines) or MaxItems. A single item adds no behaviour beyond those two.
ItemChoices == {0, MaxItems}
\* Start binds the step's item count for each-steps; plain steps always get 0.
StartWithItems(s, n) ==
LET j == JobOf[s] IN
/\ n \in ItemChoices
/\ s \in EachSteps \/ n = 0
/\ ~shuttingDown
/\ ~cancelRequested[j]
/\ jobState[j] \in {"queued", "running"}
/\ taskState[t] = "queued"
/\ ReadyIn(taskState, t)
/\ stepState[s] = "queued"
/\ NeedsMet(stepState, s)
/\ Cardinality(LiveProcesses) < MaxWorkers
/\ taskState' = [taskState EXCEPT ![t] = "running"]
/\ processRunning' = [processRunning EXCEPT ![t] = TRUE]
/\ Cardinality(RunningSteps(j)) < RunCapOf(j)
/\ stepState' = [stepState EXCEPT ![s] = "running"]
/\ itemCount' = [i \in Steps |-> IF i = s THEN n ELSE itemCount[i]]
/\ processRunning' = [processRunning EXCEPT ![s] = TRUE]
/\ jobState' = [jobState EXCEPT ![j] = "running"]
/\ UNCHANGED <<cancelRequested, shuttingDown>>
/\ UNCHANGED <<itemsDone, itemsFailed, cancelRequested, shuttingDown>>
JobAfterProgress(j) ==
IF \A t \in TasksOf(j) : taskState'[t] = "succeeded"
THEN "succeeded"
ELSE IF
/\ \E t \in TasksOf(j) : taskState'[t] = "failed"
/\ ~\E t \in TasksOf(j) : processRunning'[t]
/\ ~\E t \in TasksOf(j) :
/\ taskState'[t] = "queued"
/\ ReadyIn(taskState', t)
THEN "failed"
ELSE jobState[j]
Start(s) == \E n \in ItemChoices : StartWithItems(s, n)
Complete(t, outcome) ==
LET j == JobOf[t] IN
\* One item child of a running each-step settles; the other items and the step
\* itself are unaffected, which is the fail-soft gap between item and step.
RunItem(s, outcome) ==
LET j == JobOf[s] IN
/\ ~shuttingDown
/\ ~cancelRequested[j]
/\ taskState[t] = "running"
/\ processRunning[t]
/\ s \in EachSteps
/\ stepState[s] = "running"
/\ itemsDone[s] < itemCount[s]
/\ outcome \in {"succeeded", "failed"}
/\ taskState' = [taskState EXCEPT ![t] = outcome]
/\ processRunning' = [processRunning EXCEPT ![t] = FALSE]
/\ jobState' = [jobState EXCEPT ![j] = JobAfterProgress(j)]
/\ UNCHANGED <<cancelRequested, shuttingDown>>
/\ itemsDone' =
[i \in Steps |-> IF i = s THEN itemsDone[i] + 1 ELSE itemsDone[i]]
/\ itemsFailed' =
[i \in Steps |->
IF i = s /\ outcome = "failed"
THEN itemsFailed[i] + 1
ELSE itemsFailed[i]]
/\ UNCHANGED <<jobState, stepState, itemCount, processRunning,
cancelRequested, shuttingDown>>
ItemsSettled(s) == itemsDone[s] = itemCount[s]
\* Each-step outcomes are forced by their items: zero items fail the step, and
\* once every item settled the step succeeds iff at least one item succeeded.
OutcomeAllowed(s, outcome) ==
IF s \in EachSteps
THEN IF itemCount[s] = 0
THEN outcome = "failed"
ELSE /\ ItemsSettled(s)
/\ (outcome = "succeeded") <=> itemsFailed[s] < itemsDone[s]
ELSE TRUE
\* The run's outcome is committed only once every one of its steps settled, so
\* skip propagation is always complete before a run is called failed.
\* Succeeded means all steps succeeded with no failed item; failed means at
\* least one step or item failed (ADR 0003: item failures fail the run even
\* when the step itself was fail-soft and succeeded).
Settle(j) ==
LET settled == \A s \in StepsOf(j) : stepState[s] \in TerminalStepStates
clean == \A s \in StepsOf(j) : stepState[s] = "succeeded" /\ itemsFailed[s] = 0
outcome == IF clean THEN "succeeded" ELSE "failed"
IN
/\ ~shuttingDown
/\ ~cancelRequested[j]
/\ jobState[j] \in {"queued", "running"}
/\ settled
/\ jobState' = [jobState EXCEPT ![j] = outcome]
/\ UNCHANGED <<stepState, itemCount, itemsDone, itemsFailed,
processRunning, cancelRequested, shuttingDown>>
Complete(s, outcome) ==
LET j == JobOf[s] IN
/\ ~shuttingDown
/\ ~cancelRequested[j]
/\ stepState[s] = "running"
/\ processRunning[s]
/\ outcome \in {"succeeded", "failed"}
/\ OutcomeAllowed(s, outcome)
/\ stepState' = [stepState EXCEPT ![s] = outcome]
/\ processRunning' = [processRunning EXCEPT ![s] = FALSE]
/\ UNCHANGED <<jobState, itemCount, itemsDone, itemsFailed,
cancelRequested, shuttingDown>>
\* The supervisor propagates one skip at a time, so TLC sees every intermediate
\* state of a cascade: a dependent whose need died must never start, succeed, or
\* fail while the cascade is still running (SkipPropagation).
Skip(s) ==
LET j == JobOf[s] IN
/\ ~shuttingDown
/\ ~cancelRequested[j]
/\ jobState[j] \in {"queued", "running"}
/\ stepState[s] = "queued"
/\ ~processRunning[s]
/\ DeadNeed(s)
/\ stepState' = [stepState EXCEPT ![s] = "skipped"]
/\ UNCHANGED <<jobState, itemCount, itemsDone, itemsFailed,
processRunning, cancelRequested, shuttingDown>>
Cancel(j) ==
/\ ~shuttingDown
/\ jobState[j] \notin TerminalJobStates \cup {"cancelling"}
/\ cancelRequested' = [cancelRequested EXCEPT ![j] = TRUE]
/\ jobState' = [jobState EXCEPT ![j] = "cancelling"]
/\ taskState' = [t \in Tasks |->
IF JobOf[t] = j /\ taskState[t] = "queued"
/\ stepState' = [s \in Steps |->
IF JobOf[s] = j /\ stepState[s] = "queued"
THEN "cancelled"
ELSE taskState[t]]
/\ UNCHANGED <<processRunning, shuttingDown>>
ELSE stepState[s]]
/\ UNCHANGED <<itemCount, itemsDone, itemsFailed, processRunning,
shuttingDown>>
ReapCancelled(t) ==
ReapCancelled(s) ==
\* Models every late process outcome after cancellation. The raw exit may be
\* success or failure; the committed task outcome remains cancelled.
LET j == JobOf[t] IN
\* success or failure; the committed step outcome remains cancelled.
LET j == JobOf[s] IN
/\ cancelRequested[j]
/\ jobState[j] = "cancelling"
/\ taskState[t] = "running"
/\ processRunning[t]
/\ taskState' = [taskState EXCEPT ![t] = "cancelled"]
/\ processRunning' = [processRunning EXCEPT ![t] = FALSE]
/\ UNCHANGED <<jobState, cancelRequested, shuttingDown>>
/\ stepState[s] = "running"
/\ processRunning[s]
/\ stepState' = [stepState EXCEPT ![s] = "cancelled"]
/\ processRunning' = [processRunning EXCEPT ![s] = FALSE]
/\ UNCHANGED <<itemCount, itemsDone, itemsFailed, jobState,
cancelRequested, shuttingDown>>
FinishCancellation(j) ==
/\ jobState[j] = "cancelling"
/\ ~\E t \in TasksOf(j) : processRunning[t] \/ taskState[t] = "running"
/\ ~\E s \in StepsOf(j) : processRunning[s] \/ stepState[s] = "running"
/\ jobState' = [jobState EXCEPT ![j] = "cancelled"]
/\ UNCHANGED <<taskState, processRunning, cancelRequested, shuttingDown>>
/\ UNCHANGED <<stepState, itemCount, itemsDone, itemsFailed,
processRunning, cancelRequested, shuttingDown>>
Shutdown ==
/\ ~shuttingDown
/\ shuttingDown' = TRUE
/\ jobState' = [j \in Jobs |->
IF jobState[j] \in TerminalJobStates THEN jobState[j] ELSE "interrupted"]
/\ taskState' = [t \in Tasks |->
IF taskState[t] \in TerminalTaskStates THEN taskState[t] ELSE "interrupted"]
/\ UNCHANGED <<processRunning, cancelRequested>>
/\ stepState' = [s \in Steps |->
IF stepState[s] \in TerminalStepStates THEN stepState[s] ELSE "interrupted"]
/\ UNCHANGED <<itemCount, itemsDone, itemsFailed, processRunning,
cancelRequested>>
ReapInterrupted(t) ==
ReapInterrupted(s) ==
/\ shuttingDown
/\ taskState[t] = "interrupted"
/\ processRunning[t]
/\ processRunning' = [processRunning EXCEPT ![t] = FALSE]
/\ UNCHANGED <<jobState, taskState, cancelRequested, shuttingDown>>
/\ stepState[s] = "interrupted"
/\ processRunning[s]
/\ processRunning' = [processRunning EXCEPT ![s] = FALSE]
/\ UNCHANGED <<jobState, stepState, itemCount, itemsDone, itemsFailed,
cancelRequested, shuttingDown>>
Quiescent ==
/\ \A j \in Jobs : jobState[j] \in TerminalJobStates
/\ \A t \in Tasks : ~processRunning[t]
/\ \A s \in Steps : ~processRunning[s]
/\ UNCHANGED vars
Next ==
\/ \E t \in Tasks : Start(t)
\/ \E t \in Tasks : Complete(t, "succeeded")
\/ \E t \in Tasks : Complete(t, "failed")
\/ \E s \in Steps : Start(s)
\/ \E s \in EachSteps : \E outcome \in {"succeeded", "failed"} : RunItem(s, outcome)
\/ \E s \in Steps : Complete(s, "succeeded")
\/ \E s \in Steps : Complete(s, "failed")
\/ \E s \in Steps : Skip(s)
\/ \E j \in Jobs : Settle(j)
\/ \E j \in Jobs : Cancel(j)
\/ \E t \in Tasks : ReapCancelled(t)
\/ \E s \in Steps : ReapCancelled(s)
\/ \E j \in Jobs : FinishCancellation(j)
\/ Shutdown
\/ \E t \in Tasks : ReapInterrupted(t)
\/ \E s \in Steps : ReapInterrupted(s)
\/ Quiescent
(* ---------------------------------------------------------------------- *)
(* The correctness contract, one line per property in the ticket. *)
(* ---------------------------------------------------------------------- *)
WorkerBound == Cardinality(LiveProcesses) <= MaxWorkers
ChainOrdering ==
\A t \in Tasks :
/\ ChainPred[t] \in Tasks
/\ taskState[t] \in {"running", "succeeded", "failed"}
=> taskState[ChainPred[t]] = "succeeded"
\* The per-run reservation: a workflow run holds at most min(MaxWorkers-1, 4)
\* of the pool, so big runs yield to interactive calls by construction.
RunCapBound == \A j \in Jobs : Cardinality(RunningSteps(j)) <= RunCapOf(j)
\* A step starts (and can only have succeeded) when all its needs succeeded.
NeedsOrdering ==
\A s \in Steps :
stepState[s] \in {"running", "succeeded"} =>
\A n \in Needs[s] : stepState[n] = "succeeded"
\* Skips are complete and transitive: a step with a dead need may only be
\* queued (the cascade has not reached it yet) or skipped. Cancelled and
\* interrupted runs were torn down, so skip bookkeeping no longer applies.
SkipPropagation ==
\A s \in Steps :
/\ DeadNeed(s)
/\ stepState[s] \notin {"queued", "cancelled", "interrupted"}
=> stepState[s] = "skipped"
\* Skips are never invented: only a dead need justifies one.
SkipsJustified ==
\A s \in Steps : stepState[s] = "skipped" => DeadNeed(s)
CancellationDrainsQueue ==
\A j \in Jobs :
cancelRequested[j] =>
~\E t \in TasksOf(j) : taskState[t] = "queued"
~\E s \in StepsOf(j) : stepState[s] = "queued"
ShutdownStopsWork ==
shuttingDown =>
/\ \A t \in Tasks : taskState[t] \in TerminalTaskStates
/\ \A s \in Steps : stepState[s] \in TerminalStepStates
/\ \A j \in Jobs : jobState[j] \in TerminalJobStates
SuccessfulJobsHaveSuccessfulTasks ==
\* A failed item fails the run even when its step succeeded (ADR 0003).
StepFailed(s) == stepState[s] = "failed" \/ itemsFailed[s] > 0
\* Fail-soft, checked: an each-step that succeeded had at least one succeeding
\* item, so neither a zero-item source nor an all-items-failed step can succeed.
EachStepSuccessNeedsAnItem ==
\A s \in EachSteps :
stepState[s] = "succeeded" => itemsFailed[s] < itemsDone[s]
\* An each-step's status is derived only once every one of its items settled: a
\* step must not be called succeeded or failed while an item is still in flight.
EachStepOutcomeWaitsForItems ==
\A s \in EachSteps :
stepState[s] \in {"succeeded", "failed"} => ItemsSettled(s)
SuccessfulRunsHaveNoFailures ==
\A j \in Jobs :
jobState[j] = "succeeded" =>
\A t \in TasksOf(j) : taskState[t] = "succeeded"
\A s \in StepsOf(j) : stepState[s] = "succeeded" /\ itemsFailed[s] = 0
FailedJobsHaveFailedTasks ==
FailedRunsHaveFailures ==
\A j \in Jobs :
jobState[j] = "failed" =>
\E t \in TasksOf(j) : taskState[t] = "failed"
\E s \in StepsOf(j) : StepFailed(s)
\* Run outcome is failed exactly when a step (or one of its items) failed.
RunOutcome ==
\A j \in Jobs :
jobState[j] \in {"succeeded", "failed"} =>
(jobState[j] = "failed") <=> \E s \in StepsOf(j) : StepFailed(s)
\* A decided run has no steps still in flight: skipping completes before the
\* outcome is committed.
SettledRunsHaveTerminalSteps ==
\A j \in Jobs :
jobState[j] \in TerminalJobStates =>
\A s \in StepsOf(j) : stepState[s] \in TerminalStepStates
\* "Skips are terminal" is TerminalStepStability, since skipped is in
\* TerminalStepStates.
TerminalJobStability ==
\A j \in Jobs : \A state \in TerminalJobStates :
[](jobState[j] = state => [](jobState[j] = state))
TerminalTaskStability ==
\A t \in Tasks : \A state \in TerminalTaskStates :
[](taskState[t] = state => [](taskState[t] = state))
TerminalStepStability ==
\A s \in Steps : \A state \in TerminalStepStates :
[](stepState[s] = state => [](stepState[s] = state))
=============================================================================