diff --git a/src/agent/context.rs b/src/agent/context.rs index 89232a9..6bbb161 100644 --- a/src/agent/context.rs +++ b/src/agent/context.rs @@ -776,6 +776,11 @@ impl ContextState { self.section_mut(section).push(node); } + /// Push without logging — for restoring from an existing log. + pub fn push_no_log(&mut self, section: Section, node: AstNode) { + self.section_mut(section).push(node); + } + /// Replace the body of a leaf at `index` in `section`. /// Re-tokenizes to maintain the invariant. pub fn set_message(&mut self, section: Section, index: usize, body: NodeBody) { diff --git a/src/agent/mod.rs b/src/agent/mod.rs index 26b55de..ca11ffc 100644 --- a/src/agent/mod.rs +++ b/src/agent/mod.rs @@ -572,8 +572,9 @@ impl Agent { { let mut ctx = self.context.lock().await; ctx.clear(Section::Conversation); + // Push without logging — these are already in the log for node in nodes { - ctx.push(Section::Conversation, node); + ctx.push_no_log(Section::Conversation, node); } } self.compact().await; diff --git a/src/user/mod.rs b/src/user/mod.rs index 288e922..94a507e 100644 --- a/src/user/mod.rs +++ b/src/user/mod.rs @@ -377,20 +377,13 @@ async fn run( idle_state.decay_ewma(); app.update_idle(&idle_state); app.agent_state = mind.subconscious_snapshots().await; - { + if let Ok(mut unc) = mind.unconscious.try_lock() { let toggles: Vec = app.agent_toggles.drain(..).collect(); - if !toggles.is_empty() { - let mut sub = mind.subconscious.lock().await; - let mut unc = mind.unconscious.lock().await; - for name in &toggles { - if sub.toggle(name).is_none() { - unc.toggle(name).await; - } + for name in &toggles { + if mind.subconscious.lock().await.toggle(name).is_none() { + unc.toggle(name).await; } } - } - { - let unc = mind.unconscious.lock().await; app.unconscious_state = unc.snapshots(); app.graph_health = unc.graph_health.clone(); }