Skip to main content

vlo_kernel/
step_machine.rs

1//! The step state machine (see `docs/kernel-protocol.md`).
2//!
3//! The diagram's edges, plus two that fall out of how work actually lands:
4//! - `scheduled → succeeded|failed`: a worker may return a result inline, before the
5//!   host ever records `running`.
6//! - `retrying → succeeded|failed`: the same for a result that beats the reschedule.
7//!
8//! Terminal statuses have no outgoing edges; the kernel prunes terminal steps from
9//! `KernelState::steps`, so a later event for one reports `unknown_step`.
10
11use vlo_types::Status;
12
13/// Every status, in declaration order. Used by the exhaustive legality test.
14pub const ALL_STATUSES: [Status; 7] = [
15    Status::Scheduled,
16    Status::Running,
17    Status::Succeeded,
18    Status::Failed,
19    Status::Retrying,
20    Status::Cancelled,
21    Status::AwaitingSignal,
22];
23
24/// Whether `from → to` is an edge of the step state machine.
25pub fn is_legal(from: Status, to: Status) -> bool {
26    use Status::*;
27    matches!(
28        (from, to),
29        (Scheduled, Running)
30            | (Scheduled, Succeeded)
31            | (Scheduled, Failed)
32            | (Scheduled, Retrying)
33            | (Scheduled, Cancelled)
34            | (Running, Succeeded)
35            | (Running, Failed)
36            | (Running, Retrying)
37            | (Running, Cancelled)
38            | (Running, AwaitingSignal)
39            | (Retrying, Scheduled)
40            | (Retrying, Succeeded)
41            | (Retrying, Failed)
42            | (Retrying, Cancelled)
43            | (AwaitingSignal, Running)
44            | (AwaitingSignal, Succeeded)
45            | (AwaitingSignal, Cancelled)
46    )
47}