Expand description
Daemon-side SSE stream subscriber (R1 phase 2, v0.5.6).
Opens a long-lived GET /v1/events/:slot_id/stream connection to the
relay using the operator’s own slot_token, parses SSE data: lines as
they arrive, and pings a wake-channel for each event. The daemon’s main
loop replaces std::thread::sleep(interval) with recv_timeout(interval)
against this channel, so a posted event traverses sender → relay →
subscriber → local inbox in ~10-50ms instead of waiting for the next
~5s poll tick.
Failure model: if the stream errors or disconnects, the subscriber
reconnects with exponential backoff (1s → 2s → 4s → 8s → 30s cap). The
daemon’s regular polling loop is unaffected and continues as a safety
net — stream-down does NOT mean events-down. Operator running
wire daemon with no relay reachability sees both signals (stream
reconnect retries + poll errors) and can diagnose.
Design note: this is a one-way wake signal, not the data path. The
actual run_sync_pull re-fetches via list_events so we get
signature verification, dedup, and inbox write through the exact same
code path as polling. The stream only changes WHEN pull runs, not HOW.
Functions§
- spawn_
stream_ subscriber - Spawn the stream-subscriber thread. Returns immediately; the thread
runs until process exit.
wake_txis signaled on every received SSEdata:line (any event, no parsing of body). Errors during connect or stream-read trigger reconnect-with-backoff, never panic.