SSE and client stream
Endpoint
Section titled “Endpoint”GET /api/sessions/:id/events?after=<seq>
- Server assigns monotonic seq per session.
connectedpayload:{ type, id, seq, ringStart }(seesse-protocol.js).- Live frames: slim agent events (
slimSseEventin hub/http).
Resume policy
Section titled “Resume policy”Implemented in shouldReplayRing / client ChatStream:
| Situation | Behavior |
|---|---|
| Cold start, gap, or empty UI | No ring replay → client REST snapshot (GET …/messages) then drain buffer |
Hot resume (after in ring) |
Replay seq > after, then live |
| Duplicate / old seq | Client drops |
Client merge (chat-stream.ts)
Section titled “Client merge (chat-stream.ts)”- Optimistic user ids
c:*replaced when server usermessage_startarrives - Streaming assistant updates one slot until stable id
toolResultkeyed bytoolCallIdagent_settled/ errors clear turn phase
Do not invent “merge last message of same role”.
Tests that lock this
Section titled “Tests that lock this”server/sse-protocol.test.jsweb/src/lib/chat-stream.test.tsserver/stabilize.test.js
Change protocol only with these green.