fix: do not present compaction countdowns to models (#12902)

Co-authored-by: JimCodey <fab731feb32f528977dec0f8e40b557d552d1c795ae5c8d75e7dc071c2b05aa0@meshllm.communities.buzz.xyz>
This commit is contained in:
Michael Neale
2026-10-15 01:05:48 +00:00
committed by GitHub
parent 01fa5dfe9e
commit 7f57d5693f
7 changed files with 20 additions and 60 deletions
+11 -17
View File
@@ -11,7 +11,6 @@ Each turn may include a `<{turn_context_tag}>` block added to the request.
This block is generated by goose and contains current operational context such as:
- current time
- working directory
- compaction status
- turn budget
- extension-provided context
@@ -41,7 +40,6 @@ pub async fn turn_context_message(
turns_taken: u32,
max_turns: u32,
turn_start: chrono::DateTime<chrono::Local>,
compaction_info: Option<String>,
) -> Option<Message> {
if SKIP.with(|f| f.get()) {
return None;
@@ -85,7 +83,6 @@ pub async fn turn_context_message(
.or_else(|| session.as_ref().map(|session| session.working_dir.clone()))
.unwrap_or_else(|| PathBuf::from("."));
let mut parts = lease.moim().await;
parts.extend(compaction_info.map(|value| tag("compaction", &value)));
parts.extend(turn_budget_part(turns_taken, max_turns));
turn_context_event(&working_dir, context_limit, parts, turn_start)
}
@@ -248,10 +245,9 @@ mod tests {
let (session_id, em, _tmp) = session_and_manager().await;
let lease = em.current_lease(&session_id).await.unwrap();
let message =
turn_context_message(&session_id, &em, &lease, 0, 100, chrono::Local::now(), None)
.await
.expect("turn context should be produced");
let message = turn_context_message(&session_id, &em, &lease, 0, 100, chrono::Local::now())
.await
.expect("turn context should be produced");
assert_eq!(message.role, rmcp::model::Role::User);
assert!(message.is_agent_visible());
@@ -268,10 +264,10 @@ mod tests {
let lease = em.current_lease(&session_id).await.unwrap();
let turn_start = chrono::Local::now();
let first = turn_context_message(&session_id, &em, &lease, 0, 100, turn_start, None)
let first = turn_context_message(&session_id, &em, &lease, 0, 100, turn_start)
.await
.unwrap();
let second = turn_context_message(&session_id, &em, &lease, 0, 100, turn_start, None)
let second = turn_context_message(&session_id, &em, &lease, 0, 100, turn_start)
.await
.unwrap();
@@ -301,10 +297,9 @@ mod tests {
)
.await;
let message =
turn_context_message(&session_id, &em, &lease, 0, 100, chrono::Local::now(), None)
.await
.unwrap();
let message = turn_context_message(&session_id, &em, &lease, 0, 100, chrono::Local::now())
.await
.unwrap();
let text = message.content[0].as_text().unwrap();
assert!(text.contains("old context"));
@@ -319,10 +314,9 @@ mod tests {
.resolve(&ExtensionSet::new(&session_id, Some(leased_working_dir), vec![]).unwrap())
.await;
let message =
turn_context_message(&session_id, &em, &lease, 0, 100, chrono::Local::now(), None)
.await
.unwrap();
let message = turn_context_message(&session_id, &em, &lease, 0, 100, chrono::Local::now())
.await
.unwrap();
let text = message.content[0].as_text().unwrap();
assert!(text.contains("<working-directory>/leased/dir</working-directory>"));
@@ -11,7 +11,6 @@ Each turn may include a `<turn-context>` block added to the request.
This block is generated by goose and contains current operational context such as:
- current time
- working directory
- compaction status
- turn budget
- extension-provided context
@@ -12,7 +12,6 @@ Each turn may include a `<turn-context>` block added to the request.
This block is generated by goose and contains current operational context such as:
- current time
- working directory
- compaction status
- turn budget
- extension-provided context
@@ -12,7 +12,6 @@ Each turn may include a `<turn-context>` block added to the request.
This block is generated by goose and contains current operational context such as:
- current time
- working directory
- compaction status
- turn budget
- extension-provided context
@@ -12,7 +12,6 @@ Each turn may include a `<turn-context>` block added to the request.
This block is generated by goose and contains current operational context such as:
- current time
- working directory
- compaction status
- turn budget
- extension-provided context
@@ -23,27 +23,6 @@ const COMPACTION_THINKING_TEXT: &str = "goose is compacting the conversation..."
pub(super) const MAX_CONTEXT_ERROR_COMPACTIONS: usize = 2;
fn compaction_part(
total_tokens: Option<i32>,
context_limit: usize,
threshold: f64,
) -> Option<String> {
let total_tokens = total_tokens?;
if total_tokens <= 0 || context_limit == 0 || threshold <= 0.0 || threshold >= 1.0 {
return None;
}
let compaction_at = (context_limit as f64 * threshold) as i32;
if compaction_at <= 0 || (total_tokens as f64 / compaction_at as f64) < 0.5 {
return None;
}
Some(format!(
"<compaction>~{}k tokens remaining</compaction>",
compaction_at.saturating_sub(total_tokens) / 1000
))
}
/// Reported usage stops at the inference that requested the tools, so the
/// results that answered it are not counted until the next request.
async fn unreported_tool_tokens(conversation: &Conversation) -> Result<i32> {
@@ -210,23 +189,6 @@ impl Operation<Session, GooseEffect> for CompactionOperation {
])
}
async fn moim_parts(
&self,
session: &Session,
conversation: &Conversation,
) -> Result<Vec<String>> {
if self.manages_own_context {
return Ok(Vec::new());
}
Ok(compaction_part(
Some(self.context_tokens(session, conversation).await?),
self.context_limit,
self.threshold,
)
.into_iter()
.collect())
}
async fn run(
&self,
session: &Session,
@@ -31,7 +31,15 @@ async fn proactive_and_manual_compaction_continue_with_replaced_usage() -> Resul
pipeline.run([half_full.as_str()]).await?;
let budget = pipeline.run(["check the budget"]).await?;
budget.assert_message(-1, Agent, "budget checked");
assert!(api.calls().last().unwrap().input_contains("<compaction>"));
assert!(!api.calls().last().unwrap().input_contains("<compaction>"));
pipeline
.set_total_tokens((pipeline.context_limit() as f64 * 0.79) as i32)
.await;
let near_threshold = pipeline.run(["check the budget"]).await?;
near_threshold.assert_message(-1, Agent, "budget checked");
assert_eq!(near_threshold.history_replacements(), 0);
assert!(!api.calls().last().unwrap().input_contains("<compaction>"));
let filled_usage = (pipeline.context_limit() as f64 * 0.81) as i32;
pipeline.set_total_tokens(filled_usage).await;