adding exit signal

This commit is contained in:
Ahmed Ibrahim
2025-07-20 17:41:17 -07:00
parent 7119f241d1
commit 90f9c6ee9b
3 changed files with 28 additions and 0 deletions

View File

@@ -805,6 +805,24 @@ async fn submission_loop(
}
});
}
Op::FlushRollout => {
// Best-effort flush: shutdown recorder and ack so caller can wait.
if let Some(sess_arc) = sess.as_ref() {
let rec_opt = { sess_arc.rollout.lock().unwrap().as_ref().cloned() };
if let Some(rec) = rec_opt {
if let Err(e) = rec.shutdown().await {
warn!("failed to flush rollout recorder: {e}");
}
}
}
let event = Event {
id: sub.id,
msg: EventMsg::BackgroundEvent(BackgroundEventEvent {
message: "rollout_flushed".to_string(),
}),
};
tx_event.send(event).await.ok();
}
}
}

View File

@@ -112,6 +112,9 @@ pub enum Op {
/// Request a single history entry identified by `log_id` + `offset`.
GetHistoryEntryRequest { offset: usize, log_id: u64 },
/// Flush and persist any pending rollout items (testing / graceful shutdown aid).
FlushRollout,
}
/// Determines the conditions under which the user is consulted to approve

View File

@@ -232,6 +232,13 @@ pub async fn run_main(cli: Cli, codex_linux_sandbox_exe: Option<PathBuf>) -> any
event_processor.process_event(event);
if is_last_event {
handle_last_message(last_assistant_message, last_message_file.as_deref())?;
// After task completes, flush rollout so external tests can observe all entries.
let flush_id = codex.submit(Op::FlushRollout).await?;
while let Some(event) = rx.recv().await {
if event.id == flush_id {
break;
}
}
break;
}
}