@@ -252,6 +252,7 @@ function harness(
252252 signals,
253253 artifacts,
254254 emit,
255+ close,
255256 interrupt : ( ) => interrupt ( ) ,
256257 get cleaned ( ) {
257258 return cleaned
@@ -1051,57 +1052,68 @@ describe("agent fixture controller", () => {
10511052 assert . equal ( result . teardown . status , "ok" )
10521053 } )
10531054
1054- it ( "holds teardown after the completion message for the requested window" , async ( ) => {
1055- registerTestFixture ( "controller-hold" )
1056- const f = harness ( "no-events" )
1057- f . emit ( {
1058- eventName : RooCodeEventName . Message ,
1059- payload : [
1060- {
1061- taskId : "root" ,
1062- action : "created" ,
1063- message : { ts : 1 , type : "say" , say : "completion_result" , text : "synthetic final answer" } ,
1064- } ,
1065- ] ,
1066- } )
1067- f . emit ( {
1068- eventName : RooCodeEventName . TaskCompleted ,
1069- payload : [
1070- "root" ,
1071- { totalTokensIn : 7 , totalTokensOut : 3 , totalCost : 0 , contextTokens : 9 } ,
1072- { } ,
1073- {
1074- isSubtask : false ,
1075- } ,
1076- ] ,
1077- } )
1078- const holdPauses : number [ ] = [ ]
1079- let closeTaskSeenDuringHold = false
1080- const pause = f . runtime . pause
1081- f . runtime . pause = async ( ms ) => {
1082- if ( ms === 3_000 ) {
1083- holdPauses . push ( ms )
1084- closeTaskSeenDuringHold = f . commands . some (
1085- ( command ) => command . commandName === TaskCommandName . CloseTask ,
1086- )
1055+ for ( const hostExited of [ false , true ] ) {
1056+ it ( `holds teardown only while the completed host is live (exited=${ hostExited } )` , async ( ) => {
1057+ const fixtureName = `controller-hold-${ hostExited } `
1058+ registerTestFixture ( fixtureName )
1059+ const f = harness ( "no-events" )
1060+ f . emit ( {
1061+ eventName : RooCodeEventName . Message ,
1062+ payload : [
1063+ {
1064+ taskId : "root" ,
1065+ action : "created" ,
1066+ message : { ts : 1 , type : "say" , say : "completion_result" , text : "synthetic final answer" } ,
1067+ } ,
1068+ ] ,
1069+ } )
1070+ f . emit ( {
1071+ eventName : RooCodeEventName . TaskCompleted ,
1072+ payload : [
1073+ "root" ,
1074+ { totalTokensIn : 7 , totalTokensOut : 3 , totalCost : 0 , contextTokens : 9 } ,
1075+ { } ,
1076+ {
1077+ isSubtask : false ,
1078+ } ,
1079+ ] ,
1080+ } )
1081+ const holdPauses : number [ ] = [ ]
1082+ let closeTaskSeenDuringHold = false
1083+ const pause = f . runtime . pause
1084+ f . runtime . pause = async ( ms ) => {
1085+ if ( ms === 3_000 ) {
1086+ holdPauses . push ( ms )
1087+ closeTaskSeenDuringHold = f . commands . some (
1088+ ( command ) => command . commandName === TaskCommandName . CloseTask ,
1089+ )
1090+ }
1091+ await pause ( ms )
10871092 }
1088- await pause ( ms )
1089- }
1090- const result = await runAgentFixture ( f . runtime , {
1091- fixtureName : "controller-hold" ,
1092- credential : CREDENTIAL ,
1093- observers : { shouldStop : ( ) => true } ,
1094- holdBeforeTeardownMs : 3_000 ,
1093+ const result = await runAgentFixture ( f . runtime , {
1094+ fixtureName,
1095+ credential : CREDENTIAL ,
1096+ observers : {
1097+ onAcceptedEvent : ( event ) => {
1098+ if ( hostExited && event . eventName === RooCodeEventName . TaskCompleted ) f . close ( )
1099+ } ,
1100+ shouldStop : ( ) => true ,
1101+ } ,
1102+ holdBeforeTeardownMs : 3_000 ,
1103+ } )
1104+ assert . equal ( result . execution . code , "COMPLETED" )
1105+ assert . equal ( result . execution . completionMessageSeen , true )
1106+ assert . deepEqual ( holdPauses , hostExited ? [ ] : [ 3_000 ] )
1107+ // The hold runs before teardown, so CloseTask is sent only after it.
1108+ assert . equal ( closeTaskSeenDuringHold , false )
1109+ assert . equal ( f . commands . at ( - 1 ) ?. commandName , TaskCommandName . CloseTask )
1110+ assert . equal ( result . teardown . status , "ok" )
1111+ assert . equal ( result . teardown . hostExited , true )
1112+ const trace = writtenTrace ( f )
1113+ // CloseTask exits immediately, so none of the recording hold belongs to teardown.
1114+ assert . equal ( trace . execution . timings . teardownMs , 0 )
10951115 } )
1096- assert . equal ( result . execution . code , "COMPLETED" )
1097- assert . equal ( result . execution . completionMessageSeen , true )
1098- assert . deepEqual ( holdPauses , [ 3_000 ] )
1099- // The hold runs before teardown, so CloseTask is sent only after it.
1100- assert . equal ( closeTaskSeenDuringHold , false )
1101- assert . equal ( f . commands . at ( - 1 ) ?. commandName , TaskCommandName . CloseTask )
1102- assert . equal ( result . teardown . status , "ok" )
1103- } )
1104-
1116+ }
11051117 it ( "skips the teardown hold without a completion message" , async ( ) => {
11061118 registerTestFixture ( "controller-hold-skipped" , {
11071119 limits : {
0 commit comments