Skip to content

Commit 3082ca5

Browse files
committed
fixes stale mcp load record
1 parent 6aa05b6 commit 3082ca5

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

crates/chat-cli/src/cli/chat/tool_manager.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,8 @@ impl Clone for ToolManager {
10751075
impl 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: &regex::Regex, hasher: &mut impl Hasher) -
16441648
fn 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

crates/chat-cli/src/mcp_client/messenger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub trait Messenger: std::fmt::Debug + Send + Sync + 'static {
3737
/// Signals to the orchestrator that a server has started initializing
3838
async fn send_init_msg(&self) -> Result<(), MessengerError>;
3939

40-
/// Singals to the orchestrator that a server has deinitialized
40+
/// Signals to the orchestrator that a server has deinitialized
4141
fn send_deinit_msg(&self);
4242

4343
/// Creates a duplicate of the messenger object

0 commit comments

Comments
 (0)