@@ -418,6 +418,75 @@ it.layer(NodeServices.layer)("effect-codex-app-server protocol", (it) => {
418418 } ) ,
419419 ) ;
420420
421+ it . effect ( "releases a waiting request handler when Codex resolves its request" , ( ) =>
422+ Effect . gen ( function * ( ) {
423+ const { stdio, input, output } = yield * makeInMemoryStdio ( ) ;
424+ yield * CodexProtocol . makeCodexAppServerPatchedProtocol ( {
425+ stdio,
426+ onRequest : ( request ) =>
427+ request . id === 33 ? Effect . succeed ( { decision : "accept" } ) : Effect . never ,
428+ } ) ;
429+
430+ const messages = Array . from ( { length : 32 } , ( _ , index ) =>
431+ encodeUnknownJsonString ( {
432+ id : index + 1 ,
433+ method : "item/commandExecution/requestApproval" ,
434+ params : { } ,
435+ } ) ,
436+ ) ;
437+ for ( let requestId = 1 ; requestId <= 32 ; requestId ++ ) {
438+ messages . push (
439+ encodeUnknownJsonString ( {
440+ method : "serverRequest/resolved" ,
441+ params : { threadId : "thread-1" , requestId } ,
442+ } ) ,
443+ ) ;
444+ }
445+ messages . push (
446+ encodeUnknownJsonString ( {
447+ id : 33 ,
448+ method : "item/commandExecution/requestApproval" ,
449+ params : { } ,
450+ } ) ,
451+ ) ;
452+ yield * Queue . offer ( input , encoder . encode ( `${ messages . join ( "\n" ) } \n` ) ) ;
453+
454+ assert . deepEqual ( yield * decodeJson ( yield * Queue . take ( output ) ) , {
455+ id : 33 ,
456+ result : { decision : "accept" } ,
457+ } ) ;
458+ } ) ,
459+ ) ;
460+
461+ it . effect ( "keeps numeric and string request ids apart when Codex resolves one" , ( ) =>
462+ Effect . gen ( function * ( ) {
463+ const { stdio, input, output } = yield * makeInMemoryStdio ( ) ;
464+ const interrupted : Array < string | number > = [ ] ;
465+ yield * CodexProtocol . makeCodexAppServerPatchedProtocol ( {
466+ stdio,
467+ onRequest : ( request ) =>
468+ request . id === 2
469+ ? Effect . sync ( ( ) => ( { interrupted } ) )
470+ : Effect . never . pipe (
471+ Effect . onInterrupt ( ( ) => Effect . sync ( ( ) => interrupted . push ( request . id ) ) ) ,
472+ ) ,
473+ } ) ;
474+
475+ const messages = [
476+ { id : 1 , method : "item/commandExecution/requestApproval" , params : { } } ,
477+ { id : "1" , method : "item/commandExecution/requestApproval" , params : { } } ,
478+ { method : "serverRequest/resolved" , params : { threadId : "thread-1" , requestId : "1" } } ,
479+ { id : 2 , method : "item/commandExecution/requestApproval" , params : { } } ,
480+ ] . map ( ( message ) => encodeUnknownJsonString ( message ) ) ;
481+ yield * Queue . offer ( input , encoder . encode ( `${ messages . join ( "\n" ) } \n` ) ) ;
482+
483+ assert . deepEqual ( yield * decodeJson ( yield * Queue . take ( output ) ) , {
484+ id : 2 ,
485+ result : { interrupted : [ "1" ] } ,
486+ } ) ;
487+ } ) ,
488+ ) ;
489+
421490 it . effect ( "interrupts pending request handlers when the protocol terminates" , ( ) =>
422491 Effect . gen ( function * ( ) {
423492 const { stdio, input } = yield * makeInMemoryStdio ( ) ;
0 commit comments