diff --git a/codex-rs/core/src/exec.rs b/codex-rs/core/src/exec.rs index 5793ccaacb..a8bbd0f52c 100644 --- a/codex-rs/core/src/exec.rs +++ b/codex-rs/core/src/exec.rs @@ -361,14 +361,13 @@ pub(crate) async fn consume_truncated_output( handle: &mut JoinHandle>>, timeout: Duration, ) -> std::io::Result> { - tokio::select! { - join_res = &mut *handle => { - match join_res { - Ok(io_res) => io_res, - Err(join_err) => Err(std::io::Error::other(join_err)), - } + match tokio::time::timeout(timeout, &mut *handle).await { + Ok(join_res) => match join_res { + Ok(io_res) => io_res, + Err(join_err) => Err(std::io::Error::other(join_err)), }, - _ = tokio::time::sleep(timeout) => { + Err(_elapsed) => { + // Timeout: abort the task to avoid hanging on open pipes. handle.abort(); Ok(Vec::new()) }