From f84799c8efe79064b8ba0a6fffc27c093d117bb3 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 25 May 2026 23:59:04 +0900 Subject: [PATCH] fix: auto_compact runs before every iteration break, including terminal no-tool turns; closes #3106 --- rust/crates/runtime/src/conversation.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rust/crates/runtime/src/conversation.rs b/rust/crates/runtime/src/conversation.rs index 35c0f73f..ea50e3bd 100644 --- a/rust/crates/runtime/src/conversation.rs +++ b/rust/crates/runtime/src/conversation.rs @@ -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,