Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Make ESC button work when auto-compaction (#3857)

jif-oai4a5d6f7c7154
diff --git a/codex-rs/core/src/codex/compact.rs b/codex-rs/core/src/codex/compact.rs
index a465f937d4..0e20646423 100644
--- a/codex-rs/core/src/codex/compact.rs
+++ b/codex-rs/core/src/codex/compact.rs
@@ -79,15 +79,29 @@ pub(super) async fn run_compact_task(
input: Vec<InputItem>,
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(
- sess,
+ sess.clone(),
turn_context,
- sub_id,
+ sub_id.clone(),
input,
compact_instructions,
true,
)
.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(
@@ -98,15 +112,6 @@ async fn run_compact_task_inner(
compact_instructions: String,
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 instructions_override = compact_instructions;
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;
- 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> {
diff --git a/codex-rs/core/tests/suite/compact.rs b/codex-rs/core/tests/suite/compact.rs
index 361315f724..8db70f3559 100644
--- a/codex-rs/core/tests/suite/compact.rs
+++ b/codex-rs/core/tests/suite/compact.rs
@@ -861,8 +861,18 @@ async fn auto_compact_allows_multiple_attempts_when_interleaved_with_other_turn_
.await
.unwrap();
+ let mut auto_compact_lifecycle_events = Vec::new();
loop {
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
&& !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
.recorded_requests()
.into_iter()