fix(acp): report failed manual compaction as an error (#13099)

Signed-off-by: John Tennant <jtennant@block.xyz>
Co-authored-by: Zack <04f47b290b155b3b8b782b11501cdb15f1e21e82dfceefd01ff0ed405459d927@buzz.block.builderlab.xyz>
This commit is contained in:
John Matthew Tennant
2026-10-29 15:05:47 +00:00
committed by GitHub
parent 775b3958c3
commit c85a58d7c7
3 changed files with 82 additions and 7 deletions
@@ -79,7 +79,7 @@ impl CompactionOperation {
fn command_error(
conversation: &Conversation,
message: String,
error: &anyhow::Error,
emit: &Emitter,
) -> Result<OperationResult<GooseEffect>> {
let command = messages_since_kickoff(conversation)?
@@ -91,9 +91,7 @@ impl CompactionOperation {
.clone()
.ok_or_else(|| anyhow!("Persisted slash command message has no id"))?;
let command = command.with_visibility(true, false);
let response = Message::assistant()
.with_text(message)
.with_visibility(true, false);
let response = compaction_failure_message(error).with_visibility(true, false);
emit.message(command);
let response = emit.message(response);
yielded_with([
@@ -164,7 +162,7 @@ impl Operation<Session, GooseEffect> for CompactionOperation {
Ok(result) => result,
Err(error) => {
span.record("error.type", "compaction_error");
return Self::command_error(conversation, error.to_string(), emit);
return Self::command_error(conversation, &error, emit);
}
};
let compacted = result.conversation;
@@ -4,7 +4,10 @@ use rmcp::model::{CallToolRequestParams, CallToolResult, ContentBlock};
use super::calculator_extension::{value, ADD};
use super::dummy_api::ProviderFeatures;
use super::pipeline::{self, test_pipeline, MessageKind::Agent};
use super::pipeline::{
self, test_pipeline,
MessageKind::{Agent, Error},
};
use crate::agents::state_machine;
use crate::agents::state_machine::ops_compaction::MAX_CONTEXT_ERROR_COMPACTIONS;
use crate::context_mgmt::{compute_tool_call_cutoff, TOOLCALL_SUMMARIZATION_BATCH_SIZE};
@@ -184,7 +187,7 @@ async fn a_failed_compact_command_reports_the_error_and_keeps_working() -> Resul
let failed = pipeline.run(["/compact"]).await?;
assert_eq!(failed.history_replacements(), 0);
failed.assert_message(-1, Agent, "summarizer offline");
failed.assert_message(-1, Error, "summarizer offline");
assert!(failed
.conversation()
.messages()
+74
View File
@@ -1448,3 +1448,77 @@ fn test_prompt_fails_and_streams_the_error() {
);
});
}
#[test]
fn test_manual_compaction_refusal_fails_without_replacing_context() {
run_test(async {
let expected_session_id = <AcpServerConnection as Connection>::expected_session_id();
let basic = include_str!("acp_test_data/openai_basic.txt");
let refusal =
r#"status:400 {"error":{"message":"summary refused","type":"invalid_request_error"}}"#;
let openai = OpenAiFixture::new(
vec![
(format!("what is 1+1{TURN_CONTEXT_OPEN}"), basic),
(SUMMARIZE_HISTORY.to_string(), refusal),
(SUMMARIZE_HISTORY.to_string(), refusal),
(SUMMARIZE_HISTORY.to_string(), refusal),
(SUMMARIZE_HISTORY.to_string(), refusal),
(format!("still there?{TURN_CONTEXT_OPEN}"), basic),
],
expected_session_id.clone(),
)
.await;
let mut conn =
<AcpServerConnection as Connection>::new(TestConnectionConfig::default(), openai).await;
let SessionData { mut session, .. } = conn.new_session().await.unwrap();
expected_session_id.set(&session.session_id().0);
session
.prompt("what is 1+1", PermissionDecision::Cancel)
.await
.unwrap();
let manager = SessionManager::new(conn.data_root());
let before = manager
.get_session(&session.session_id().0, true)
.await
.unwrap();
let result = session.prompt("/compact", PermissionDecision::Cancel).await;
let streamed: String = session
.session_updates()
.into_iter()
.filter_map(|update| match update {
SessionUpdate::AgentMessageChunk(chunk) => match chunk.content {
ContentBlock::Text(text) => Some(text.text),
_ => None,
},
_ => None,
})
.collect();
assert!(streamed.contains("summary refused"), "{streamed:?}");
assert!(!streamed.contains("Compaction complete"), "{streamed:?}");
let error = prompt_acp_error(result.unwrap_err());
assert_eq!(error.code, ErrorCode::InternalError);
assert_eq!(error.data.unwrap()["reason"], "turn_failed");
let after = manager
.get_session(&session.session_id().0, true)
.await
.unwrap();
assert_eq!(after.usage, before.usage);
for original in before.conversation.unwrap().messages() {
assert!(after
.conversation
.as_ref()
.unwrap()
.messages()
.contains(original));
}
assert_eq!(
session
.prompt("still there?", PermissionDecision::Cancel)
.await
.unwrap()
.text,
"2"
);
});
}