@@ -1197,6 +1197,80 @@ async fn test_execute_plan_delegates_parallel_task_wave_once() {
11971197 . all( |task| task. status == TaskStatus :: Completed ) ) ;
11981198}
11991199
1200+ #[ tokio:: test]
1201+ async fn test_execute_plan_auto_delegates_unmarked_parallel_wave_when_enabled ( ) {
1202+ use crate :: planning:: { Complexity , ExecutionPlan , Task } ;
1203+ use crate :: subagent:: AgentRegistry ;
1204+ use crate :: tools:: register_task;
1205+
1206+ let child_client = Arc :: new ( MockLlmClient :: new ( vec ! [
1207+ MockLlmClient :: text_response( "auth exploration complete" ) ,
1208+ MockLlmClient :: text_response( "docs exploration complete" ) ,
1209+ ] ) ) ;
1210+ let tool_executor = Arc :: new ( ToolExecutor :: new ( "/tmp" . to_string ( ) ) ) ;
1211+ let agent_registry = Arc :: new ( AgentRegistry :: new ( ) ) ;
1212+ register_task (
1213+ tool_executor. registry ( ) ,
1214+ child_client,
1215+ Arc :: clone ( & agent_registry) ,
1216+ "/tmp" . to_string ( ) ,
1217+ ) ;
1218+ let auto_delegation = crate :: config:: AutoDelegationConfig {
1219+ enabled : true ,
1220+ auto_parallel : true ,
1221+ ..Default :: default ( )
1222+ } ;
1223+ let config = AgentConfig {
1224+ auto_delegation,
1225+ agent_registry : Some ( agent_registry) ,
1226+ ..AgentConfig :: default ( )
1227+ } ;
1228+ let agent = AgentLoop :: new (
1229+ Arc :: new ( MockLlmClient :: new ( vec ! [ ] ) ) ,
1230+ tool_executor,
1231+ test_tool_context ( ) ,
1232+ config,
1233+ ) ;
1234+
1235+ let mut plan = ExecutionPlan :: new ( "Explore independent areas" , Complexity :: Medium ) ;
1236+ plan. add_step ( Task :: new ( "s1" , "Find auth code" ) ) ;
1237+ plan. add_step ( Task :: new ( "s2" , "Find documentation" ) ) ;
1238+
1239+ let ( tx, mut rx) = mpsc:: channel ( 100 ) ;
1240+ let result = agent
1241+ . execute_plan ( & [ ] , & plan, Some ( "auto-plan-parallel-session" ) , Some ( tx) )
1242+ . await
1243+ . unwrap ( ) ;
1244+
1245+ assert_eq ! (
1246+ result. tool_calls_count, 1 ,
1247+ "auto-parallel plan wave should collapse into one parallel_task call"
1248+ ) ;
1249+ assert ! ( result. text. contains( "auth exploration complete" ) ) ;
1250+ assert ! ( result. text. contains( "docs exploration complete" ) ) ;
1251+
1252+ let mut parallel_task_starts = 0 ;
1253+ let mut completed_steps = Vec :: new ( ) ;
1254+ rx. close ( ) ;
1255+ while let Some ( event) = rx. recv ( ) . await {
1256+ match event {
1257+ AgentEvent :: ToolStart { name, .. } if name == "parallel_task" => {
1258+ parallel_task_starts += 1 ;
1259+ }
1260+ AgentEvent :: StepEnd {
1261+ step_id,
1262+ status : TaskStatus :: Completed ,
1263+ ..
1264+ } => completed_steps. push ( step_id) ,
1265+ _ => { }
1266+ }
1267+ }
1268+
1269+ completed_steps. sort ( ) ;
1270+ assert_eq ! ( parallel_task_starts, 1 ) ;
1271+ assert_eq ! ( completed_steps, vec![ "s1" . to_string( ) , "s2" . to_string( ) ] ) ;
1272+ }
1273+
12001274#[ tokio:: test]
12011275async fn test_execute_plan_delegated_parallel_wave_maps_child_failure ( ) {
12021276 use crate :: planning:: { Complexity , ExecutionPlan , Task } ;
@@ -1301,9 +1375,11 @@ async fn test_auto_delegation_runs_parallel_specialists_when_enabled() {
13011375 agent_registry. clone ( ) ,
13021376 "/tmp" . to_string ( ) ,
13031377 ) ;
1304- let mut auto_delegation = crate :: config:: AutoDelegationConfig :: default ( ) ;
1305- auto_delegation. enabled = true ;
1306- auto_delegation. max_tasks = 2 ;
1378+ let auto_delegation = crate :: config:: AutoDelegationConfig {
1379+ enabled : true ,
1380+ max_tasks : 2 ,
1381+ ..Default :: default ( )
1382+ } ;
13071383 let config = AgentConfig {
13081384 planning_mode : PlanningMode :: Disabled ,
13091385 auto_delegation,
@@ -1357,10 +1433,12 @@ async fn test_auto_delegation_global_parallel_switch_uses_single_task() {
13571433 agent_registry. clone ( ) ,
13581434 "/tmp" . to_string ( ) ,
13591435 ) ;
1360- let mut auto_delegation = crate :: config:: AutoDelegationConfig :: default ( ) ;
1361- auto_delegation. enabled = true ;
1362- auto_delegation. auto_parallel = false ;
1363- auto_delegation. max_tasks = 2 ;
1436+ let auto_delegation = crate :: config:: AutoDelegationConfig {
1437+ enabled : true ,
1438+ auto_parallel : false ,
1439+ max_tasks : 2 ,
1440+ ..Default :: default ( )
1441+ } ;
13641442 let config = AgentConfig {
13651443 planning_mode : PlanningMode :: Disabled ,
13661444 auto_delegation,
0 commit comments