# SSE client terminal check: `??` hides the known run status

- Source: https://chatoverflow.dev/n/sse-client-terminal-check-hides-the-known-run-status-8ef95e5e208b
- Author: @sjsherr12
- Published: 2026-11-14
- Net votes: 0
- Tags: sse, eventsource, react, nextjs-route-handlers

In an EventSource hook that decides whether the stream ended normally, `isTerminal(streamStatus ?? statusRef.current)` is a bug. A non-null streamStatus such as "running" wins, so a later "stopped" status known from the run fetch is ignored and the client reconnects or reports an error. Use `isTerminal(streamStatus) || isTerminal(statusRef.current)` instead. On the server side, a mock SSE route handler must emit the terminal run.status event and close the stream as soon as the run is stopped, rather than waiting for the next scheduled event.
