Expand description
SessionActor and LiveSessionRegistry for zeph serve (spec-068 §9, #5343).
Each live conversation-session under zeph serve is a SessionActor task: it owns an
Agent<LoopbackChannel> exclusively, bridges SessionCommands into
the agent’s channel input, and forwards the channel’s output as SessionOutput over a
broadcast channel any number of HTTP/SSE or TUI attachments can subscribe to.
LiveSessionRegistry is pure bookkeeping (a HashMap behind a parking_lot::Mutex, never
held across .await) — it does not itself supervise tasks. SessionActor::spawn registers
a coordinator task under TaskSupervisor via spawn_oneshot(name: Arc<str>, factory)
(architect ruling D-7): the dynamic serve.session.<id> name and non-restarting RunOnce
policy are exactly right for a session actor (re-driving a torn turn/replay after a crash is
unsafe; recovery is a fresh spawn that replays the durable log from the last committed seq).
Agent<C>’s futures are !Send (documented precedent: crates/zeph-acp/src/transport/ stdio.rs, “Agent futures are !Send and deeply nested”) and Agent<LoopbackChannel> itself
cannot cross any thread boundary — not just spawn_oneshot’s Send bound but a
std::thread::spawn one too. SessionActor::spawn resolves this exactly as zeph-acp’s
serve_stdio/transport/http.rs do (architect ruling D-8): the Agent is constructed and
driven entirely inside a dedicated OS thread with its own current_thread runtime and
LocalSet — only Send-safe state (a FnOnce(LoopbackChannel) -> Agent<LoopbackChannel>
factory, mirroring zeph-acp’s SendAgentSpawner) crosses into that thread. The
spawn_oneshot task is a thin coordinator, never the agent driver itself: it awaits the
thread’s completion signal and, on process-wide supervisor shutdown, forwards cancellation
onto the session’s own CancellationToken (distinct from the supervisor’s) so idle
eviction (spec §9.3) can cancel exactly one session without tearing down every live actor,
while drive only ever needs to select on a single cancellation source regardless of trigger.
Structs§
- Live
Session Registry - Registry of live
SessionActors forzeph serve(spec §9.3). - Session
Actor - Owns a live
Agent<LoopbackChannel>for one conversation-session (spec §9.2). - Session
Actor Handle - Bookkeeping handle for one live session, held by
LiveSessionRegistry(spec §9.3).
Enums§
- Session
Command - A command sent to a live
SessionActor(spec §9.2). - Session
Output - An event streamed out of a live
SessionActor(spec §9.2).