fix(mcp): propagate internal serialization errors instead of silently swallowing them to prevent LLM hallucination
This commit is contained in:
1 parent
f8925050db
commit
8f32a09399
13 files changed
+235
-63
No files matched your search
+21
-7
@@ -84,7 +84,6 @@ impl MemoryState {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn broadcast_activity(&self, message: &str) {
|
||||
let time = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
@@ -124,19 +123,28 @@ impl MemoryState {
|
||||
}
|
||||
|
||||
pub fn get_search_index(&self) -> MemoryIndex {
|
||||
self.search_index.read().unwrap_or_else(|e| e.into_inner()).clone()
|
||||
self.search_index
|
||||
.read()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.clone()
|
||||
}
|
||||
|
||||
pub async fn rebuild_index(self: &Arc<Self>) {
|
||||
let idx = self.search_index.read().unwrap().clone();
|
||||
idx.delete_all();
|
||||
|
||||
let entities: Vec<_> = self.graph.read_with(|g| g.entities.values().cloned().collect());
|
||||
let entities: Vec<_> = self
|
||||
.graph
|
||||
.read_with(|g| g.entities.values().cloned().collect());
|
||||
let tasks = self.tasks.read_with(|t| t.clone());
|
||||
let snippets = self.snippets.read_with(|s| s.clone());
|
||||
let adrs = self.adrs.read_with(|a| a.clone());
|
||||
|
||||
println!("rebuild_index: found {} entities, {} tasks", entities.len(), tasks.len());
|
||||
println!(
|
||||
"rebuild_index: found {} entities, {} tasks",
|
||||
entities.len(),
|
||||
tasks.len()
|
||||
);
|
||||
|
||||
let idx_clone = idx.clone();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
@@ -209,15 +217,21 @@ mod tests {
|
||||
let idx = arc_state.search_index.read().unwrap();
|
||||
// Force reload reader to ensure it sees the commit made by rebuild_index
|
||||
idx.reader.reload().unwrap();
|
||||
println!("Index reader doc count: {}", idx.reader.searcher().num_docs());
|
||||
|
||||
println!(
|
||||
"Index reader doc count: {}",
|
||||
idx.reader.searcher().num_docs()
|
||||
);
|
||||
|
||||
let all_docs = idx.search("Test", None).expect("Search failed");
|
||||
println!("All docs for 'Test': {:?}", all_docs);
|
||||
|
||||
// Verify the task added synchronously is actually searchable
|
||||
let results = idx.search("Test", None).expect("Search failed");
|
||||
assert_eq!(results.len(), 1, "Expected exactly 1 search result");
|
||||
assert_eq!(results[0].0, "123", "Expected the result to be the task we just added");
|
||||
assert_eq!(
|
||||
results[0].0, "123",
|
||||
"Expected the result to be the task we just added"
|
||||
);
|
||||
assert_eq!(results[0].1, "task", "Expected document type to be task");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user