@@ -12,6 +12,7 @@ import { ILogService } from '../../../log/common/logService';
1212import { isOpenAIContextManagementResponse } from '../../../networking/common/fetch' ;
1313import { IChatEndpoint , ICreateEndpointBodyOptions } from '../../../networking/common/networking' ;
1414import { openAIContextManagementCompactionType , OpenAIContextManagementResponse } from '../../../networking/common/openai' ;
15+ import { IChatWebSocketManager , NullChatWebSocketManager } from '../../../networking/node/chatWebSocketManager' ;
1516import { TelemetryData } from '../../../telemetry/common/telemetryData' ;
1617import { SpyingTelemetryService } from '../../../telemetry/node/spyingTelemetryService' ;
1718import { createFakeStreamResponse } from '../../../test/node/fetcher' ;
@@ -307,6 +308,9 @@ describe('createResponsesRequestBody', () => {
307308
308309 it ( 'still slices websocket requests by stateful marker index when compaction is disabled' , ( ) => {
309310 const services = createPlatformServices ( ) ;
311+ const wsManager = new NullChatWebSocketManager ( ) ;
312+ wsManager . getStatefulMarker = ( ) => 'resp-prev' ;
313+ services . set ( IChatWebSocketManager , wsManager ) ;
310314 const accessor = services . createTestingAccessor ( ) ;
311315 const instantiationService = accessor . get ( IInstantiationService ) ;
312316 const endpointWithoutCompaction = { ...testEndpoint , family : 'gpt-5' as const } ;
@@ -322,7 +326,7 @@ describe('createResponsesRequestBody', () => {
322326 } ,
323327 ] ;
324328
325- const webSocketBody = instantiationService . invokeFunction ( servicesAccessor => createResponsesRequestBody ( servicesAccessor , createRequestOptions ( messages , true ) , endpointWithoutCompaction . model , endpointWithoutCompaction ) ) ;
329+ const webSocketBody = instantiationService . invokeFunction ( servicesAccessor => createResponsesRequestBody ( servicesAccessor , { ... createRequestOptions ( messages , true ) , conversationId : 'conv-1' } , endpointWithoutCompaction . model , endpointWithoutCompaction ) ) ;
326330
327331 expect ( webSocketBody . previous_response_id ) . toBe ( 'resp-prev' ) ;
328332 expect ( webSocketBody . input ) . toHaveLength ( 1 ) ;
@@ -337,6 +341,9 @@ describe('createResponsesRequestBody', () => {
337341
338342 it ( 'includes the newest compaction item in websocket requests when it predates the stateful marker' , ( ) => {
339343 const services = createPlatformServices ( ) ;
344+ const wsManager = new NullChatWebSocketManager ( ) ;
345+ wsManager . getStatefulMarker = ( ) => 'resp-prev' ;
346+ services . set ( IChatWebSocketManager , wsManager ) ;
340347 const accessor = services . createTestingAccessor ( ) ;
341348 const instantiationService = accessor . get ( IInstantiationService ) ;
342349 const latestCompaction = createCompactionResponse ( 'cmp_ws' , 'enc_ws' ) ;
@@ -353,7 +360,7 @@ describe('createResponsesRequestBody', () => {
353360 } ,
354361 ] ;
355362
356- const webSocketBody = instantiationService . invokeFunction ( servicesAccessor => createResponsesRequestBody ( servicesAccessor , createRequestOptions ( messages , true ) , testEndpoint . model , testEndpoint ) ) ;
363+ const webSocketBody = instantiationService . invokeFunction ( servicesAccessor => createResponsesRequestBody ( servicesAccessor , { ... createRequestOptions ( messages , true ) , conversationId : 'conv-1' } , testEndpoint . model , testEndpoint ) ) ;
357364
358365 expect ( webSocketBody . previous_response_id ) . toBe ( 'resp-prev' ) ;
359366 expect ( webSocketBody . input ) . toContainEqual ( {
@@ -370,6 +377,42 @@ describe('createResponsesRequestBody', () => {
370377 services . dispose ( ) ;
371378 } ) ;
372379
380+ it ( 'sends all messages when the websocket stateful marker is not in the current messages' , ( ) => {
381+ const services = createPlatformServices ( ) ;
382+ const wsManager = new NullChatWebSocketManager ( ) ;
383+ wsManager . getStatefulMarker = ( ) => 'resp-stale' ;
384+ services . set ( IChatWebSocketManager , wsManager ) ;
385+ const accessor = services . createTestingAccessor ( ) ;
386+ const instantiationService = accessor . get ( IInstantiationService ) ;
387+ const messages : Raw . ChatMessage [ ] = [
388+ {
389+ role : Raw . ChatRole . User ,
390+ content : [ { type : Raw . ChatCompletionContentPartKind . Text , text : 'first message' } ] ,
391+ } ,
392+ createStatefulMarkerMessage ( testEndpoint . model , 'resp-different' ) ,
393+ {
394+ role : Raw . ChatRole . User ,
395+ content : [ { type : Raw . ChatCompletionContentPartKind . Text , text : 'second message' } ] ,
396+ } ,
397+ ] ;
398+
399+ const body = instantiationService . invokeFunction ( servicesAccessor => createResponsesRequestBody ( servicesAccessor , { ...createRequestOptions ( messages , true ) , conversationId : 'conv-1' } , testEndpoint . model , testEndpoint ) ) ;
400+
401+ expect ( body . previous_response_id ) . toBeUndefined ( ) ;
402+ expect ( body . input ) . toHaveLength ( 2 ) ;
403+ expect ( body . input ?. [ 0 ] ) . toMatchObject ( {
404+ role : 'user' ,
405+ content : [ { type : 'input_text' , text : 'first message' } ] ,
406+ } ) ;
407+ expect ( body . input ?. [ 1 ] ) . toMatchObject ( {
408+ role : 'user' ,
409+ content : [ { type : 'input_text' , text : 'second message' } ] ,
410+ } ) ;
411+
412+ accessor . dispose ( ) ;
413+ services . dispose ( ) ;
414+ } ) ;
415+
373416 it ( 'includes the newest compaction item in non-websocket requests when it predates the stateful marker' , ( ) => {
374417 const services = createPlatformServices ( ) ;
375418 const accessor = services . createTestingAccessor ( ) ;
0 commit comments