Skip to main content

Module sse

Module sse 

Source
Expand description

Workstream-level SSE event aggregation route (DOC-48 §5.3, §5.3.1; issue #3297, epic #3292); thin trusty-agents-common::transport adapter (issue #3299, Phase 1B).

§Spec References

Why: GET /sessions/{id}/events (crate::serve::http::session_events_sse) is a direct lookup against ONE session’s ring buffer + live filter. A workstream is a GROUP of sessions (§2.1), so observing “this workstream” is not a lookup at all — it is a fan-out: subscribe once to the daemon’s existing session-scoped event bus (crate::events::subscribe, already shared by every per-session SSE connection) and forward only the events whose session_id is currently bound to this workstream, tagged with the generic {session_id, event_type, payload} envelope AC-7.2 requires. “Currently bound” is re-checked against the store on every event (not a snapshot taken at subscribe time) so a session added to the workstream after the client connected is picked up without a reconnect (§5.3 point 4) — cheap in practice because WorkstreamStore::get only re-parses the backing file when its (mtime, len) fingerprint actually changed.

AC-7 harness-agnostic seam (Phase 1B, issue #3299): the fan-out algorithm itself now lives in trusty_agents_common::transport::aggregate_live — this module is a thin adapter that implements the shared EventSource/MembershipProvider traits over crate::events/SharedWorkstreamStore and supplies the classify closure encoding tcode’s two group-scoped bypass events (WorkstreamActivationChanged, WorkstreamStateInferred). Behavior is byte-for-byte identical to the Phase 1A implementation this replaces (see sse_tests, ported unchanged); only the fan-out combinator itself moved.

What: WorkstreamEventEnvelope (a type alias over the shared EventEnvelope<Event>), aggregate_live (this module’s adapter function — constructs the two trait impls and the classify closure, then delegates to the shared combinator), and routes (the single GET /workstreams/{id}/events axum route, merged into crate::serve::http::build_axum_router alongside rest::workstreams). Unknown workstream id -> 404; malformed (non-UUID) id -> 400; a CLOSED workstream is still observable (200, not 404) because its existing bound sessions “remain valid and may accumulate turns” after closure (§4.4) — closing only stops NEW session bindings, not event delivery for the ones it already has. A workstream with zero bound sessions returns 200 with a stream that simply never emits (until a future session is added or the workstream’s activation state changes) — it does not error or close early. Test: sse_tests.

Functions§

aggregate_live
Build the live aggregation stream for one workstream (no ring-buffer replay — see module docs).
routes
Build the GET /workstreams/{id}/events route group.

Type Aliases§

WorkstreamEventEnvelope
The harness-agnostic wire envelope AC-7.2 requires: {session_id, event_type, payload} — a type alias over trusty_agents_common::transport::EventEnvelope<Event> (Phase 1B, issue #3299), deliberately distinct from crate::events::SessionEventEnvelope (which carries seq/at/kind/event, tuned for one session’s ring-buffer replay).