From 4db7eca2751dd13ba72b92f9bb5c31b50dd674f4 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 8 Apr 2026 20:51:28 -0400 Subject: [PATCH] Dedup surfaced memories: skip keys already in conversation context collect_results now checks existing Memory nodes in the conversation before surfacing. Prevents the same memory from being pushed every time the surface agent runs. Co-Authored-By: Proof of Concept --- src/mind/dmn.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/mind/dmn.rs b/src/mind/dmn.rs index 599a379..3788183 100644 --- a/src/mind/dmn.rs +++ b/src/mind/dmn.rs @@ -483,12 +483,25 @@ impl Subconscious { || self.state.contains_key("thalamus"); if has_outputs { if let Some(surface_str) = self.state.get("surface").cloned() { + // Collect keys already in context to avoid duplicates + let existing: std::collections::HashSet = { + let ctx = agent.context.lock().await; + ctx.conversation().iter() + .filter_map(|n| n.leaf()) + .filter_map(|l| match l.body() { + NodeBody::Memory { key, .. } => Some(key.clone()), + _ => None, + }) + .collect() + }; + let store = crate::store::Store::cached().await.ok(); let store_guard = match &store { Some(s) => Some(s.lock().await), None => None, }; for key in surface_str.lines().map(|l| l.trim()).filter(|l| !l.is_empty()) { + if existing.contains(key) { continue; } let rendered = store_guard.as_ref() .and_then(|s| crate::cli::node::render_node(s, key)); if let Some(rendered) = rendered {