Fix: don't overwrite journal during restore/compaction

The restore and compaction paths called build_context_window which
reads from the stale flat journal file, overwriting the journal we
loaded from the memory graph. Preserve the graph-loaded journal
across these operations.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-02 03:31:16 -04:00
parent b9e3568385
commit 87add36cdd

View file

@ -967,13 +967,15 @@ impl Agent {
fn do_compact(&mut self) {
let conversation: Vec<Message> = self.context.entries.iter()
.map(|e| e.api_message().clone()).collect();
let (messages, journal) = crate::agent::context::build_context_window(
let (messages, _) = crate::agent::context::build_context_window(
&self.context,
&conversation,
&self.client.model,
&self.tokenizer,
);
self.context.journal = journal::parse_journal_text(&journal);
// Don't overwrite journal — it was loaded from the memory graph
// in load_startup_journal. The old build_context_window reads
// from a stale flat file. TODO: remove build_context_window.
self.context.entries = messages.into_iter()
.map(ConversationEntry::Message).collect();
self.last_prompt_tokens = 0;
@ -1028,15 +1030,15 @@ impl Agent {
.collect();
dbglog!("[restore] {} messages after filtering system", conversation.len());
let (messages, journal) = crate::agent::context::build_context_window(
let (messages, _) = crate::agent::context::build_context_window(
&self.context,
&conversation,
&self.client.model,
&self.tokenizer,
);
dbglog!("[restore] journal text: {} chars, {} lines",
journal.len(), journal.lines().count());
self.context.journal = journal::parse_journal_text(&journal);
dbglog!("[restore] journal preserved: {} entries",
self.context.journal.len());
// Don't overwrite journal — already loaded from memory graph
self.context.entries = messages.into_iter()
.map(ConversationEntry::Message).collect();
dbglog!("[restore] built context window: {} entries", self.context.entries.len());