Make ESC button work when auto-compaction (#3857)
Only emit a task finished when the compaction comes from a `/compact`
This commit is contained in:
@@ -79,15 +79,29 @@ pub(super) async fn run_compact_task(
|
|||||||
input: Vec<InputItem>,
|
input: Vec<InputItem>,
|
||||||
compact_instructions: String,
|
compact_instructions: String,
|
||||||
) {
|
) {
|
||||||
|
let start_event = Event {
|
||||||
|
id: sub_id.clone(),
|
||||||
|
msg: EventMsg::TaskStarted(TaskStartedEvent {
|
||||||
|
model_context_window: turn_context.client.get_model_context_window(),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
sess.send_event(start_event).await;
|
||||||
run_compact_task_inner(
|
run_compact_task_inner(
|
||||||
sess,
|
sess.clone(),
|
||||||
turn_context,
|
turn_context,
|
||||||
sub_id,
|
sub_id.clone(),
|
||||||
input,
|
input,
|
||||||
compact_instructions,
|
compact_instructions,
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
let event = Event {
|
||||||
|
id: sub_id,
|
||||||
|
msg: EventMsg::TaskComplete(TaskCompleteEvent {
|
||||||
|
last_agent_message: None,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
sess.send_event(event).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_compact_task_inner(
|
async fn run_compact_task_inner(
|
||||||
@@ -98,15 +112,6 @@ async fn run_compact_task_inner(
|
|||||||
compact_instructions: String,
|
compact_instructions: String,
|
||||||
remove_task_on_completion: bool,
|
remove_task_on_completion: bool,
|
||||||
) {
|
) {
|
||||||
let model_context_window = turn_context.client.get_model_context_window();
|
|
||||||
let start_event = Event {
|
|
||||||
id: sub_id.clone(),
|
|
||||||
msg: EventMsg::TaskStarted(TaskStartedEvent {
|
|
||||||
model_context_window,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
sess.send_event(start_event).await;
|
|
||||||
|
|
||||||
let initial_input_for_turn: ResponseInputItem = ResponseInputItem::from(input);
|
let initial_input_for_turn: ResponseInputItem = ResponseInputItem::from(input);
|
||||||
let instructions_override = compact_instructions;
|
let instructions_override = compact_instructions;
|
||||||
let turn_input = sess.turn_input_with_history(vec![initial_input_for_turn.clone().into()]);
|
let turn_input = sess.turn_input_with_history(vec![initial_input_for_turn.clone().into()]);
|
||||||
@@ -195,13 +200,6 @@ async fn run_compact_task_inner(
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
sess.send_event(event).await;
|
sess.send_event(event).await;
|
||||||
let event = Event {
|
|
||||||
id: sub_id.clone(),
|
|
||||||
msg: EventMsg::TaskComplete(TaskCompleteEvent {
|
|
||||||
last_agent_message: None,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
sess.send_event(event).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn content_items_to_text(content: &[ContentItem]) -> Option<String> {
|
fn content_items_to_text(content: &[ContentItem]) -> Option<String> {
|
||||||
|
|||||||
@@ -861,8 +861,18 @@ async fn auto_compact_allows_multiple_attempts_when_interleaved_with_other_turn_
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let mut auto_compact_lifecycle_events = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
let event = codex.next_event().await.unwrap();
|
let event = codex.next_event().await.unwrap();
|
||||||
|
if event.id.starts_with("auto-compact-")
|
||||||
|
&& matches!(
|
||||||
|
event.msg,
|
||||||
|
EventMsg::TaskStarted(_) | EventMsg::TaskComplete(_)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
auto_compact_lifecycle_events.push(event);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if let EventMsg::TaskComplete(_) = &event.msg
|
if let EventMsg::TaskComplete(_) = &event.msg
|
||||||
&& !event.id.starts_with("auto-compact-")
|
&& !event.id.starts_with("auto-compact-")
|
||||||
{
|
{
|
||||||
@@ -870,6 +880,11 @@ async fn auto_compact_allows_multiple_attempts_when_interleaved_with_other_turn_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
auto_compact_lifecycle_events.is_empty(),
|
||||||
|
"auto compact should not emit task lifecycle events"
|
||||||
|
);
|
||||||
|
|
||||||
let request_bodies: Vec<String> = responder
|
let request_bodies: Vec<String> = responder
|
||||||
.recorded_requests()
|
.recorded_requests()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|||||||
Reference in New Issue
Block a user