@@ -233,10 +233,6 @@ impl ExecutionContext<'_> {
233233 false
234234 }
235235 LeafExecutionKind :: Spawn ( spawn_execution) => {
236- #[ expect(
237- clippy:: large_futures,
238- reason = "spawn execution with cache management creates large futures"
239- ) ]
240236 let outcome = execute_spawn (
241237 leaf_reporter,
242238 spawn_execution,
@@ -304,7 +300,7 @@ struct CacheState<'a> {
304300/// Post-execution summary of what fspy observed for a single task. Used in the
305301/// cache-update step. Fields are cfg-agnostic so the downstream match logic
306302/// doesn't need `cfg(fspy)` — the value is only ever `Some` when tracking
307- /// happened (see the `let tracking = ...` fork in `execute_spawn`).
303+ /// happened (see the `let fspy_outcome = ...` fork in `execute_spawn`).
308304struct TrackingOutcome {
309305 path_reads : HashMap < RelativePathBuf , PathRead > ,
310306 /// First path that was both read and written during execution, if any.
@@ -547,152 +543,177 @@ pub async fn execute_spawn(
547543 ExecutionMode :: Uncached { pipe_writers : None } => None ,
548544 } ;
549545
550- if let Some ( sinks) = sinks {
551- let stdout = child. stdout . take ( ) . expect ( "SpawnStdio::Piped yields a stdout pipe" ) ;
552- let stderr = child. stderr . take ( ) . expect ( "SpawnStdio::Piped yields a stderr pipe" ) ;
553- #[ expect(
554- clippy:: large_futures,
555- reason = "pipe_stdio streams child I/O and creates a large future"
556- ) ]
557- let pipe_result = pipe_stdio ( stdout, stderr, sinks, fast_fail_token. clone ( ) ) . await ;
558- if let Err ( err) = pipe_result {
559- // Cancel so `child.wait` kills the child instead of orphaning it.
560- fast_fail_token. cancel ( ) ;
561- let _ = child. wait . await ;
562- leaf_reporter. finish (
563- None ,
564- CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: CacheDisabled ) ,
565- Some ( ExecutionError :: Spawn ( err. into ( ) ) ) ,
566- ) ;
567- return SpawnOutcome :: Failed ;
546+ // 8. Drive pipe_stdio and child.wait inside one future with a single
547+ // error sink: a pipe failure cancels (so `child.wait` kills the child
548+ // instead of orphaning it) and surfaces through the same `wait_result`
549+ // match as a wait failure, so there is exactly one error exit.
550+ let child_fast_fail = fast_fail_token. clone ( ) ;
551+ let child_work = async move {
552+ let pipe_result: anyhow:: Result < ( ) > = if let Some ( sinks) = sinks {
553+ let stdout = child. stdout . take ( ) . expect ( "SpawnStdio::Piped yields a stdout pipe" ) ;
554+ let stderr = child. stderr . take ( ) . expect ( "SpawnStdio::Piped yields a stderr pipe" ) ;
555+ #[ expect(
556+ clippy:: large_futures,
557+ reason = "pipe_stdio streams child I/O and creates a large future"
558+ ) ]
559+ let r = pipe_stdio ( stdout, stderr, sinks, child_fast_fail. clone ( ) ) . await ;
560+ r. map_err ( anyhow:: Error :: from)
561+ } else {
562+ Ok ( ( ) )
563+ } ;
564+
565+ match pipe_result {
566+ Ok ( ( ) ) => child. wait . await . map_err ( anyhow:: Error :: from) ,
567+ Err ( err) => {
568+ // Pipe failed — cancel so `child.wait` kills the child
569+ // instead of orphaning it.
570+ child_fast_fail. cancel ( ) ;
571+ let _ = child. wait . await ;
572+ Err ( err)
573+ }
568574 }
569- }
575+ } ;
576+
577+ // Box::pin to keep the child-and-pipe stack off the enclosing future:
578+ // pipe_stdio alone makes the combined future large enough to trip
579+ // clippy::large_futures in every caller otherwise.
580+ let child_work = Box :: pin ( child_work) ;
581+ let wait_result = child_work. await ;
570582
571- // 8. Wait for exit (handles cancellation internally).
572- let outcome = match child. wait . await {
583+ let outcome = match wait_result {
573584 Ok ( outcome) => outcome,
574585 Err ( err) => {
575586 leaf_reporter. finish (
576587 None ,
577588 CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: CacheDisabled ) ,
578- Some ( ExecutionError :: Spawn ( err. into ( ) ) ) ,
589+ Some ( ExecutionError :: Spawn ( err) ) ,
579590 ) ;
580591 return SpawnOutcome :: Failed ;
581592 }
582593 } ;
583594 let duration = start. elapsed ( ) ;
584595
585596 // 9. Cache update (only when we were in `Cached` mode). Errors during cache
586- // update are reported but do not affect the exit status we return.
587- let ( cache_update_status, cache_error) = if let ExecutionMode :: Cached { state, .. } = mode {
588- let CacheState { metadata, globbed_inputs, std_outputs, fspy_negatives } = state;
589-
590- // Post-execution summary of what fspy observed. `Some` iff tracking was
591- // both requested (`fspy_negatives.is_some()`) and compiled in (`cfg(fspy)`).
592- // On a `cfg(not(fspy))` build this is always `None`, and the match below
593- // short-circuits to `FspyUnsupported` when tracking was needed.
594- let tracking: Option < TrackingOutcome > = {
595- #[ cfg( fspy) ]
596- {
597- outcome. path_accesses . as_ref ( ) . zip ( fspy_negatives. as_deref ( ) ) . map ( |( raw, negs) | {
598- let tracked = TrackedPathAccesses :: from_raw ( raw, workspace_root, negs) ;
599- let read_write_overlap = tracked
600- . path_reads
601- . keys ( )
602- . find ( |p| tracked. path_writes . contains ( * p) )
603- . cloned ( ) ;
604- TrackingOutcome { path_reads : tracked. path_reads , read_write_overlap }
605- } )
606- }
607- #[ cfg( not( fspy) ) ]
608- {
609- None
610- }
611- } ;
597+ // update are reported but do not affect the exit status we return. The
598+ // labeled block gives the section a single exit: every outcome `break`s
599+ // with a `(status, error)` pair and the one `finish()` below reports it.
600+ let ( cache_update_status, cache_error) = ' cache_update: {
601+ if let ExecutionMode :: Cached { state, .. } = mode {
602+ let CacheState { metadata, globbed_inputs, std_outputs, fspy_negatives } = state;
603+
604+ // Post-execution summary of what fspy observed. `Some` iff tracking
605+ // was both requested (`fspy_negatives.is_some()`) and compiled in
606+ // (`cfg(fspy)`). On a `cfg(not(fspy))` build this is always `None`,
607+ // and the match below short-circuits to `FspyUnsupported` when
608+ // tracking was needed.
609+ let fspy_outcome: Option < TrackingOutcome > = {
610+ #[ cfg( fspy) ]
611+ {
612+ outcome. path_accesses . as_ref ( ) . zip ( fspy_negatives. as_deref ( ) ) . map (
613+ |( raw, negs) | {
614+ let tracked = TrackedPathAccesses :: from_raw ( raw, workspace_root, negs) ;
615+ let read_write_overlap = tracked
616+ . path_reads
617+ . keys ( )
618+ . find ( |p| tracked. path_writes . contains ( * p) )
619+ . cloned ( ) ;
620+ TrackingOutcome { path_reads : tracked. path_reads , read_write_overlap }
621+ } ,
622+ )
623+ }
624+ #[ cfg( not( fspy) ) ]
625+ {
626+ None
627+ }
628+ } ;
612629
613- let cancelled = fast_fail_token. is_cancelled ( ) || interrupt_token. is_cancelled ( ) ;
614- if cancelled {
615- // Cancelled (Ctrl-C or sibling failure) — result is untrustworthy
616- ( CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: Cancelled ) , None )
617- } else if outcome. exit_status . success ( ) {
618- // fspy-inferred read-write overlap: the task wrote to a file it also
619- // read, so the prerun input hashes are stale and caching is unsound.
620- // (We only check fspy-inferred reads, not globbed_inputs. A task that
621- // writes to a glob-matched file without reading it produces perpetual
622- // cache misses but not a correctness bug.)
623- if let Some ( TrackingOutcome { read_write_overlap : Some ( path) , .. } ) = & tracking {
624- (
625- CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: InputModified {
626- path : path. clone ( ) ,
627- } ) ,
628- None ,
629- )
630- } else if tracking. is_none ( ) && fspy_negatives. is_some ( ) {
631- // Task requested fspy auto-inference but this binary was built
632- // without `cfg(fspy)`. Task ran, but we can't compute a valid
633- // cache entry without tracked path accesses.
634- ( CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: FspyUnsupported ) , None )
635- } else {
636- // Paths already in globbed_inputs are skipped: the overlap check
637- // above guarantees no input modification, so the prerun hash is
638- // the correct post-exec hash.
639- let empty_path_reads = HashMap :: default ( ) ;
640- let path_reads = tracking. as_ref ( ) . map_or ( & empty_path_reads, |t| & t. path_reads ) ;
641- match PostRunFingerprint :: create ( path_reads, workspace_root, & globbed_inputs) {
642- Ok ( post_run_fingerprint) => {
643- // Collect output files and create archive
644- let output_archive = match collect_and_archive_outputs (
645- metadata,
646- workspace_root,
647- cache_dir,
648- ) {
649- Ok ( archive) => archive,
650- Err ( err) => {
651- let result = (
630+ let cancelled = fast_fail_token. is_cancelled ( ) || interrupt_token. is_cancelled ( ) ;
631+ if cancelled {
632+ // Cancelled (Ctrl-C or sibling failure) — result is untrustworthy
633+ ( CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: Cancelled ) , None )
634+ } else if outcome. exit_status . success ( ) {
635+ // fspy-inferred read-write overlap: the task wrote to a file it
636+ // also read, so the prerun input hashes are stale and caching
637+ // is unsound. (We only check fspy-inferred reads, not
638+ // globbed_inputs. A task that writes to a glob-matched file
639+ // without reading it produces perpetual cache misses but not a
640+ // correctness bug.)
641+ if let Some ( TrackingOutcome { read_write_overlap : Some ( path) , .. } ) = & fspy_outcome
642+ {
643+ (
644+ CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: InputModified {
645+ path : path. clone ( ) ,
646+ } ) ,
647+ None ,
648+ )
649+ } else if fspy_outcome. is_none ( ) && fspy_negatives. is_some ( ) {
650+ // Task requested fspy auto-inference but this binary was built
651+ // without `cfg(fspy)`. Task ran, but we can't compute a valid
652+ // cache entry without tracked path accesses.
653+ ( CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: FspyUnsupported ) , None )
654+ } else {
655+ // Paths already in globbed_inputs are skipped: the overlap check
656+ // above guarantees no input modification, so the prerun hash is
657+ // the correct post-exec hash.
658+ let empty_path_reads = HashMap :: default ( ) ;
659+ let path_reads =
660+ fspy_outcome. as_ref ( ) . map_or ( & empty_path_reads, |o| & o. path_reads ) ;
661+ match PostRunFingerprint :: create ( path_reads, workspace_root, & globbed_inputs) {
662+ Ok ( post_run_fingerprint) => {
663+ // Collect output files and create archive.
664+ let output_archive = match collect_and_archive_outputs (
665+ metadata,
666+ workspace_root,
667+ cache_dir,
668+ ) {
669+ Ok ( archive) => archive,
670+ Err ( err) => {
671+ break ' cache_update (
672+ CacheUpdateStatus :: NotUpdated (
673+ CacheNotUpdatedReason :: CacheDisabled ,
674+ ) ,
675+ Some ( ExecutionError :: Cache {
676+ kind : CacheErrorKind :: Update ,
677+ source : err,
678+ } ) ,
679+ ) ;
680+ }
681+ } ;
682+
683+ let new_cache_value = CacheEntryValue {
684+ post_run_fingerprint,
685+ std_outputs : std_outputs. into ( ) ,
686+ duration,
687+ globbed_inputs,
688+ output_archive,
689+ } ;
690+ match cache. update ( metadata, new_cache_value, cache_dir) . await {
691+ Ok ( ( ) ) => ( CacheUpdateStatus :: Updated , None ) ,
692+ Err ( err) => (
652693 CacheUpdateStatus :: NotUpdated (
653694 CacheNotUpdatedReason :: CacheDisabled ,
654695 ) ,
655696 Some ( ExecutionError :: Cache {
656697 kind : CacheErrorKind :: Update ,
657698 source : err,
658699 } ) ,
659- ) ;
660- leaf_reporter. finish ( Some ( outcome. exit_status ) , result. 0 , result. 1 ) ;
661- return SpawnOutcome :: Spawned ( outcome. exit_status ) ;
700+ ) ,
662701 }
663- } ;
664-
665- let new_cache_value = CacheEntryValue {
666- post_run_fingerprint,
667- std_outputs : std_outputs. into ( ) ,
668- duration,
669- globbed_inputs,
670- output_archive,
671- } ;
672- match cache. update ( metadata, new_cache_value, cache_dir) . await {
673- Ok ( ( ) ) => ( CacheUpdateStatus :: Updated , None ) ,
674- Err ( err) => (
675- CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: CacheDisabled ) ,
676- Some ( ExecutionError :: Cache {
677- kind : CacheErrorKind :: Update ,
678- source : err,
679- } ) ,
680- ) ,
681702 }
703+ Err ( err) => (
704+ CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: CacheDisabled ) ,
705+ Some ( ExecutionError :: PostRunFingerprint ( err) ) ,
706+ ) ,
682707 }
683- Err ( err) => (
684- CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: CacheDisabled ) ,
685- Some ( ExecutionError :: PostRunFingerprint ( err) ) ,
686- ) ,
687708 }
709+ } else {
710+ // Execution failed with non-zero exit status — don't update cache
711+ ( CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: NonZeroExitStatus ) , None )
688712 }
689713 } else {
690- // Execution failed with non-zero exit status — don't update cache
691- ( CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: NonZeroExitStatus ) , None )
714+ // Caching was disabled for this task
715+ ( CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: CacheDisabled ) , None )
692716 }
693- } else {
694- // Caching was disabled for this task
695- ( CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: CacheDisabled ) , None )
696717 } ;
697718
698719 // 7. Finish the leaf execution with the result and optional cache error.
0 commit comments