@@ -3226,75 +3226,87 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
32263226 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
32273227 ) ;
32283228
3229- it . effect ( "settles native image tasks when reconnect attempts fail" , ( ) =>
3230- Effect . gen ( function * ( ) {
3231- const attempts = yield * Effect . forEach ( [ 0 , 1 , 2 , 3 , 4 ] , ( ) => Deferred . make < void > ( ) ) ;
3232- let count = 0 ;
3233- let failures = 0 ;
3234- const borrowers = {
3235- get current ( ) {
3236- return count ;
3237- } ,
3238- set current ( next : number ) {
3239- if ( next < count && count === 2 ) {
3240- const attempt = attempts [ failures ++ ] ;
3241- if ( attempt !== undefined ) Deferred . doneUnsafe ( attempt , Effect . void ) ;
3242- }
3243- count = next ;
3244- } ,
3245- } ;
3246- const tool = {
3247- sessionID : SESSION ,
3248- assistantMessageID : "msg_assistant" ,
3249- id : "call-image-lost" ,
3250- } ;
3251- const { runtime, thread } = yield * resumed (
3252- [
3253- out ( "session.prompt" , { sessionID : SESSION , text : "<any>" } ) ,
3254- promptAccepted ,
3255- event ( "session.tool.input.started" , { ...tool , name : "experimental_image_generate" } ) ,
3256- event (
3257- "session.tool.success" ,
3258- {
3259- ...tool ,
3260- content : [ { type : "text" , text : "Launched" } ] ,
3261- metadata : { jobID : "image_lost" , path : "/tmp/image" , model : "test/image" } ,
3262- executed : false ,
3263- } ,
3264- undefined ,
3265- 2 ,
3229+ it . effect . each ( [ "root" , "child" ] as const ) (
3230+ "settles %s native image tasks when reconnect attempts fail" ,
3231+ ( owner ) =>
3232+ Effect . gen ( function * ( ) {
3233+ const attempts = yield * Effect . forEach ( [ 0 , 1 , 2 , 3 , 4 ] , ( ) => Deferred . make < void > ( ) ) ;
3234+ let count = 0 ;
3235+ let failures = 0 ;
3236+ const borrowers = {
3237+ get current ( ) {
3238+ return count ;
3239+ } ,
3240+ set current ( next : number ) {
3241+ if ( next < count && count === 2 ) {
3242+ const attempt = attempts [ failures ++ ] ;
3243+ if ( attempt !== undefined ) Deferred . doneUnsafe ( attempt , Effect . void ) ;
3244+ }
3245+ count = next ;
3246+ } ,
3247+ } ;
3248+ const tool = {
3249+ sessionID : owner === "root" ? SESSION : CHILD ,
3250+ assistantMessageID : "msg_assistant" ,
3251+ id : "call-image-lost" ,
3252+ } ;
3253+ const { runtime, thread } = yield * resumed (
3254+ [
3255+ ...( owner === "root"
3256+ ? [ out ( "session.prompt" , { sessionID : SESSION , text : "<any>" } ) , promptAccepted ]
3257+ : [
3258+ ...backgroundLaunch ( CHILD ) ,
3259+ event ( "session.execution.started" , { sessionID : CHILD } ) ,
3260+ ] ) ,
3261+ event ( "session.tool.input.started" , { ...tool , name : "experimental_image_generate" } ) ,
3262+ event (
3263+ "session.tool.success" ,
3264+ {
3265+ ...tool ,
3266+ content : [ { type : "text" , text : "Launched" } ] ,
3267+ metadata : { jobID : "image_lost" , path : "/tmp/image" , model : "test/image" } ,
3268+ executed : false ,
3269+ } ,
3270+ undefined ,
3271+ 2 ,
3272+ ) ,
3273+ ...( owner === "child"
3274+ ? [ event ( "session.execution.succeeded" , { sessionID : CHILD } ) ]
3275+ : [ ] ) ,
3276+ event ( "session.execution.succeeded" , { sessionID : SESSION } ) ,
3277+ { type : "runtime_exit" , status : "success" } ,
3278+ ] ,
3279+ { borrowers } ,
3280+ ) ;
3281+ const events = yield * runtime . events . pipe ( Stream . runCollect , Effect . forkScoped ) ;
3282+ yield * runtime . startTurn ( withLineage ( thread ) ) ;
3283+ yield * Deferred . await ( attempts [ 0 ] ! ) ;
3284+ for ( const attempt of attempts . slice ( 1 ) ) {
3285+ yield * TestClock . adjust ( "2 seconds" ) ;
3286+ yield * Deferred . await ( attempt ) ;
3287+ }
3288+ const collected = yield * Fiber . join ( events ) ;
3289+ assert . isFalse ( yield * runtime . hasPendingBackgroundWorkForThread ! ( thread ) ) ;
3290+ assert . isTrue (
3291+ collected . some (
3292+ ( e ) =>
3293+ e . type === "turn_item.updated" &&
3294+ e . turnItem . nativeItemRef ?. nativeId ===
3295+ ( owner === "root" ? tool . id : `${ CHILD } :${ tool . id } ` ) &&
3296+ e . turnItem . status === "failed" ,
32663297 ) ,
3267- event ( "session.execution.succeeded" , { sessionID : SESSION } ) ,
3268- { type : "runtime_exit" , status : "success" } ,
3269- ] ,
3270- { borrowers } ,
3271- ) ;
3272- const events = yield * runtime . events . pipe ( Stream . runCollect , Effect . forkScoped ) ;
3273- yield * runtime . startTurn ( turnInput ( thread ) ) ;
3274- yield * Deferred . await ( attempts [ 0 ] ! ) ;
3275- for ( const attempt of attempts . slice ( 1 ) ) {
3276- yield * TestClock . adjust ( "2 seconds" ) ;
3277- yield * Deferred . await ( attempt ) ;
3278- }
3279- const collected = yield * Fiber . join ( events ) ;
3280- assert . isFalse ( yield * runtime . hasPendingBackgroundWorkForThread ! ( thread ) ) ;
3281- assert . isTrue (
3282- collected . some (
3283- ( e ) =>
3284- e . type === "turn_item.updated" &&
3285- e . turnItem . nativeItemRef ?. nativeId === tool . id &&
3286- e . turnItem . status === "failed" ,
3287- ) ,
3288- ) ;
3289- assert . deepEqual (
3290- collected
3291- . flatMap ( ( e ) =>
3292- e . type === "provider_thread.updated" ? [ e . providerThread . pendingBackgroundTasks ] : [ ] ,
3293- )
3294- . at ( - 1 ) ,
3295- [ ] ,
3296- ) ;
3297- } ) . pipe ( Effect . scoped ) ,
3298+ ) ;
3299+ const rootSnapshots = collected . flatMap ( ( e ) =>
3300+ e . type === "provider_thread.updated" && e . providerThread . id === thread . id ? [ e ] : [ ] ,
3301+ ) ;
3302+ assert . isFalse ( rootSnapshots . at ( - 1 ) ?. pendingBackgroundWork ) ;
3303+ assert . deepEqual ( rootSnapshots . at ( - 1 ) ?. providerThread . pendingBackgroundTasks , [ ] ) ;
3304+ assert . isTrue (
3305+ rootSnapshots . some ( ( e ) =>
3306+ e . providerThread . pendingBackgroundTasks ?. some ( ( task ) => task . taskId === "image_lost" ) ,
3307+ ) ,
3308+ ) ;
3309+ } ) . pipe ( Effect . scoped ) ,
32983310 ) ;
32993311
33003312 it . effect ( "projects successful native todo updates into one checklist" , ( ) =>
0 commit comments