@@ -276,6 +276,7 @@ describe("ChatGPT Responses encrypted replay recovery", () => {
276276
277277 it ( "SSE suppresses rejected compaction only after successful stripped recovery" , async ( ) => {
278278 const context = createReplayContext ( "compaction" ) ;
279+ const onCompactionRejected = vi . fn ( ) ;
279280 const observations : ResponsesPromptObservation [ ] = [ ] ;
280281 const requests : RecordedRequest [ ] = [ ] ;
281282 const responses = [
@@ -295,7 +296,13 @@ describe("ChatGPT Responses encrypted replay recovery", () => {
295296 } ) ,
296297 ) ;
297298 const options = createObservedOptions (
298- { apiKey : createJwt ( ) , transport : "sse" as const , maxRetries : 0 , ...REPLAY_IDENTITY } ,
299+ {
300+ apiKey : createJwt ( ) ,
301+ transport : "sse" as const ,
302+ maxRetries : 0 ,
303+ onCompactionRejected,
304+ ...REPLAY_IDENTITY ,
305+ } ,
299306 observations ,
300307 ) ;
301308
@@ -324,6 +331,7 @@ describe("ChatGPT Responses encrypted replay recovery", () => {
324331 "initial" ,
325332 ] ) ;
326333 expect ( JSON . stringify ( observations ) ) . not . toContain ( COMPACTION_CIPHERTEXT ) ;
334+ expect ( onCompactionRejected ) . toHaveBeenCalledOnce ( ) ;
327335 } ) ;
328336
329337 it ( "SSE preserves compaction when reasoning-stripped recovery succeeds" , async ( ) => {
@@ -364,6 +372,7 @@ describe("ChatGPT Responses encrypted replay recovery", () => {
364372
365373 it ( "SSE failed final recovery leaves compaction replayable on the next turn" , async ( ) => {
366374 const context = createReplayContext ( "mixed" ) ;
375+ const onCompactionRejected = vi . fn ( ) ;
367376 const requests : RecordedRequest [ ] = [ ] ;
368377 const responses = [
369378 errorResponse ( "invalid_encrypted_content" ) ,
@@ -382,12 +391,14 @@ describe("ChatGPT Responses encrypted replay recovery", () => {
382391 apiKey : createJwt ( ) ,
383392 transport : "sse" as const ,
384393 maxRetries : 0 ,
394+ onCompactionRejected,
385395 ...REPLAY_IDENTITY ,
386396 } ;
387397
388398 const failed = await streamOpenAICodexResponses ( model , context , options ) . result ( ) ;
389399 expect ( failed ) . toMatchObject ( { stopReason : "error" , errorMessage : "unsupported_parameter" } ) ;
390400 expect ( failed . providerReplay ) . toBeUndefined ( ) ;
401+ expect ( onCompactionRejected ) . not . toHaveBeenCalled ( ) ;
391402 await streamOpenAICodexResponses ( model , nextTurn ( context , failed ) , options ) . result ( ) ;
392403
393404 expect ( requests ) . toHaveLength ( 4 ) ;
@@ -496,14 +507,20 @@ describe("ChatGPT Responses encrypted replay recovery", () => {
496507
497508 it ( "WebSocket suppresses rejected compaction after output starts and reacquires" , async ( ) => {
498509 const context = createReplayContext ( "compaction" ) ;
510+ const onCompactionRejected = vi . fn ( ) ;
499511 const observations : ResponsesPromptObservation [ ] = [ ] ;
500512 const scripted = installScriptedWebSocket ( [
501513 { events : [ invalidEncryptedEvent ( ) ] } ,
502514 { events : [ completionEvent ( "resp_ws_recovered" ) ] } ,
503515 { events : [ completionEvent ( "resp_ws_next" ) ] } ,
504516 ] ) ;
505517 const options = createObservedOptions (
506- { apiKey : createJwt ( ) , transport : "websocket" as const , ...REPLAY_IDENTITY } ,
518+ {
519+ apiKey : createJwt ( ) ,
520+ transport : "websocket" as const ,
521+ onCompactionRejected,
522+ ...REPLAY_IDENTITY ,
523+ } ,
507524 observations ,
508525 ) ;
509526
@@ -526,6 +543,7 @@ describe("ChatGPT Responses encrypted replay recovery", () => {
526543 "compaction-stripped" ,
527544 "initial" ,
528545 ] ) ;
546+ expect ( onCompactionRejected ) . toHaveBeenCalledOnce ( ) ;
529547 } ) ;
530548
531549 it ( "WebSocket preserves compaction when reasoning-stripped recovery succeeds" , async ( ) => {
@@ -558,17 +576,24 @@ describe("ChatGPT Responses encrypted replay recovery", () => {
558576
559577 it ( "WebSocket final recovery failure leaves replay for the next turn" , async ( ) => {
560578 const context = createReplayContext ( "mixed" ) ;
579+ const onCompactionRejected = vi . fn ( ) ;
561580 const scripted = installScriptedWebSocket ( [
562581 { events : [ invalidEncryptedEvent ( ) ] } ,
563582 { events : [ invalidEncryptedEvent ( ) ] } ,
564583 { events : [ unrelatedErrorEvent ( ) ] } ,
565584 { events : [ completionEvent ( "resp_ws_after_failure" ) ] } ,
566585 ] ) ;
567- const options = { apiKey : createJwt ( ) , transport : "websocket" as const , ...REPLAY_IDENTITY } ;
586+ const options = {
587+ apiKey : createJwt ( ) ,
588+ transport : "websocket" as const ,
589+ onCompactionRejected,
590+ ...REPLAY_IDENTITY ,
591+ } ;
568592
569593 const failed = await streamOpenAICodexResponses ( model , context , options ) . result ( ) ;
570594 expect ( failed . stopReason ) . toBe ( "error" ) ;
571595 expect ( failed . providerReplay ) . toBeUndefined ( ) ;
596+ expect ( onCompactionRejected ) . not . toHaveBeenCalled ( ) ;
572597 await streamOpenAICodexResponses ( model , nextTurn ( context , failed ) , options ) . result ( ) ;
573598
574599 expect ( scripted . sockets . slice ( 0 , 3 ) . every ( ( socket ) => socket . closed ) ) . toBe ( true ) ;
0 commit comments