@@ -26,7 +26,6 @@ import {
2626} from '@/lib/copilot/request/http'
2727import type { FilePreviewSession } from '@/lib/copilot/request/session'
2828import { readEvents } from '@/lib/copilot/request/session/buffer'
29- import { readFilePreviewSessions } from '@/lib/copilot/request/session/file-preview-session'
3029import { type StreamBatchEvent , toStreamBatchEvent } from '@/lib/copilot/request/session/types'
3130import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
3231import { captureServerEvent } from '@/lib/posthog/server'
@@ -50,7 +49,12 @@ export const GET = withRouteHandler(
5049 return NextResponse . json ( { success : false , error : 'Chat not found' } , { status : 404 } )
5150 }
5251
53- let streamSnapshot : {
52+ // The Redis replay buffer is read here only to synthesize the in-flight
53+ // assistant turn for the initial paint. The raw events are NOT shipped
54+ // to the client: when `activeStreamId` is set, the client reconnects to
55+ // the replay buffer (from seq 0) via the stream resume endpoint, which
56+ // is the source of truth for streaming state.
57+ let liveTurnSnapshot : {
5458 events : StreamBatchEvent [ ]
5559 previewSessions : FilePreviewSession [ ]
5660 status : string
@@ -64,17 +68,7 @@ export const GET = withRouteHandler(
6468
6569 if ( liveStreamId ) {
6670 try {
67- const [ events , previewSessions ] = await Promise . all ( [
68- readEvents ( liveStreamId , '0' ) ,
69- readFilePreviewSessions ( liveStreamId ) . catch ( ( error ) => {
70- logger . warn ( 'Failed to read preview sessions for mothership chat' , {
71- chatId,
72- streamId : liveStreamId ,
73- error : toError ( error ) . message ,
74- } )
75- return [ ]
76- } ) ,
77- ] )
71+ const events = await readEvents ( liveStreamId , '0' )
7872 const run = await getLatestRunForStream ( liveStreamId , userId ) . catch ( ( error ) => {
7973 logger . warn ( 'Failed to fetch latest run for mothership chat snapshot' , {
8074 chatId,
@@ -84,9 +78,9 @@ export const GET = withRouteHandler(
8478 return null
8579 } )
8680
87- streamSnapshot = {
81+ liveTurnSnapshot = {
8882 events : events . map ( toStreamBatchEvent ) ,
89- previewSessions,
83+ previewSessions : [ ] ,
9084 status :
9185 typeof run ?. status === 'string'
9286 ? run . status
@@ -111,7 +105,7 @@ export const GET = withRouteHandler(
111105 const effectiveMessages = buildEffectiveChatTranscript ( {
112106 messages : normalizedMessages ,
113107 activeStreamId : liveStreamId ,
114- ...( streamSnapshot ? { streamSnapshot } : { } ) ,
108+ ...( liveTurnSnapshot ? { streamSnapshot : liveTurnSnapshot } : { } ) ,
115109 } )
116110
117111 return NextResponse . json ( {
@@ -124,7 +118,6 @@ export const GET = withRouteHandler(
124118 resources : Array . isArray ( chat . resources ) ? chat . resources : [ ] ,
125119 createdAt : chat . createdAt ,
126120 updatedAt : chat . updatedAt ,
127- ...( streamSnapshot ? { streamSnapshot } : { } ) ,
128121 } ,
129122 } )
130123 } catch ( error ) {
0 commit comments