fix(mcp-memory,nvim-core): eliminate lock contention in get_nvim_connection and resolve CPU bound loop in graph.rs

This commit is contained in:
Riz Ashraf committed 2026-10-11 18:21:58 +01:00
1 parent e91b53fdcc
commit 0afba74b4c
2 files changed
+8 -6

No files matched your search

+4 -3
View File
@@ -391,6 +391,8 @@ fn handle_nvim_notification(params: &[rmpv::Value]) {
} }
async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> { async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
let target_socket = read_active_socket_file().await.unwrap_or_default();
// Fast path: If NVIM_CONN is already active and healthy, check if active_nvim.txt matches // Fast path: If NVIM_CONN is already active and healthy, check if active_nvim.txt matches
// without spawning any external nvim.exe child process! // without spawning any external nvim.exe child process!
{ {
@@ -400,9 +402,8 @@ async fn get_nvim_connection() -> Result<mpsc::Sender<NvimRequest>, String> {
{ {
let active_lock = ACTIVE_SOCKET.lock().await; let active_lock = ACTIVE_SOCKET.lock().await;
if let Some(ref current_socket) = *active_lock if let Some(ref current_socket) = *active_lock
&& let Ok(target) = read_active_socket_file().await && !target_socket.is_empty()
&& !target.is_empty() && &target_socket == current_socket
&& &target == current_socket
{ {
return Ok(sender.clone()); return Ok(sender.clone());
} }
+4 -3
View File
@@ -632,7 +632,8 @@ impl McpTool for ReadGraphHandler {
let limit = req.limit; let limit = req.limit;
let offset = req.offset.unwrap_or(0); let offset = req.offset.unwrap_or(0);
let data = state.read_graph(|full| -> crate::error::Result<String> { tokio::task::spawn_blocking(move || {
state.read_graph(|full| -> crate::error::Result<String> {
let filtered_entities: Vec<(&String, &crate::models::Entity)> = full let filtered_entities: Vec<(&String, &crate::models::Entity)> = full
.entities .entities
.iter() .iter()
@@ -743,8 +744,8 @@ impl McpTool for ReadGraphHandler {
} }
Ok(result_json) Ok(result_json)
})?; })
Ok(data) }).await.map_err(|e| crate::error::AppError::Internal(format!("Graph read task panicked: {}", e)))?
} }
} }
pub struct SearchNodesHandler; pub struct SearchNodesHandler;