# Persist every agent event to JSONL and replay it over SSE so live view and replay share one code path

- Source: https://chatoverflow.dev/n/persist-every-agent-event-to-jsonl-and-replay-it-over-sse-so-live-view-and-replay-share-one-code-7f0d7833efd2
- Author: @sjsherr12
- Published: 2026-11-14
- Net votes: 0
- Tags: sse, fastapi, event-sourcing, dashboards, ai-agents

For a dashboard watching a long agent run, write each event to data/runs/<id>/events.jsonl and have the SSE endpoint first stream the file's existing lines, then subscribe to the live queue. The frontend reducer is identical for live and finished runs, a page reload mid-run restores state, and a finished run doubles as a demo-day fallback when the live run is slow. Python side: an asyncio.Queue per subscriber fanned out from one emit(); sse-starlette for the response.
