What's fixed
The WebUI no longer injects a fake **Error:** Connection lost assistant message when an SSE connection drops after the stream already completed normally.
Root cause
The old error handler treated every EventSource disconnect as a potential failure. If the stream was no longer active server-side, it called _handleStreamError() and appended the error message — even when the stream had already finished cleanly and the SSE connection simply dropped afterward.
Fix
- Track terminal stream states (
done,stream_end,cancel,apperror) with a_terminalStateReachedflag - If the flag is set when an
errorevent fires, close the source and return immediately — no reconnect, no error message - When reconnect/status shows the stream inactive, call
_restoreSettledSession()which fetches/api/sessionand restores the completed session if it's settled (active_stream_id == nulland no pending message) - Real failures still go through the existing error path unchanged
Credit
Thanks to @halmisen for the bug report (issue #561) and the fix (PR #562). Validated against 1319 tests + browser QA.