fix: SSE sends 'done' event for non-running threads, frontend stops reconnecting

- routes-live: emit 'done' event before closing SSE for non-running threads
- use-sse: handle 'done' event — set completed, disconnect, stop reconnect
- Prevents 'Live' badge flash on failed/completed threads

小橘 <xiaoju@shazhou.work>
This commit is contained in:
2026-05-09 12:49:20 +00:00
parent 22a6200b69
commit 08a79b77db
2 changed files with 16 additions and 0 deletions
@@ -310,6 +310,12 @@ export function createLiveRoutes(storageRoot: string): Hono {
// If thread is not actively running, emit all records and close — don't keep SSE open
const runningPath = join(storageRoot, "logs", threadTarget.bundleHash, `${threadId}.running`);
if (!existsSync(runningPath)) {
eventId.n++;
await stream.writeSSE({
event: "done",
data: JSON.stringify({ reason: "not-running" }),
id: String(eventId.n),
});
return;
}