Module reducer

Module reducer 

Source
Expand description

Reducer task body: the single mutator of CP-mirror state.

Owns the cached SignedManifestSet, the per-channel quarantine set, and (transiently) the per-rollout HostRolloutState map it loads from the DB. Calls into nixfleet_state_machine::step on every HostEvent input, nixfleet_reconciler::plan_next on ManifestSetUpdated / PlanTick, and the applier (apply_plan_action/apply_effect) for every output.

Invariant 1 from runtime::mod: this is the only place that calls step() or plan_next(). Workers and HTTP route handlers emit ReducerInput values; the applier executes the produced effects.

Structsยง

ReducerState ๐Ÿ”’
Reducer-task-private state. The DB-backed CP-mirror lives in host_rollout_records; this struct holds only the data the reducer canโ€™t or shouldnโ€™t go back to SQLite for on every input.
ShutdownGuard ๐Ÿ”’
RAII container for per-worker shutdown senders. Holding it in scope ensures workers receive shutdown signal exactly when this task exits.

Constantsยง

PLAN_TICK_INTERVAL ๐Ÿ”’
Safety-net replan cadence. Triggers plan_next even when no event arrives โ€” covers manifest_poll crashes mid-cycle, missed kicks, etc.

Functionsยง

advance_current_waves ๐Ÿ”’
Promote each rolloutโ€™s current_wave when every host in the current wave has reached HostState::Converged. The check reads the host list from the verified manifestโ€™s fleet.waves[channel][current_wave] โ€” the same path the wave_promotion gate uses for host_wave, so the bump and the gate stay in lock-step.
build_bootstrap_for_host ๐Ÿ”’
Scan active records for host and produce a HostRolloutSnapshot per record. Called only on boot-recovery-shaped heartbeats (rollout_id=None). Order is deterministic by (rollout_id, hostname) PK in SQL; the agent applies them in arrival order.
build_fleet_state ๐Ÿ”’
Build a fresh FleetState from the DB. Called on every plan tick; at v0.2 scale (โ‰ค256 hosts, โ‰ค8 active rollouts) the SELECTs are negligible.
compute_replay_from ๐Ÿ”’
evaluate_synth_gates ๐Ÿ”’
Run the dispatch-gate evaluation against a Pending HRR record so maybe_synthesize_recovery_completion can refuse to fast-forward Pending โ†’ Converged when an active gate (channel-edges, wave-promotion, quarantine, etc.) would still hold the host.
handle_heartbeat ๐Ÿ”’
handle_host_event ๐Ÿ”’
handle_input ๐Ÿ”’
host_rollout_state_to_snapshot ๐Ÿ”’
maybe_synthesize_recovery_completion ๐Ÿ”’
Scan active host_rollout_records for host; for each record whose observed closure on the wire identifies a missed transition, synthesize the event chain that advances the row to a state consistent with the agentโ€™s reality. Idempotent: if the state has already advanced (e.g. concurrent agent emit), the record wonโ€™t match and the synthesis is a no-op.
resolve_policy ๐Ÿ”’
run ๐Ÿ”’
run_plan ๐Ÿ”’
synthesize_pending_to_converged ๐Ÿ”’
Drive a Pending HRR row through the full lifecycle to Converged when the agent reports current_closure == target. The chain preserves the event-log audit trail (RFC-0004 ยง1): every transition emits its usual RemoteAppendEventLog effect flagged with the synthesis context via the seq ordering relative to the pre-synthesis last_event_seq.