From 98a1ae74d70e8a9e872f55d6800ea44b7c9dbfc4 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Mon, 6 Apr 2026 23:04:08 -0400 Subject: [PATCH] fix logging assistant messages --- src/agent/mod.rs | 16 ++++++++++++---- src/mind/log.rs | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/agent/mod.rs b/src/agent/mod.rs index 1ba2ad4..39e52b5 100644 --- a/src/agent/mod.rs +++ b/src/agent/mod.rs @@ -309,14 +309,22 @@ impl Agent { } /// Finalize the streaming entry with the complete response message. - /// Finds the unstamped assistant entry and updates it in place. + /// Finds the unstamped assistant entry, updates it in place, and logs it. fn finalize_streaming(&mut self, msg: Message) { if let Some(m) = self.streaming_entry() { - *m = msg; + *m = msg.clone(); m.stamp(); } else { - // No streaming entry found — push as new - self.push_message(msg); + // No streaming entry found — push as new (this logs via push_message) + self.push_message(msg.clone()); + } + + // Log the finalized entry + if let Some(ref log) = self.conversation_log { + let entry = ConversationEntry::Message(msg); + if let Err(e) = log.append(&entry) { + eprintln!("warning: failed to log finalized entry: {:#}", e); + } } self.changed.notify_one(); diff --git a/src/mind/log.rs b/src/mind/log.rs index 1de9593..e7b6e71 100644 --- a/src/mind/log.rs +++ b/src/mind/log.rs @@ -41,6 +41,8 @@ impl ConversationLog { .context("serializing entry for log")?; writeln!(file, "{}", line) .context("writing to conversation log")?; + file.sync_all() + .context("syncing conversation log")?; Ok(()) }