mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Order unified exec lifecycle events reliably (#34713)
## What changed - Treat output-task closure as the signal that trailing output is complete, drain any remaining chunks before publishing command completion, and retain the grace period as a fallback. - Wait for deferred network-denial classification before emitting the final command result. - Serialize `write_stdin` interaction and completion events so an interaction that exits a process is published first, and avoid pruning processes while their terminal events are being finalized. ## Testing - Add coverage for late output, missing output-close signals, late network denials, interaction/completion ordering, cross-platform aggregated output, and pruning during finalization. GitOrigin-RevId: 46a118552bb1a4658b78aa5a5ca76eb8c5fba571
This commit is contained in:
1 parent
516f1e2aff
commit
9fc715c086
10 files changed
+445
-35
No files matched your search
@@ -65,6 +65,18 @@ pub(crate) struct OutputHandles {
|
||||
pub(crate) cancellation_token: CancellationToken,
|
||||
}
|
||||
|
||||
struct OutputTaskGuard {
|
||||
output_closed: Arc<AtomicBool>,
|
||||
output_closed_notify: Arc<Notify>,
|
||||
}
|
||||
|
||||
impl Drop for OutputTaskGuard {
|
||||
fn drop(&mut self) {
|
||||
self.output_closed.store(true, Ordering::Release);
|
||||
self.output_closed_notify.notify_waiters();
|
||||
}
|
||||
}
|
||||
|
||||
/// Transport-specific process handle used by unified exec.
|
||||
enum ProcessHandle {
|
||||
Local(Box<ExecCommandSession>),
|
||||
@@ -203,8 +215,6 @@ impl UnifiedExecProcess {
|
||||
}
|
||||
|
||||
fn finish_termination(&self) {
|
||||
self.output_closed.store(true, Ordering::Release);
|
||||
self.output_closed_notify.notify_waiters();
|
||||
self.cancellation_token.cancel();
|
||||
if let Some(output_task) = &self.output_task {
|
||||
output_task.abort();
|
||||
@@ -434,6 +444,10 @@ impl UnifiedExecProcess {
|
||||
let process = started.process;
|
||||
let mut events = process.subscribe_events();
|
||||
tokio::spawn(async move {
|
||||
let _output_task_guard = OutputTaskGuard {
|
||||
output_closed: Arc::clone(&output_closed),
|
||||
output_closed_notify: Arc::clone(&output_closed_notify),
|
||||
};
|
||||
let mut last_seq: u64 = 0;
|
||||
loop {
|
||||
let event = match events.recv().await {
|
||||
@@ -590,6 +604,10 @@ impl UnifiedExecProcess {
|
||||
output_tx: broadcast::Sender<Vec<u8>>,
|
||||
) -> JoinHandle<()> {
|
||||
tokio::spawn(async move {
|
||||
let _output_task_guard = OutputTaskGuard {
|
||||
output_closed: Arc::clone(&output_closed),
|
||||
output_closed_notify: Arc::clone(&output_closed_notify),
|
||||
};
|
||||
loop {
|
||||
match receiver.recv().await {
|
||||
Ok(chunk) => {
|
||||
|
||||
Reference in new issue
Block a user