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ยง
- Reducer
State ๐ - 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. - Shutdown
Guard ๐ - 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_nexteven when no event arrives โ covers manifest_poll crashes mid-cycle, missed kicks, etc.
Functionsยง
- advance_
current_ ๐waves - Promote each rolloutโs
current_wavewhen every host in the current wave has reachedHostState::Converged. The check reads the host list from the verified manifestโsfleet.waves[channel][current_wave]โ the same path the wave_promotion gate uses forhost_wave, so the bump and the gate stay in lock-step. - build_
bootstrap_ ๐for_ host - Scan active records for
hostand produce aHostRolloutSnapshotper 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
FleetStatefrom 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_completioncan 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
PendingHRR row through the full lifecycle toConvergedwhen the agent reportscurrent_closure == target. The chain preserves the event-log audit trail (RFC-0004 ยง1): every transition emits its usualRemoteAppendEventLogeffect flagged with the synthesis context via theseqordering relative to the pre-synthesislast_event_seq.