Expand description
Reducer event log: an in-memory ring buffer of recent
Events for replay, plus an optional append-only JSON-lines disk
stream for crash forensics.
This module used to exist twice — crates/launcher/src/event_log.rs
(Phase D.2) and a byte-for-byte mirror in crates/srv/src/event_log.rs
(Phase E.1b), 415 lines each, whose only code-level difference was
which logging sink a warning went to. The srv copy’s own header
carried the to-do: “Phase E.7 cleanup: lift the shared parts into
agentmux-common and unify launcher + srv event logs. (reagent P2
#610.)” This is that lift
(docs/reports/REPORT_DRY_AND_MODULARITY_AUDIT_2026_09_06.md §2.2).
The one real divergence is preserved as a parameter: run_disk_writer
takes a WarnSink, because the launcher logs to its own rotating
file (crate::log) and has no tracing subscriber installed, while
srv logs via tracing::warn!. Hard-coding either would silently drop
the other crate’s warnings.
Two roles, kept clean:
-
In-memory ring is the source of truth for replay during the owning process’s lifetime.
GetEvents { since: u64 }reads from it. Bounded byMAX_RING_EVENTSto stop unbounded memory growth in long sessions; oldest events evict first. A subscriber that fell behind further than the ring’s coverage gets anEventListof whatever’s still in the ring + a flag indicating they may have missed some — it’s their job to recover by treating subsequent events as authoritative. -
Disk file is purely forensic. Append-only JSON-lines. Survives a crash so an operator can post-mortem “what was it doing right before it died.” Fire-and-forget: write failures log a warning but never block the in-memory path. Rotated when it exceeds
MAX_DISK_BYTES(renames current to.old, starts fresh).
Why both: in-memory satisfies D.3’s resync needs at zero I/O cost in the happy path. Disk satisfies the “what happened before the crash” debugging story without complicating the replay reader.
Structs§
- Event
Log - Append-only ring + optional disk persistence.
Functions§
- event_
version - Extract the
versionfield from any Event variant. When a new variant is added that carries a version, add it here too — the exhaustive match catches future-variant compile errors. - run_
disk_ writer - Background task: write events to the disk file as they arrive
on the broadcast bus. Rotates when the file exceeds
MAX_DISK_BYTES.
Type Aliases§
- Warn
Sink - Where
run_disk_writersends its warnings. Each owning crate binds its own logging facility — see the module doc for why this is a parameter rather than a hard-codedtracing::warn!.