CL-6380: in-flight reply survives navigation and resumes on return - #123
Merged
Merged
Conversation
Covers reconstructing a running turn's committed text from turn_part rows, the turns route attaching that snapshot only while a turn is running, and useStreamingReply hydrating from a fetched snapshot on a fresh mount without ever clobbering a live event that already opened the reply.
A turn already ran entirely server-side — closing the SSE EventSource on unmount never touched it — but the client had no way to catch up: useStreamingReply/useTurnActivity reset to null on every mount, so returning to a workbench mid-reply showed nothing until the next token happened to arrive. Adds a read path for the catch-up: turnTextSnapshot reconstructs a running turn's visible text from the platform's own inference_turn/ turn_part rows (no new storage, same tables trace-reader.ts already reads), wired into GET /workbenches/:id/turns/:turnId behind an optional dep so a deployment without it just serves no snapshot. The client fetches this once per mount and hands it to useStreamingReply's new resumeFromTurn, which hydrates the reply immediately and is guarded to never override state a live event already produced.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
EventSourceon unmount was already a pure detach (no cancel/abort path exists), but the client had nothing to reattach to:useStreamingReply/useTurnActivityreset tonullon every mount, so returning to a workbench mid-reply showed nothing until the next token happened to arrive.turnTextSnapshotreconstructs a running turn's committed text from the platform's owninference_turn/turn_parttables (no new storage — the same tablestrace-reader.tsalready reads), wired intoGET /workbenches/:id/turns/:turnIdbehind an optional dep.fetchRunningTurn) and feeds it touseStreamingReply's newresumeFromTurn, which hydrates the reply immediately and is guarded to never override state a live SSE event already produced.Teardown path found (honest accounting)
useWorkbenchStream(packages/chat-ui/src/use-workbench-stream.ts) only ever callsEventSource#close()on unmount — no fetch, no cancel/abort call exists anywhere inchat-ui/chattied to unmount. The turn dispatch path (packages/chat/src/workbench-service.ts) has no dependency on any client connection, so navigating away was already safe for the turn itself. The actual gap was purely client-side: no snapshot on remount, and the streaming/typing indicator was derived from local component state (useState(null)on mount) rather than server turn state.Test plan
bun testinpackages/chat-ui,packages/chat,packages/insights(scoped)bunx tsc --noEmitinpackages/chat-ui,packages/chat,packages/insights,apps/hubeslint/prettieron touched files