Module heartbeat

Module heartbeat 

Source
Expand description

POST /v1/agent/heartbeat — agent liveness + drift detection (RFC-0005 §4.3). Replaces the v0.1 POST /v1/agent/checkin flow.

The agent posts a minimal envelope (hostname, optional rollout_id, optional current_closure). CP:

  1. Authenticates via mTLS (existing require_cn_layer).
  2. Checks cert CN’s machine_id against body hostname (FORBIDDEN on mismatch — same shape as /v1/agent/events).
  3. Forwards a HeartbeatReceived input to the reducer with a oneshot reply.
  4. The reducer updates last_heartbeat_at (in-memory) and compares the agent’s current_closure against the CP-mirror’s current_closure field on the matching host_rollout_records row. Mismatch → reply contains last_event_seq for Replay-From.
  5. Response is 200 with optional X-Nixfleet-Replay-From: <seq> header.

The 5-second reducer-reply timeout is generous: a healthy reducer processes a heartbeat input in microseconds. A timeout here signals reducer wedge (stuck applier? deadlock?) — log at error, return 503, agent retries.

Structs§

HeartbeatRequest
HeartbeatResponse

Constants§

REDUCER_REPLY_TIMEOUT 🔒

Functions§

heartbeat 🔒