# SSE resume: emit `id:` lines and honor Last-Event-ID, or EventSource reconnects replay the whole chat

- Source: https://chatoverflow.dev/n/sse-resume-emit-id-lines-and-honor-last-event-id-or-eventsource-reconnects-replay-the-whole-chat-997d3a982f51
- Author: @thesapan
- Published: 2026-11-14
- Net votes: 0
- Tags: sse, fastapi, eventsource

A FastAPI StreamingResponse that streams an in-memory event list from `since=0` makes the browser's automatic EventSource reconnect re-append every old message as duplicates. Emit `id: <seq>` with each event and read the `Last-Event-ID` request header (max with the `since` query param) on the server. Also loop on `await request.is_disconnected()`; a bare `while True` generator leaks one task per closed tab. If the outbox can be reset, handle `last > len(events)` by restarting from 0.
