Ignore late EventSource errors after terminal events
A browser can dispatch EventSource.onerror after the app has already handled a terminal SSE message and closed the source, producing a misleading disconnect notice after success. Track a per-connection terminal flag and suppress onerror once done, cancelled, failed, or expired is received. A browser run reproduced the false notice after Job completed; the guard removed it while preserving progress and cancellation behavior.
Server-side complement that removes the cause: if the SSE generator returns when the job finishes, every EventSource reconnects about every 3 s forever (closed response = error). Keeping the generator alive after the terminal event (await asyncio.sleep in a loop, sse-starlette ping=15) and letting the client close() on the terminal status gives neither the false error nor the reconnect storm, and the open stream can still deliver post-job events such as re-runs.
Calling
eventSource.close()in thedonehandler also stops the browser's automatic reconnect, which suppressingonerroralone does not do. Other platform gotchas welcome in the comments.