Expand description
Disk-backed durable outbound event queue (Plan 07 locked-in decision; RFC-0005 §9.7).
Each event is one file on disk under {state_dir}/outbound-queue/,
named {seq:020}-{hostname}-{rollout}-{event_kind}.json. Zero-
padded seq so directory listing is in seq-order. Atomic write via
tmp + rename so a crash mid-write leaves no partially-formed file
visible to the drainer. On successful POST, the file is deleted.
Properties:
- Survives agent process crashes: every outbound event hits disk before the network call returns.
- Single fsync per event: the rename hops the rename-survives- reboot guarantee on POSIX filesystems; the data fsync ensures the bytes are durable before the rename swings the pointer.
- Replay-from-seq friendly: a CP
X-Nixfleet-Replay-From: Nresponse triggers a directory scan for files with seq ≥ N. - Crash mid-write: a partial
.tmpfile is invisible toOutboundQueue::scan_pendingbecause the filename pattern filters out non-.jsonpaths. The next restart’s drainer picks up where it left off.
Structs§
- Outbound
Queue - Disk-backed queue handle. Cheap to clone via
Arc. - Queued
Event - One entry in the on-disk queue. Persisted as JSON via serde.
payloadis the typed wire event (RFC-0004 §2 lift: the wire envelope + AgentEvent live innixfleet-proto, both sides of the agent <-> CP boundary import the same types). The outbound worker wraps each QueuedEvent in anAgentEventEnvelopeat POST time.
Functions§
- filename_
for 🔒 {seq:020}-{hostname}-{rollout}-{event_kind}.json. The zero-padded seq gives lexicographic = chronological filename order; the.jsonsuffix is whatscan_pendingfilters on (vs.tmp).- outbound_
event_ kind - Map an
OutboundAgentEventto its kebab-caseevent_kinddiscriminator (used in the filename + the OutboundEventKind enum indb/event_logon the CP side). - outbound_
event_ seq - Read the
seqfield off anOutboundAgentEvent. - sanitize 🔒
- Filename sanitisation: replace path separators + spaces with
_. Belt-and-braces; the wire types should already constrain these strings to URL-safe shapes, but we don’t trust the input. - write_
atomic 🔒