mind: inline compaction (not async), remove check_compaction

Compaction is CPU-only on in-memory data — no reason to spawn a
task. Inline it in run_commands as a synchronous agent lock + compact.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2026-04-05 03:43:53 -04:00
parent 2d6a17e773
commit 556a56035b

View file

@ -239,7 +239,13 @@ impl Mind {
for cmd in cmds {
match cmd {
MindCommand::None => {}
MindCommand::Compact => self.check_compaction(),
MindCommand::Compact => {
let threshold = compaction_threshold(&self.config.app);
let mut ag = self.agent.lock().await;
if ag.last_prompt_tokens() > threshold {
ag.compact();
}
}
MindCommand::Score => {
let mut s = self.shared.lock().unwrap();
if !s.scoring_in_flight {
@ -317,19 +323,6 @@ impl Mind {
});
}
fn check_compaction(&self) {
let threshold = compaction_threshold(&self.config.app);
let agent = self.agent.clone();
let shared = self.shared.clone();
shared.lock().unwrap().compaction_in_flight = true;
tokio::spawn(async move {
let mut ag = agent.lock().await;
if ag.last_prompt_tokens() > threshold {
ag.compact();
}
shared.lock().unwrap().compaction_in_flight = false;
});
}
pub async fn shutdown(&mut self) {