@@ -293,7 +293,7 @@ impl DaemonServiceApi for FileServiceHub {
293293 }
294294
295295 async fn health ( & self ) -> Result < DaemonHealth > {
296- let status = self . status ( ) . await ?;
296+ let mut status = self . status ( ) . await ?;
297297 let config_dir = runner_config_dir ( & self . project_root ) ;
298298 let runner_connected = is_agent_runner_ready ( & config_dir) . await ;
299299 let persisted_process_count = self . state . read ( ) . await . active_process_count ;
@@ -303,20 +303,37 @@ impl DaemonServiceApi for FileServiceHub {
303303 None => 0 ,
304304 } ;
305305 let lock = self . state . read ( ) . await ;
306+
307+ // Read pool_size from pm-config as fallback when core-state has stale/missing value
308+ let pm_config_path = crate :: daemon_project_config_path ( & self . project_root ) ;
309+ let daemon_dir = pm_config_path. parent ( ) . map ( |p| p. to_path_buf ( ) ) ;
310+ let pool_size = lock
311+ . daemon_pool_size
312+ . or_else ( || crate :: load_daemon_project_config ( & self . project_root ) . ok ( ) . and_then ( |c| c. pool_size ) ) ;
313+
314+ // If core-state says stopped but daemon process is alive, report as running
315+ let daemon_pid = daemon_dir. as_ref ( ) . and_then ( |dir| {
316+ std:: fs:: read_to_string ( dir. join ( "daemon.pid" ) ) . ok ( ) . and_then ( |s| s. trim ( ) . parse :: < u32 > ( ) . ok ( ) )
317+ } ) ;
318+ let process_alive = daemon_pid. map ( protocol:: is_process_alive) ;
319+ if matches ! ( status, DaemonStatus :: Stopped ) && process_alive == Some ( true ) {
320+ status = DaemonStatus :: Running ;
321+ }
322+
306323 let pool_utilization_percent =
307- lock . daemon_pool_size . map ( |ps| if ps == 0 { 0.0 } else { ( active_agents as f64 / ps as f64 ) * 100.0 } ) ;
324+ pool_size . map ( |ps| if ps == 0 { 0.0 } else { ( active_agents as f64 / ps as f64 ) * 100.0 } ) ;
308325 let queued_tasks = lock. tasks . values ( ) . filter ( |t| t. status == TaskStatus :: Ready ) . count ( ) as u32 ;
309326
310327 Ok ( DaemonHealth {
311- healthy : matches ! ( status, DaemonStatus :: Running | DaemonStatus :: Paused ) && runner_connected ,
328+ healthy : matches ! ( status, DaemonStatus :: Running | DaemonStatus :: Paused ) ,
312329 status,
313330 runner_connected,
314331 runner_pid : lock. runner_pid ,
315332 active_agents,
316- pool_size : lock . daemon_pool_size ,
333+ pool_size,
317334 project_root : Some ( self . project_root . display ( ) . to_string ( ) ) ,
318- daemon_pid : None ,
319- process_alive : None ,
335+ daemon_pid,
336+ process_alive,
320337 pool_utilization_percent,
321338 queued_tasks : Some ( queued_tasks) ,
322339 total_agents_spawned : None ,
0 commit comments