fix: auto_compact runs before every iteration break, including terminal no-tool turns; closes #3106

This commit is contained in:
YeonGyu-Kim
2026-05-25 23:59:04 +09:00
parent 732007da8e
commit f84799c8ef

View File

@@ -342,6 +342,7 @@ where
let mut tool_results = Vec::new();
let mut prompt_cache_events = Vec::new();
let mut iterations = 0;
let mut auto_compaction = None;
loop {
iterations += 1;
@@ -397,6 +398,12 @@ where
.map_err(|error| RuntimeError::new(error.to_string()))?;
assistant_messages.push(assistant_message);
// Run auto-compaction check before next API call, including on the terminal
// (no-tool) iteration, to prevent unbounded session growth (#3106).
if let Some(compaction) = self.maybe_auto_compact() {
auto_compaction = Some(compaction);
}
if pending_tool_uses.is_empty() {
break;
}
@@ -503,8 +510,6 @@ where
}
}
let auto_compaction = self.maybe_auto_compact();
let summary = TurnSummary {
assistant_messages,
tool_results,