Skip to main content

Module registry

Module registry 

Source
Expand description

Daemon-owned session registry: storage, per-session sequencing, ring buffer, and attach/detach bookkeeping (#2054, #2055).

Why: this is the object Axiom 4 describes — sessions live INSIDE the daemon, not in a CLI-side tmux pane. SessionRegistry is the single owner of every Session’s state, its bounded event history, and (#2055) the per-session sequence counter that makes replay -> live gap detection possible. Designed so persistence (Phase 2+, out of scope per §12) can be added by swapping the storage backing this type without touching session::protocol’s handlers or the wire protocol at all. What: SessionRegistry holds HashMap<String, SessionEntry> behind a std::sync::Mutex (never held across an .await — every method here is synchronous; attach uses tokio::spawn to hand off, not to block). Each entry carries the Session snapshot, a monotonic per-session seq counter, a bounded ring buffer of recent crate::events::SessionEventEnvelopes (§12.1.5: default 1000, oldest dropped first), and a map of live attachments (connection_id -> oneshot::Sender<()> used by detach to stop that connection’s forwarder task). Self::record is the ONE place that assigns seq (under the same lock that pushes the ring buffer entry), so replay and every subsequent live event share one gap-free, strictly increasing sequence — see crate::events’s module docs for the full envelope rationale. attach replays the ring buffer synchronously, then spawns a task that subscribes to the existing process-global crate::events bus, filters by session_id, and forwards matching envelopes into the caller’s NotifySender until detached or the channel closes (the connection is gone). Test: see registry_tests (sibling file, #[cfg(test)]).

Structs§

SessionRegistry
The daemon-owned session registry (Axiom 4).

Constants§

DEFAULT_RING_CAPACITY
Default ring-buffer capacity per session (vision spec §12, 11.5).