@@ -2137,118 +2137,126 @@ describe("CodexAdapterV2 post-settle continuation", () => {
21372137 } ;
21382138 } ) ;
21392139
2140- it . effect ( "resubmits a voice handoff Codex started only after its turn is interrupted" , ( ) =>
2141- Effect . scoped (
2142- Effect . gen ( function * ( ) {
2143- const nativeThreadId = "voice-thread" ;
2144- const delegation = ( input : string ) =>
2145- `<realtime_delegation>\n <input>${ input } </input>\n</realtime_delegation>` ;
2146- const voiceTurn = (
2147- turnId : string ,
2148- request : string ,
2149- id : number ,
2150- status : "completed" | "interrupted" ,
2151- ) => [
2152- {
2153- type : "emit_inbound" as const ,
2154- label : `turn/started/${ turnId } ` ,
2155- frame : {
2156- method : "turn/started" ,
2157- params : {
2158- threadId : nativeThreadId ,
2159- turn : makeCodexReplayTurn ( { id : turnId , status : "inProgress" } ) ,
2140+ it . effect (
2141+ "resubmits a voice handoff Codex started only once its turn is interrupted or failed" ,
2142+ ( ) =>
2143+ Effect . scoped (
2144+ Effect . gen ( function * ( ) {
2145+ const nativeThreadId = "voice-thread" ;
2146+ const delegation = ( input : string ) =>
2147+ `<realtime_delegation>\n <input>${ input } </input>\n</realtime_delegation>` ;
2148+ const voiceTurn = (
2149+ turnId : string ,
2150+ request : string ,
2151+ id : number ,
2152+ status : "completed" | "interrupted" | "failed" ,
2153+ ) => [
2154+ {
2155+ type : "emit_inbound" as const ,
2156+ label : `turn/started/${ turnId } ` ,
2157+ frame : {
2158+ method : "turn/started" ,
2159+ params : {
2160+ threadId : nativeThreadId ,
2161+ turn : makeCodexReplayTurn ( { id : turnId , status : "inProgress" } ) ,
2162+ } ,
21602163 } ,
21612164 } ,
2162- } ,
2163- {
2164- type : "emit_inbound" as const ,
2165- label : `item/started/ ${ turnId } ` ,
2166- frame : {
2167- method : "item/started" ,
2168- params : {
2169- threadId : nativeThreadId ,
2170- turnId ,
2171- startedAtMs : 1782622440500 ,
2172- item : {
2173- type : "userMessage" ,
2174- id : `user- ${ turnId } ` ,
2175- content : [ { type : "text" , text : delegation ( request ) , text_elements : [ ] } ] ,
2165+ {
2166+ type : "emit_inbound" as const ,
2167+ label : `item/started/ ${ turnId } ` ,
2168+ frame : {
2169+ method : "item/started" ,
2170+ params : {
2171+ threadId : nativeThreadId ,
2172+ turnId ,
2173+ startedAtMs : 1782622440500 ,
2174+ item : {
2175+ type : "userMessage" ,
2176+ id : `user- ${ turnId } ` ,
2177+ content : [ { type : "text" , text : delegation ( request ) , text_elements : [ ] } ] ,
2178+ } ,
21762179 } ,
21772180 } ,
21782181 } ,
2179- } ,
2180- {
2181- type : "expect_outbound" as const ,
2182- label : ` turn/interrupt/ ${ turnId } ` ,
2183- frame : { id , method : "turn/interrupt" , params : { threadId : nativeThreadId , turnId } } ,
2184- } ,
2185- {
2186- type : "emit_inbound" as const ,
2187- label : `turn/interrupt/ ${ turnId } ` ,
2188- frame : { id , result : { } } ,
2189- } ,
2190- {
2191- type : "emit_inbound" as const ,
2192- label : `turn/completed/ ${ turnId } ` ,
2193- frame : {
2194- method : "turn/completed" ,
2195- params : {
2196- threadId : nativeThreadId ,
2197- turn : makeCodexReplayTurn ( { id : turnId , status } ) ,
2182+ {
2183+ type : "expect_outbound" as const ,
2184+ label : `turn/interrupt/ ${ turnId } ` ,
2185+ frame : { id , method : " turn/interrupt" , params : { threadId : nativeThreadId , turnId } } ,
2186+ } ,
2187+ {
2188+ type : "emit_inbound" as const ,
2189+ label : `turn/interrupt/ ${ turnId } ` ,
2190+ frame : { id , result : { } } ,
2191+ } ,
2192+ {
2193+ type : "emit_inbound" as const ,
2194+ label : `turn/completed/ ${ turnId } ` ,
2195+ frame : {
2196+ method : "turn/completed" ,
2197+ params : {
2198+ threadId : nativeThreadId ,
2199+ turn : makeCodexReplayTurn ( { id : turnId , status } ) ,
2200+ } ,
21982201 } ,
21992202 } ,
2200- } ,
2201- ] ;
2202- const harness = yield * makeCodexReplayHarness (
2203- makeCodexReplayTranscript ( {
2204- scenario : "voice-handoff-resubmit" ,
2205- entries : [
2206- // Initialization and thread/start only; Codex, not T3, starts these turns.
2207- ...codexReplayPreamble ( { nativeThreadId, nativeTurnId : "unused" , prompt : "" } ) . slice (
2208- 0 ,
2209- - 3 ,
2210- ) ,
2211- {
2212- type : "expect_outbound" ,
2213- label : "thread/realtime/start" ,
2214- frame : {
2215- id : 3 ,
2216- method : "thread/realtime/start" ,
2217- params : {
2218- threadId : nativeThreadId ,
2219- outputModality : "audio" ,
2220- transport : { type : "webrtc" , sdp : "v=offer\r\n" } ,
2221- version : "v3" ,
2222- clientManagedHandoffs : true ,
2223- includeStartupContext : false ,
2203+ ] ;
2204+ const harness = yield * makeCodexReplayHarness (
2205+ makeCodexReplayTranscript ( {
2206+ scenario : "voice-handoff-resubmit" ,
2207+ entries : [
2208+ // Initialization and thread/start only; Codex, not T3, starts these turns.
2209+ ...codexReplayPreamble ( {
2210+ nativeThreadId,
2211+ nativeTurnId : "unused" ,
2212+ prompt : "" ,
2213+ } ) . slice ( 0 , - 3 ) ,
2214+ {
2215+ type : "expect_outbound" ,
2216+ label : "thread/realtime/start" ,
2217+ frame : {
2218+ id : 3 ,
2219+ method : "thread/realtime/start" ,
2220+ params : {
2221+ threadId : nativeThreadId ,
2222+ outputModality : "audio" ,
2223+ transport : { type : "webrtc" , sdp : "v=offer\r\n" } ,
2224+ version : "v3" ,
2225+ clientManagedHandoffs : true ,
2226+ includeStartupContext : false ,
2227+ } ,
22242228 } ,
22252229 } ,
2226- } ,
2227- {
2228- type : "emit_inbound" ,
2229- label : "thread/realtime/start" ,
2230- frame : { id : 3 , result : { } } ,
2231- } ,
2232- // The interrupt lost the race: Codex finished, so it must not run twice.
2233- ...voiceTurn ( "voice-raced" , "already done" , 4 , "completed" ) ,
2234- ...voiceTurn ( "voice-stopped" , "run the tests" , 5 , "interrupted" ) ,
2235- ] ,
2236- } ) ,
2237- ) ;
2238- yield * harness . runtime . startVoiceSession ! ( {
2239- providerThread : harness . providerThread ,
2240- offerSdp : "v=offer\r\n" ,
2241- } ) . pipe ( Stream . runDrain , Effect . forkScoped ) ;
2242-
2243- yield * awaitUntil ( ( ) => harness . continuationRequests . length === 1 , "voice resubmit" ) ;
2244- assert . lengthOf ( harness . continuationRequests , 1 ) ;
2245- const request = harness . continuationRequests [ 0 ] ;
2246- assert . equal ( request ?. origin , "voice" ) ;
2247- assert . equal ( request ?. delivery , "message_text" ) ;
2248- assert . equal ( request ?. detail , "run the tests" ) ;
2249- assert . equal ( request ?. providerThreadId , harness . providerThread . id ) ;
2250- } ) . pipe ( Effect . provide ( Layer . merge ( idAllocatorLayer , NodeServices . layer ) ) ) ,
2251- ) ,
2230+ {
2231+ type : "emit_inbound" ,
2232+ label : "thread/realtime/start" ,
2233+ frame : { id : 3 , result : { } } ,
2234+ } ,
2235+ // The interrupt lost the race: Codex finished, so it must not run twice.
2236+ ...voiceTurn ( "voice-raced" , "already done" , 4 , "completed" ) ,
2237+ ...voiceTurn ( "voice-stopped" , "run the tests" , 5 , "interrupted" ) ,
2238+ // A failed turn never did the work either, so its request is kept.
2239+ ...voiceTurn ( "voice-failed" , "open a pull request" , 6 , "failed" ) ,
2240+ ] ,
2241+ } ) ,
2242+ ) ;
2243+ yield * harness . runtime . startVoiceSession ! ( {
2244+ providerThread : harness . providerThread ,
2245+ offerSdp : "v=offer\r\n" ,
2246+ } ) . pipe ( Stream . runDrain , Effect . forkScoped ) ;
2247+
2248+ yield * awaitUntil ( ( ) => harness . continuationRequests . length === 2 , "voice resubmits" ) ;
2249+ assert . deepEqual (
2250+ harness . continuationRequests . map ( ( entry ) => entry . detail ) ,
2251+ [ "run the tests" , "open a pull request" ] ,
2252+ ) ;
2253+ const request = harness . continuationRequests [ 0 ] ;
2254+ assert . equal ( request ?. origin , "voice" ) ;
2255+ assert . equal ( request ?. delivery , "message_text" ) ;
2256+ assert . equal ( request ?. detail , "run the tests" ) ;
2257+ assert . equal ( request ?. providerThreadId , harness . providerThread . id ) ;
2258+ } ) . pipe ( Effect . provide ( Layer . merge ( idAllocatorLayer , NodeServices . layer ) ) ) ,
2259+ ) ,
22522260 ) ;
22532261
22542262 it . effect . each ( [ "supported" , "unsupported" , "invalid" ] as const ) (
0 commit comments