@@ -1075,6 +1075,8 @@ impl Clone for ToolManager {
10751075impl ToolManager {
10761076 /// Swapping agent involves the following:
10771077 /// - Dropping all of the clients first to avoid resource contention
1078+ /// - Clearing fields that are already referenced by background tasks. We can't simply spawn new
1079+ /// instances of these fields because one or more background tasks are already depending on it
10781080 /// - Building a new tool manager builder from the current tool manager
10791081 /// - Building a tool manager from said tool manager builder
10801082 /// - Calling load tools
@@ -1085,6 +1087,8 @@ impl ToolManager {
10851087 * agent_lock = agent. clone ( ) ;
10861088 drop ( agent_lock) ;
10871089
1090+ self . mcp_load_record . lock ( ) . await . clear ( ) ;
1091+
10881092 let builder = ToolManagerBuilder :: from ( & mut * self ) ;
10891093 let mut new_tool_manager = builder. build ( os, Box :: new ( std:: io:: sink ( ) ) , true ) . await ?;
10901094 std:: mem:: swap ( self , & mut new_tool_manager) ;
@@ -1644,32 +1648,15 @@ fn sanitize_name(orig: String, regex: ®ex::Regex, hasher: &mut impl Hasher) -
16441648fn is_process_running ( pid : u32 ) -> bool {
16451649 #[ cfg( unix) ]
16461650 {
1647- // On Unix systems, we can use kill with signal 0 to check if process exists
1648- std:: process:: Command :: new ( "ps" )
1649- . arg ( "-p" )
1650- . arg ( pid. to_string ( ) )
1651- . output ( )
1652- . map ( |output| output. status . success ( ) )
1653- . unwrap_or ( false )
1651+ let system = sysinfo:: System :: new_all ( ) ;
1652+ system. process ( sysinfo:: Pid :: from ( pid as usize ) ) . is_some ( )
16541653 }
16551654 #[ cfg( windows) ]
16561655 {
1657- // On Windows, try to open the process handle
1658- use std:: ptr;
1659-
1660- use winapi:: um:: handleapi:: CloseHandle ;
1661- use winapi:: um:: processthreadsapi:: OpenProcess ;
1662- use winapi:: um:: winnt:: PROCESS_QUERY_INFORMATION ;
1663-
1664- unsafe {
1665- let handle = OpenProcess ( PROCESS_QUERY_INFORMATION , 0 , pid) ;
1666- if handle != ptr:: null_mut ( ) {
1667- CloseHandle ( handle) ;
1668- true
1669- } else {
1670- false
1671- }
1672- }
1656+ // TODO: fill in the process health check for windows when when we officially support
1657+ // windows
1658+ _ = pid;
1659+ true
16731660 }
16741661}
16751662
0 commit comments