@@ -18,8 +18,8 @@ use self::{
1818use super :: {
1919 cache:: { CommandCacheValue , ExecutionCache } ,
2020 event:: {
21- CacheDisabledReason , CacheStatus , ExecutionEvent , ExecutionEventKind , ExecutionId ,
22- ExecutionItemDisplay , OutputKind ,
21+ CacheDisabledReason , CacheNotUpdatedReason , CacheStatus , CacheUpdateStatus , ExecutionEvent ,
22+ ExecutionEventKind , ExecutionId , ExecutionItemDisplay , OutputKind ,
2323 } ,
2424 reporter:: { ExitStatus , Reporter } ,
2525} ;
@@ -153,10 +153,15 @@ impl ExecutionContext<'_> {
153153 } ,
154154 } ) ;
155155
156- // Emit Finish WITHOUT cache_status (already in Start event )
156+ // Emit Finish with CacheDisabled status (in-process executions don't cache )
157157 self . event_handler . handle_event ( ExecutionEvent {
158158 execution_id,
159- kind : ExecutionEventKind :: Finish { status : Some ( 0 ) } ,
159+ kind : ExecutionEventKind :: Finish {
160+ status : Some ( 0 ) ,
161+ cache_update_status : CacheUpdateStatus :: NotUpdated (
162+ CacheNotUpdatedReason :: CacheDisabled ,
163+ ) ,
164+ } ,
160165 } ) ;
161166 }
162167 LeafExecutionKind :: Spawn ( spawn_execution) => {
@@ -228,10 +233,15 @@ impl ExecutionContext<'_> {
228233 } ,
229234 } ) ;
230235 }
231- // Emit Finish without cache_status ( status already in Start event )
236+ // Emit Finish with CacheHit status (no cache update needed )
232237 self . event_handler . handle_event ( ExecutionEvent {
233238 execution_id,
234- kind : ExecutionEventKind :: Finish { status : Some ( 0 ) } ,
239+ kind : ExecutionEventKind :: Finish {
240+ status : Some ( 0 ) ,
241+ cache_update_status : CacheUpdateStatus :: NotUpdated (
242+ CacheNotUpdatedReason :: CacheHit ,
243+ ) ,
244+ } ,
235245 } ) ;
236246 return Ok ( ( ) ) ;
237247 }
@@ -276,51 +286,62 @@ impl ExecutionContext<'_> {
276286 }
277287 } ;
278288
279- // 5. Update cache if successful
280- // Only update cache if: (a) tracking was enabled, and (b) execution succeeded
281- if let Some ( ( track_result, cache_metadata) ) = track_result_with_cache_metadata
282- && result. exit_status . success ( )
289+ // 5. Update cache if successful and determine cache update status
290+ let cache_update_status = if let Some ( ( track_result, cache_metadata) ) =
291+ track_result_with_cache_metadata
283292 {
284- let fingerprint_ignores =
285- cache_metadata. spawn_fingerprint . fingerprint_ignores ( ) . map ( |v| v. as_slice ( ) ) ;
286- match PostRunFingerprint :: create (
287- & track_result. path_reads ,
288- & * self . cache_base_path ,
289- fingerprint_ignores,
290- ) {
291- Ok ( post_run_fingerprint) => {
292- let cache_value = CommandCacheValue {
293- post_run_fingerprint,
294- std_outputs : track_result. std_outputs . clone ( ) . into ( ) ,
295- duration : result. duration ,
296- } ;
297- if let Err ( err) = self . cache . update ( cache_metadata, cache_value) . await {
293+ if result. exit_status . success ( ) {
294+ // Execution succeeded, attempt cache update
295+ let fingerprint_ignores =
296+ cache_metadata. spawn_fingerprint . fingerprint_ignores ( ) . map ( |v| v. as_slice ( ) ) ;
297+ match PostRunFingerprint :: create (
298+ & track_result. path_reads ,
299+ & * self . cache_base_path ,
300+ fingerprint_ignores,
301+ ) {
302+ Ok ( post_run_fingerprint) => {
303+ let cache_value = CommandCacheValue {
304+ post_run_fingerprint,
305+ std_outputs : track_result. std_outputs . clone ( ) . into ( ) ,
306+ duration : result. duration ,
307+ } ;
308+ if let Err ( err) = self . cache . update ( cache_metadata, cache_value) . await {
309+ self . event_handler . handle_event ( ExecutionEvent {
310+ execution_id,
311+ kind : ExecutionEventKind :: Error {
312+ message : format ! ( "Failed to update cache: {err}" ) ,
313+ } ,
314+ } ) ;
315+ return Err ( ExecutionAborted ) ;
316+ }
317+ CacheUpdateStatus :: Updated
318+ }
319+ Err ( err) => {
298320 self . event_handler . handle_event ( ExecutionEvent {
299321 execution_id,
300322 kind : ExecutionEventKind :: Error {
301- message : format ! ( "Failed to update cache : {err}" ) ,
323+ message : format ! ( "Failed to create post-run fingerprint : {err}" ) ,
302324 } ,
303325 } ) ;
304326 return Err ( ExecutionAborted ) ;
305327 }
306328 }
307- Err ( err) => {
308- self . event_handler . handle_event ( ExecutionEvent {
309- execution_id,
310- kind : ExecutionEventKind :: Error {
311- message : format ! ( "Failed to create post-run fingerprint: {err}" ) ,
312- } ,
313- } ) ;
314- return Err ( ExecutionAborted ) ;
315- }
329+ } else {
330+ // Execution failed with non-zero exit status, don't update cache
331+ CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: NonZeroExitStatus )
316332 }
317- }
333+ } else {
334+ // Caching was disabled for this task
335+ CacheUpdateStatus :: NotUpdated ( CacheNotUpdatedReason :: CacheDisabled )
336+ } ;
318337
319- // 6. Emit finish WITHOUT cache_status
320- // Cache status was already emitted in Start event
338+ // 6. Emit finish with cache_update_status
321339 self . event_handler . handle_event ( ExecutionEvent {
322340 execution_id,
323- kind : ExecutionEventKind :: Finish { status : result. exit_status . code ( ) } ,
341+ kind : ExecutionEventKind :: Finish {
342+ status : result. exit_status . code ( ) ,
343+ cache_update_status,
344+ } ,
324345 } ) ;
325346
326347 Ok ( ( ) )
0 commit comments