Expand description
Pure per-host rollout state-machine reducer.
Implements RFC-0005 §3 (6-state machine) and RFC-0006 §3 (functional core / imperative shell). The reducer is a single function:
ⓘ
step(state, event, now, policy) -> Result<(state, Vec<Effect>), TransitionError>Properties enforced by the crate’s structure:
- No I/O.
Cargo.tomldeclares no tokio, no reqwest, no rusqlite. CI verifies viacargo tree -p nixfleet-state-machine(RFC-0006 §11). - No clock reads.
chrono::Utc::now()is not called anywhere in this crate;nowis always a parameter. - Pure transitions.
stepis deterministic for a given input. Same(state, event, now, policy)→ same(state, effects). - Side effects as data.
Effectis a description, not an execution. The agent runtime (RFC-0006 §7.1) and CP runtime (§7.2) each exhaustively match onEffectvariants; adding a variant is a compiler-enforced change at every applier.
§Same code, both sides
The CP-mirror view of per-host state (RFC-0006 §2 principle 4) runs the
same step() as the agent. Event carries both Local* (agent-side,
synthesized from worker output) and Remote* (CP-side, synthesized from
inbound agent events) variants — the transitions they drive are identical
by construction.
Modules§
- effect 🔒
- Reducer outputs. Descriptions of side effects, not executions.
- error 🔒
- Reducer error path. Distinct from runtime errors — these mean the input event is structurally inapplicable to the current state, which is a runtime invariant violation (out-of-order event, stale seq, etc.). The runtime layer decides whether to log + drop, request replay, or panic.
- event 🔒
- Reducer inputs. Maps RFC-0005 §4.2 wire events onto reducer transitions.
- rehydration 🔒
- Snapshot rehydration — effect emission rules for state restored from a
CP-supplied
HostRolloutSnapshot(RFC-0005 §9.5 / LIFT #3). - rollout
- Pure rollout-level reducer (RFC-0008 §3). Parallel to the per-host
reducer (
crate::step); same functional-core discipline (RFC-0006 §2): no I/O, no clock reads, no shared mutable state, deterministic given(state, event, now). - state 🔒
- Per-(rollout, host) reducer state. Maps RFC-0005 §5
HostRolloutRecord. - transitions 🔒
- Transition dispatcher. Routes
(state, event)to the per-source-state handler in a sibling module, after performing the universal pre-checks (seq monotonicity, basic structural validity). - wire_
conversions 🔒 - Bidirectional conversions between the wire-format types in
nixfleet-proto::agent_eventand the state-machine’s effect / event types. Both directions live in this crate (the state-machine) by the orphan rule: every conversion has a state-machine-local type on at least one side. Keepsnixfleet-protofree of state-machine awareness (proto is the leaf crate) and CP free of duplicate wire definitions (the architect’s d013 lift per RFC-0004 §2).
Structs§
- Host
Rollout State - Per-(rollout, host) reducer state. Mirrors RFC-0005 §5
HostRolloutRecord; the persistence schema in Phase 4 serializes this struct. - Probe
Record - Probe
SubResult - Per-control sub-result on a
kind = evidenceprobe (RFC-0007 §7.1).Noneaggregate for non-evidence probes;Some(vec)for evidence probes — the applier’sprobe_failuresco-write iteratessub_resultsto populate one row per failing control_id. - Probe
Topology Entry - One entry in a
LocalProbeTopologyDeclared/RemoteProbeTopologyDeclaredevent. Carries the per-probe metadata CP needs to evaluate the gate without reading the agent’s filesystem (RFC-0007 §8). Threadingmodeper-event would also work, but the upfront declaration also lets the gate distinguish “this enforce probe declared but never reported” from “no enforce probe declared at all” — the difference matters for wave-hold semantics. - Rollout
Id - Content-addressed rollout identifier (RFC-0008 §6.3).
Enums§
- Effect
- Event
- Inputs to
crate::step. Each variant maps to exactly one (legal) outbound or inbound RFC-0005 §4.2 event. - Host
State - 6-state rollout machine per RFC-0005 §3. Replaces the pre-v0.2 9-variant
nixfleet_proto::HostRolloutState(theQueued/Dispatched/ConfirmWindow/Healthy/Soakedvariants are removed — phases 4-6 delete the old enum entirely once the new machine is wired through). - LogLevel
- Outbound
Agent Event - Outbound wire payloads (POST
/v1/agent/events). Defined here for the reducer’sLocalEmitEventeffect; Phase 6/7 lifts these intonixfleet-proto::agent_wireonce the HTTP routes are wired. - Probe
Mode - Per-probe gate participation (RFC-0007 §3.4). Threaded through every probe event so CP can decide whether to gate on a result without consulting a separate topology table.
- Probe
Status - Transition
Error
Functions§
- rehydration_
effects - Effects to emit immediately after applying a
HostRolloutSnapshotto the agent’s in-memory state. Workers consume these to refresh any cached per-rollout state seeded by prior process incarnations. - step
- Pure reducer. Same signature on agent and CP-mirror sides.