@@ -21,7 +21,26 @@ const agentRuntimePath = path.join(
2121 "plugin-sdk" ,
2222 "agent-runtime.js" ,
2323) ;
24+ const startedAt = Date . now ( ) ;
25+ const markPhase = ( phase ) => {
26+ const resources = new Map ( ) ;
27+ for ( const type of process . getActiveResourcesInfo ( ) ) {
28+ resources . set ( type , ( resources . get ( type ) ?? 0 ) + 1 ) ;
29+ }
30+ console . log (
31+ JSON . stringify ( {
32+ phase,
33+ elapsedMs : Date . now ( ) - startedAt ,
34+ resources : Object . fromEntries (
35+ [ ...resources ] . toSorted ( ( [ left ] , [ right ] ) => left . localeCompare ( right ) ) . slice ( 0 , 32 ) ,
36+ ) ,
37+ } ) ,
38+ ) ;
39+ } ;
40+ process . once ( "beforeExit" , ( ) => markPhase ( "followthrough:before-exit" ) ) ;
41+ markPhase ( "followthrough:import-start" ) ;
2442const { agentCommandFromIngress } = await import ( pathToFileURL ( agentRuntimePath ) . href ) ;
43+ markPhase ( "followthrough:import-complete" ) ;
2544if ( typeof agentCommandFromIngress !== "function" ) {
2645 throw new Error (
2746 `package agent runtime did not export agentCommandFromIngress: ${ agentRuntimePath } ` ,
@@ -35,6 +54,7 @@ const quietRuntime = {
3554 throw new Error ( `agent runtime exited with code ${ code } ` ) ;
3655 } ,
3756} ;
57+ markPhase ( "followthrough:turn-start" ) ;
3858const result = await agentCommandFromIngress (
3959 {
4060 agentId : "main" ,
@@ -56,4 +76,8 @@ const result = await agentCommandFromIngress(
5676 } ,
5777 quietRuntime ,
5878) ;
79+ markPhase ( "followthrough:turn-and-cleanup-complete" ) ;
5980fs . writeFileSync ( outputPath , `${ JSON . stringify ( result ) } \n` ) ;
81+ markPhase ( "followthrough:result-written" ) ;
82+ // Observe lingering resources without keeping a completed one-shot process alive.
83+ setTimeout ( ( ) => markPhase ( "followthrough:resources-after-result" ) , 1_000 ) . unref ( ) ;
0 commit comments