@@ -2721,6 +2721,19 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
27212721 let initial_deadline =
27222722 timeout_seconds. map ( |seconds| Instant :: now ( ) + Duration :: from_secs ( seconds) ) ;
27232723 let ( deadline_tx, mut deadline_rx) = watch:: channel ( initial_deadline) ;
2724+ let subagent_started_at = Instant :: now ( ) ;
2725+ let parent_session_id = subagent_parent_info
2726+ . as_ref ( )
2727+ . map ( |info| info. session_id . as_str ( ) )
2728+ . unwrap_or ( "-" ) ;
2729+ let parent_dialog_turn_id = subagent_parent_info
2730+ . as_ref ( )
2731+ . map ( |info| info. dialog_turn_id . as_str ( ) )
2732+ . unwrap_or ( "-" ) ;
2733+ let parent_tool_call_id = subagent_parent_info
2734+ . as_ref ( )
2735+ . map ( |info| info. tool_call_id . as_str ( ) )
2736+ . unwrap_or ( "-" ) ;
27242737
27252738 let context_profile_policy = self . context_profile_policy_for_subagent (
27262739 & agent_type,
@@ -2909,6 +2922,17 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
29092922 let execution_engine = self . execution_engine . clone ( ) ;
29102923 let tool_pipeline = self . tool_pipeline . clone ( ) ;
29112924 let agent_type_for_execution = agent_type. clone ( ) ;
2925+ debug ! (
2926+ "Subagent execution task starting: agent_type={}, session_id={}, dialog_turn_id={}, parent_session_id={}, parent_dialog_turn_id={}, parent_tool_call_id={}, timeout_seconds={:?}, wait_ms={}" ,
2927+ agent_type,
2928+ session_id,
2929+ dialog_turn_id,
2930+ parent_session_id,
2931+ parent_dialog_turn_id,
2932+ parent_tool_call_id,
2933+ timeout_seconds,
2934+ wait_ms
2935+ ) ;
29122936 let mut execution_task = tokio:: spawn ( async move {
29132937 execution_engine
29142938 . execute_dialog_turn (
@@ -2974,6 +2998,23 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
29742998 }
29752999 } ;
29763000
3001+ let execution_outcome_label = match & execution_outcome {
3002+ SubagentExecutionOutcome :: Completed ( _) => "completed" ,
3003+ SubagentExecutionOutcome :: Cancelled => "cancelled" ,
3004+ SubagentExecutionOutcome :: TimedOut => "timed_out" ,
3005+ } ;
3006+ debug ! (
3007+ "Subagent execution outcome resolved: agent_type={}, session_id={}, dialog_turn_id={}, parent_session_id={}, parent_dialog_turn_id={}, parent_tool_call_id={}, outcome={}, duration_ms={}" ,
3008+ agent_type,
3009+ session_id,
3010+ dialog_turn_id,
3011+ parent_session_id,
3012+ parent_dialog_turn_id,
3013+ parent_tool_call_id,
3014+ execution_outcome_label,
3015+ subagent_started_at. elapsed( ) . as_millis( )
3016+ ) ;
3017+
29773018 let result = match execution_outcome {
29783019 SubagentExecutionOutcome :: Completed ( join_result) => match join_result {
29793020 Ok ( result) => result,
@@ -3203,21 +3244,69 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
32033244 } ;
32043245
32053246 // Clean up subagent session resources after successful execution
3206- debug ! ( "Starting subagent resource cleanup: session={}" , session_id) ;
3247+ debug ! (
3248+ "Subagent successful execution produced final text: agent_type={}, session_id={}, dialog_turn_id={}, parent_session_id={}, parent_dialog_turn_id={}, parent_tool_call_id={}, text_len={}, duration_ms={}" ,
3249+ agent_type,
3250+ session_id,
3251+ dialog_turn_id,
3252+ parent_session_id,
3253+ parent_dialog_turn_id,
3254+ parent_tool_call_id,
3255+ response_text. len( ) ,
3256+ subagent_started_at. elapsed( ) . as_millis( )
3257+ ) ;
3258+ let cleanup_started_at = Instant :: now ( ) ;
3259+ debug ! (
3260+ "Subagent cleanup starting after successful execution: agent_type={}, session_id={}, dialog_turn_id={}, parent_session_id={}, parent_dialog_turn_id={}, parent_tool_call_id={}" ,
3261+ agent_type,
3262+ session_id,
3263+ dialog_turn_id,
3264+ parent_session_id,
3265+ parent_dialog_turn_id,
3266+ parent_tool_call_id
3267+ ) ;
32073268 if let Err ( e) = self . cleanup_subagent_resources ( & session_id) . await {
32083269 warn ! (
32093270 "Failed to cleanup subagent resources: session={}, error={}" ,
32103271 session_id, e
32113272 ) ;
32123273 } else {
32133274 debug ! (
3214- "Subagent resource cleanup completed: session={}" ,
3215- session_id
3275+ "Subagent cleanup completed after successful execution: agent_type={}, session_id={}, dialog_turn_id={}, parent_session_id={}, parent_dialog_turn_id={}, parent_tool_call_id={}, cleanup_duration_ms={}" ,
3276+ agent_type,
3277+ session_id,
3278+ dialog_turn_id,
3279+ parent_session_id,
3280+ parent_dialog_turn_id,
3281+ parent_tool_call_id,
3282+ cleanup_started_at. elapsed( ) . as_millis( )
32163283 ) ;
32173284 }
3285+ debug ! (
3286+ "Subagent timeout registry removal starting: agent_type={}, session_id={}, dialog_turn_id={}" ,
3287+ agent_type, session_id, dialog_turn_id
3288+ ) ;
32183289 let mut registry = self . subagent_timeout_registry . write ( ) . await ;
32193290 registry. remove ( & session_id) ;
3291+ debug ! (
3292+ "Subagent timeout registry removal completed: agent_type={}, session_id={}, dialog_turn_id={}, total_duration_ms={}" ,
3293+ agent_type,
3294+ session_id,
3295+ dialog_turn_id,
3296+ subagent_started_at. elapsed( ) . as_millis( )
3297+ ) ;
32203298
3299+ debug ! (
3300+ "Subagent result returning to caller: agent_type={}, session_id={}, dialog_turn_id={}, parent_session_id={}, parent_dialog_turn_id={}, parent_tool_call_id={}, status=completed, text_len={}, total_duration_ms={}" ,
3301+ agent_type,
3302+ session_id,
3303+ dialog_turn_id,
3304+ parent_session_id,
3305+ parent_dialog_turn_id,
3306+ parent_tool_call_id,
3307+ response_text. len( ) ,
3308+ subagent_started_at. elapsed( ) . as_millis( )
3309+ ) ;
32213310 Ok ( SubagentResult :: completed ( response_text) )
32223311 }
32233312
@@ -3442,17 +3531,21 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
34423531 ///
34433532 /// Release resources occupied by subagent session (sandbox, etc.) and delete session
34443533 async fn cleanup_subagent_resources ( & self , session_id : & str ) -> BitFunResult < ( ) > {
3445- debug ! (
3446- "Starting subagent resource cleanup: session_id={}" ,
3447- session_id
3448- ) ;
3534+ let cleanup_started_at = Instant :: now ( ) ;
3535+ debug ! ( "Starting subagent resource cleanup: session_id={}" , session_id) ;
34493536
34503537 // Clean up snapshot system resources
34513538 if let Some ( workspace_path) = self
34523539 . session_manager
34533540 . get_session ( session_id)
34543541 . and_then ( |session| session. config . workspace_path . map ( std:: path:: PathBuf :: from) )
34553542 {
3543+ debug ! (
3544+ "Subagent cleanup stage starting: session_id={}, stage=snapshot_cleanup, workspace_path={}" ,
3545+ session_id,
3546+ workspace_path. display( )
3547+ ) ;
3548+ let stage_started_at = Instant :: now ( ) ;
34563549 if let Ok ( snapshot_manager) =
34573550 crate :: service:: snapshot:: ensure_snapshot_manager_for_workspace ( & workspace_path)
34583551 {
@@ -3470,6 +3563,11 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
34703563 ) ;
34713564 }
34723565 }
3566+ debug ! (
3567+ "Subagent cleanup stage completed: session_id={}, stage=snapshot_cleanup, duration_ms={}" ,
3568+ session_id,
3569+ stage_started_at. elapsed( ) . as_millis( )
3570+ ) ;
34733571 }
34743572
34753573 // Delete the subagent session itself, including runtime context and persisted turn data.
@@ -3479,6 +3577,12 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
34793577 . and_then ( |session| session. config . workspace_path . map ( std:: path:: PathBuf :: from) ) ;
34803578
34813579 if let Some ( workspace_path) = workspace_path {
3580+ debug ! (
3581+ "Subagent cleanup stage starting: session_id={}, stage=session_delete, workspace_path={}" ,
3582+ session_id,
3583+ workspace_path. display( )
3584+ ) ;
3585+ let stage_started_at = Instant :: now ( ) ;
34823586 if let Err ( e) = self
34833587 . session_manager
34843588 . delete_session ( & workspace_path, session_id)
@@ -3491,6 +3595,11 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
34913595 } else {
34923596 debug ! ( "Subagent session deleted: session={}" , session_id) ;
34933597 }
3598+ debug ! (
3599+ "Subagent cleanup stage completed: session_id={}, stage=session_delete, duration_ms={}" ,
3600+ session_id,
3601+ stage_started_at. elapsed( ) . as_millis( )
3602+ ) ;
34943603 } else {
34953604 warn ! (
34963605 "Failed to delete subagent session because workspace_path is missing: session={}" ,
@@ -3499,8 +3608,9 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
34993608 }
35003609
35013610 debug ! (
3502- "Subagent resource cleanup completed: session_id={}" ,
3503- session_id
3611+ "Subagent resource cleanup completed: session_id={}, duration_ms={}" ,
3612+ session_id,
3613+ cleanup_started_at. elapsed( ) . as_millis( )
35043614 ) ;
35053615 Ok ( ( ) )
35063616 }
0 commit comments