@@ -432,6 +432,116 @@ describe("OpenAI Responses passthrough sanitization", () => {
432432 expect ( body . input ) . toEqual ( input ) ;
433433 } ) ;
434434
435+ test ( "forward mode repairs oversized call ids consistently across paired replay items" , ( ) => {
436+ const adapter = createResponsesPassthroughAdapter ( provider ) ;
437+ const oversizedCallId = `call_${ "x" . repeat ( 80 ) } ` ;
438+ const input = [
439+ { type : "function_call" , call_id : oversizedCallId , name : "ping" , arguments : "{}" } ,
440+ { type : "function_call_output" , call_id : oversizedCallId , output : "pong" } ,
441+ { type : "function_call" , call_id : "call_short" , name : "keep" , arguments : "{}" } ,
442+ { type : "function_call_output" , call_id : "call_short" , output : "kept" } ,
443+ ] ;
444+
445+ const body = JSON . parse ( adapter . buildRequest ( {
446+ modelId : "gpt-5.6-sol" ,
447+ context : { messages : [ ] } ,
448+ stream : true ,
449+ options : { } ,
450+ _rawBody : { model : "gpt-5.6-sol" , input } ,
451+ } , meta ) . body ) as { input : Record < string , unknown > [ ] } ;
452+
453+ const repairedCallId = body . input [ 0 ] . call_id as string ;
454+ expect ( repairedCallId ) . toStartWith ( "call_ocx_" ) ;
455+ expect ( repairedCallId . length ) . toBeLessThanOrEqual ( 64 ) ;
456+ expect ( body . input [ 1 ] . call_id ) . toBe ( repairedCallId ) ;
457+ expect ( body . input [ 2 ] . call_id ) . toBe ( "call_short" ) ;
458+ expect ( body . input [ 3 ] . call_id ) . toBe ( "call_short" ) ;
459+ expect ( input [ 0 ] . call_id ) . toBe ( oversizedCallId ) ;
460+ expect ( input [ 1 ] . call_id ) . toBe ( oversizedCallId ) ;
461+ } ) ;
462+
463+ test ( "forward mode assigns distinct stable aliases to oversized custom and tool-search pairs" , ( ) => {
464+ const adapter = createResponsesPassthroughAdapter ( provider ) ;
465+ const customCallId = `call_custom_${ "a" . repeat ( 80 ) } ` ;
466+ const searchCallId = `call_search_${ "b" . repeat ( 80 ) } ` ;
467+ const input = [
468+ { type : "custom_tool_call" , call_id : customCallId , name : "apply_patch" , input : "patch" } ,
469+ { type : "custom_tool_call_output" , call_id : customCallId , output : "done" } ,
470+ { type : "tool_search_call" , call_id : searchCallId , execution : "client" , arguments : { } } ,
471+ { type : "tool_search_output" , call_id : searchCallId , tools : [ ] } ,
472+ ] ;
473+
474+ const build = ( ) => JSON . parse ( adapter . buildRequest ( {
475+ modelId : "gpt-5.6-sol" ,
476+ context : { messages : [ ] } ,
477+ stream : true ,
478+ options : { } ,
479+ _rawBody : { model : "gpt-5.6-sol" , input } ,
480+ } , meta ) . body ) as { input : Record < string , unknown > [ ] } ;
481+
482+ const first = build ( ) . input ;
483+ const second = build ( ) . input ;
484+ expect ( first [ 0 ] . call_id ) . toBe ( first [ 1 ] . call_id ) ;
485+ expect ( first [ 2 ] . call_id ) . toBe ( first [ 3 ] . call_id ) ;
486+ expect ( first [ 0 ] . call_id ) . not . toBe ( first [ 2 ] . call_id ) ;
487+ expect ( ( first [ 0 ] . call_id as string ) . length ) . toBeLessThanOrEqual ( 64 ) ;
488+ expect ( ( first [ 2 ] . call_id as string ) . length ) . toBeLessThanOrEqual ( 64 ) ;
489+ expect ( second . map ( item => item . call_id ) ) . toEqual ( first . map ( item => item . call_id ) ) ;
490+ } ) ;
491+
492+ test ( "api-key mode preserves oversized call ids that may reference upstream stored state" , ( ) => {
493+ const adapter = createResponsesPassthroughAdapter ( {
494+ adapter : "openai-responses" ,
495+ baseUrl : "https://api.openai.example/v1" ,
496+ authMode : "key" as const ,
497+ apiKey : "sk-test" ,
498+ } ) ;
499+ const oversizedCallId = `call_${ "stored" . repeat ( 14 ) } ` ;
500+ const input = [
501+ { type : "function_call_output" , call_id : oversizedCallId , output : "pong" } ,
502+ ] ;
503+
504+ const body = JSON . parse ( adapter . buildRequest ( {
505+ ...parsedBase ,
506+ _rawBody : {
507+ model : "gpt-5.5" ,
508+ previous_response_id : "resp_stored" ,
509+ input,
510+ } ,
511+ } , meta ) . body ) as { previous_response_id : string ; input : Array < { call_id : string } > } ;
512+
513+ expect ( body . previous_response_id ) . toBe ( "resp_stored" ) ;
514+ expect ( body . input [ 0 ] ?. call_id ) . toBe ( oversizedCallId ) ;
515+ } ) ;
516+
517+ test ( "api-key mode repairs oversized call ids after proxy-expanded replay" , ( ) => {
518+ const adapter = createResponsesPassthroughAdapter ( {
519+ adapter : "openai-responses" ,
520+ baseUrl : "https://api.openai.example/v1" ,
521+ authMode : "key" as const ,
522+ apiKey : "sk-test" ,
523+ } ) ;
524+ const oversizedCallId = `call_${ "expanded" . repeat ( 12 ) } ` ;
525+
526+ const body = JSON . parse ( adapter . buildRequest ( {
527+ ...parsedBase ,
528+ _previousResponseInputExpanded : true ,
529+ _rawBody : {
530+ model : "gpt-5.5" ,
531+ previous_response_id : "resp_expanded" ,
532+ input : [
533+ { type : "function_call" , call_id : oversizedCallId , name : "ping" , arguments : "{}" } ,
534+ { type : "function_call_output" , call_id : oversizedCallId , output : "pong" } ,
535+ ] ,
536+ } ,
537+ } , meta ) . body ) as { previous_response_id ?: string ; input : Array < { call_id : string } > } ;
538+
539+ expect ( body . previous_response_id ) . toBeUndefined ( ) ;
540+ expect ( body . input [ 0 ] ?. call_id ) . toStartWith ( "call_ocx_" ) ;
541+ expect ( body . input [ 0 ] ?. call_id . length ) . toBe ( 64 ) ;
542+ expect ( body . input [ 1 ] ?. call_id ) . toBe ( body . input [ 0 ] ?. call_id ) ;
543+ } ) ;
544+
435545 test ( "forward expanded replay keeps reasoning items (chain is intact)" , ( ) => {
436546 const adapter = createResponsesPassthroughAdapter ( provider ) ;
437547 const body = JSON . parse ( adapter . buildRequest ( {
0 commit comments