Skip to content

Commit 26d24bf

Browse files
branchseerclaude
andcommitted
feat(cache): detect stdin data and disable cache update
- Forward stdin from parent to child process concurrently with output draining - Track whether stdin had data during execution - Disable cache update when stdin had data (output may depend on input) - Add CacheNotUpdatedReason::StdinDataExists variant - Add e2e test for stdin passthrough functionality This ensures tasks that read from stdin don't get incorrectly cached, since their output may depend on the input data which we don't fingerprint. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent de0f2ca commit 26d24bf

File tree

5 files changed

+236
-83
lines changed

5 files changed

+236
-83
lines changed

crates/vite_task/src/session/cache/display.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,13 @@ pub fn format_cache_update_status(status: &CacheUpdateStatus) -> Option<String>
304304
CacheNotUpdatedReason::CacheHit => None,
305305
CacheNotUpdatedReason::CacheDisabled => None,
306306
CacheNotUpdatedReason::BuiltInCommand => None,
307-
// This needs to be shown - task failed so cache wasn't updated
307+
// These need to be shown - they explain why cache wasn't updated
308308
CacheNotUpdatedReason::NonZeroExitStatus => {
309309
Some("→ Cache not updated: task failed".to_string())
310310
}
311+
CacheNotUpdatedReason::StdinDataExists => {
312+
Some("→ Cache not updated: stdin had data".to_string())
313+
}
311314
},
312315
}
313316
}

crates/vite_task/src/session/event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub enum CacheNotUpdatedReason {
2929
NonZeroExitStatus,
3030
/// Built-in command doesn't support caching
3131
BuiltInCommand,
32+
/// Stdin had data - output may depend on input, unsafe to cache
33+
StdinDataExists,
3234
}
3335

3436
#[derive(Debug)]

crates/vite_task/src/session/execute/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,18 @@ impl ExecutionContext<'_> {
287287
};
288288

289289
// 5. Update cache if successful and determine cache update status
290+
// Priority: NonZeroExitStatus > StdinDataExists > Success
290291
let cache_update_status = if let Some((track_result, cache_metadata)) =
291292
track_result_with_cache_metadata
292293
{
293-
if result.exit_status.success() {
294-
// Execution succeeded, attempt cache update
294+
if !result.exit_status.success() {
295+
// Priority 1: Non-zero exit status - don't update cache
296+
CacheUpdateStatus::NotUpdated(CacheNotUpdatedReason::NonZeroExitStatus)
297+
} else if result.stdin_had_data {
298+
// Priority 2: Stdin had data - output may depend on input, unsafe to cache
299+
CacheUpdateStatus::NotUpdated(CacheNotUpdatedReason::StdinDataExists)
300+
} else {
301+
// Success: attempt cache update
295302
let fingerprint_ignores =
296303
cache_metadata.spawn_fingerprint.fingerprint_ignores().map(|v| v.as_slice());
297304
match PostRunFingerprint::create(
@@ -326,9 +333,6 @@ impl ExecutionContext<'_> {
326333
return Err(ExecutionAborted);
327334
}
328335
}
329-
} else {
330-
// Execution failed with non-zero exit status, don't update cache
331-
CacheUpdateStatus::NotUpdated(CacheNotUpdatedReason::NonZeroExitStatus)
332336
}
333337
} else {
334338
// Caching was disabled for this task

0 commit comments

Comments
 (0)