@@ -983,38 +983,39 @@ pub(crate) fn classify_runtime(
983983/// [`std::process::Child::try_wait`] (the repo's standard deadline pattern) and
984984/// killed if it does not exit in time.
985985///
986- /// Stdout is redirected to a temporary file rather than a pipe. A pipe's
987- /// `read_to_end` blocks until all file descriptors holding the write-end are
988- /// closed — including those inherited by forked descendants. A regular file does
989- /// not have this property: `read` returns EOF at the current write position
990- /// regardless of how many processes still have the file open. This makes the
991- /// post-exit read guaranteed to complete without blocking, and works identically
992- /// on Windows and Unix.
986+ /// Stdout is redirected to a temporary file rather than a pipe, so forked
987+ /// descendants cannot hold EOF open. Reads from a regular file return EOF at its
988+ /// current write position regardless of inherited file descriptors, cross-platform.
993989pub ( crate ) fn probe_codex_acp_major_version ( binary_path : & Path ) -> Option < u64 > {
990+ probe_codex_acp_major_version_with_path (
991+ binary_path,
992+ crate :: managed_agents:: readiness:: cli_probe:: augmented_path ( ) . as_deref ( ) ,
993+ )
994+ }
995+ pub ( crate ) fn probe_codex_acp_major_version_with_path (
996+ binary_path : & Path ,
997+ augmented_path : Option < & str > ,
998+ ) -> Option < u64 > {
994999 use std:: io:: { Read as _, Seek as _, SeekFrom } ;
9951000 use std:: time:: { Duration , Instant } ;
996-
997- /// Hard ceiling on how long the version probe may block discovery.
9981001 const VERSION_PROBE_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
9991002
1000- // Redirect stdout to a temporary file instead of a pipe. When the child
1001- // exits its write-end is closed; any forked descendant that inherited the
1002- // file descriptor can keep writing, but `read` on a regular file returns
1003- // EOF at the current file size — not blocking on a "writer present" check.
1004- // This is the only cross-platform way to bound the post-exit stdout read
1005- // without O_NONBLOCK (which is Unix-only) or a reader thread.
1003+ // A regular file returns EOF at its current size even when a descendant
1004+ // inherits its descriptor, bounding the post-exit read cross-platform.
10061005 let mut tmp = tempfile:: tempfile ( ) . ok ( ) ?;
10071006
1008- let mut child = Command :: new ( binary_path)
1009- . arg ( "--version" )
1007+ let mut command = Command :: new ( binary_path) ;
1008+ command. arg ( "--version" ) ;
1009+ if let Some ( path) = augmented_path {
1010+ command. env ( "PATH" , path) ;
1011+ }
1012+ let mut child = command
10101013 . stdout ( tmp. try_clone ( ) . ok ( ) ?)
10111014 . stderr ( std:: process:: Stdio :: null ( ) )
10121015 . spawn ( )
10131016 . ok ( ) ?;
10141017
1015- // Poll try_wait with a deadline — the repo's standard bounded-subprocess
1016- // pattern (see backend.rs). This returns as soon as the process exits
1017- // rather than blocking on stdout EOF.
1018+ // Poll until the deadline rather than blocking on stdout EOF.
10181019 let deadline = Instant :: now ( ) + VERSION_PROBE_TIMEOUT ;
10191020 let exit_status = loop {
10201021 match child. try_wait ( ) {
@@ -1039,9 +1040,7 @@ pub(crate) fn probe_codex_acp_major_version(binary_path: &Path) -> Option<u64> {
10391040 return None ;
10401041 }
10411042
1042- // Seek to the start and read at most 4 KiB. A regular file returns EOF
1043- // at the current write position even if a descendant still has the fd
1044- // open, so this read is guaranteed to complete without blocking.
1043+ // Read at most 4 KiB from the regular file without blocking.
10451044 tmp. seek ( SeekFrom :: Start ( 0 ) ) . ok ( ) ?;
10461045 let mut buf = Vec :: with_capacity ( 128 ) ;
10471046 let _ = ( & mut tmp as & mut dyn std:: io:: Read )
0 commit comments