fix(dashboard): replay buffered planning thinking events on first connect

The /planning/:sessionId/stream route only replayed buffered events when
the client sent a Last-Event-ID (resume case). On a fresh subscription it
just attached as a live subscriber. On slower devices (mobile especially),
the agent often streamed several thinking deltas into the buffer before
the SSE connection finished establishing — so the user saw the spinner
sit there, then a question appear out of nowhere, with no streaming
"thinking" content.

When a session has no current question or summary yet (i.e. the agent is
generating its first response) and the client connects without a
Last-Event-ID, replay every buffered event before attaching the live
subscription. This catches up the user on the in-flight thinking stream.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-25 11:17:43 -07:00
parent 59306284e6
commit a8124da1ff

View File

@@ -9713,6 +9713,18 @@ export function createApiRoutes(store: TaskStore, options?: ServerOptions): Rout
}
}
// Don't return — subscribe to continue receiving events (thinking, next question, etc.)
} else if (lastEventId === undefined) {
// First-connect catch-up for a session that is still generating its
// first response: there is no question or summary yet, but the agent
// may already be streaming thinking deltas into the buffer faster
// than the client could establish the SSE connection. Replay every
// buffered event so the user sees the running thinking output from
// the start of generation, especially on slower mobile connections.
const buffered = planningStreamManager.getBufferedEvents(sessionId, 0);
if (!replayBufferedSSE(res, buffered)) {
res.end();
return;
}
}
// Subscribe to session events