Skip to content

Commit 837da53

Browse files
committed
fix(cache): keep ignored outputs with tracked reads required
A path reported through ignoreOutput remains a required input when the task reads and writes it and the read survives input filtering. Cache schema v25 starts a fresh cache because v24 entries can replay stale outputs when one of these inputs is missing.
1 parent 2bd878a commit 837da53

18 files changed

Lines changed: 474 additions & 70 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Changelog
22

3+
- **Fixed** Deleting a file that a task reads, rewrites, and reports with `ignoreOutput` now makes `vp run` miss the cache when the read is still tracked, so the task recomputes its outputs ([#PR](https://github.com/voidzero-dev/vite-task/pull/PR)).
34
- **Fixed** Remote cache operations now cap concurrent uploads to 4 per endpoint, use pooled HTTP/1.1 connections instead of multiplexing all reads and uploads over one HTTP/2 connection, retry transient `5xx`/`429`/`408` and network failures with jittered backoff, and back off briefly during sustained endpoint outages, preventing `503` upload bursts and Windows connection-reset drops ([#1016](https://github.com/voidzero-dev/vite-task/pull/1016)).
45
- **Fixed** Tasks that list `node_modules`, the workspace root, or `node_modules/.vite` no longer miss the cache when pnpm's `node_modules/.pnpm-workspace-state-*.json`, Vite's `node_modules/.vite-temp`, the workspace root's `.git`, or the task cache directory appear or disappear. Direct accesses to `node_modules/.vite-temp` and `.DS_Store` are now skipped as well, so they are neither tracked as inputs nor archived as outputs ([#1014](https://github.com/voidzero-dev/vite-task/pull/1014)).
56
- **Fixed** When a command handler sets a working directory for a command it generates, `vp run` now runs that command in the selected directory and includes the directory in its cache fingerprint ([#1005](https://github.com/voidzero-dev/vite-task/pull/1005)).

‎crates/vt/src/session/cache/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ pub fn split_path(path: &str) -> (Option<&str>, &str) {
470470
/// its own cache warm across branch switches, and a cache from a different
471471
/// version is simply ignored (it lives in a directory this build never looks
472472
/// at) rather than aborting the run. Bumping the version starts a fresh cache.
473-
const CACHE_SCHEMA_VERSION: u32 = 24;
473+
const CACHE_SCHEMA_VERSION: u32 = 25;
474474

475475
/// Name of the per-version subdirectory (e.g. `v14`) under the task-cache
476476
/// directory that holds the database and output archives for the current

‎crates/vt/src/session/execute/cache_update.rs‎

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ struct TrackingOutcome {
4343
/// archived as folders: all of them when `output_config.includes_auto`,
4444
/// otherwise those a positive output glob matches.
4545
empty_folders: FxHashSet<RelativePathBuf>,
46-
/// What the task can rebuild, from every write, rename target and mkdir
47-
/// fspy recorded before output exclusions and `ignoreOutput` paths are
48-
/// applied, with the files under a renamed folder in place of the folder.
4946
rebuildable: Rebuildable,
5047
}
5148

@@ -201,9 +198,9 @@ pub(super) async fn update_cache(
201198
///
202199
/// `path_reads` is gated on `input_config.includes_auto`, filtered by
203200
/// user-configured input negatives, and by tool-reported `ignoreInput` paths.
204-
/// `rebuildable` takes every write, rename target and mkdir unfiltered, since
205-
/// what the task can rebuild doesn't depend on what is archived, and expands
206-
/// renamed folders into the files under them. `path_writes` and
201+
/// `rebuildable` uses writes and mkdirs, including files under renamed
202+
/// folders as writes. A write covered by `ignoreOutput` is left out of
203+
/// `rebuildable` if it is still in `path_reads`. `path_writes` and
207204
/// `empty_folders` are its written files and empty folders filtered by
208205
/// user-configured output negatives and tool-reported `ignoreOutput` paths,
209206
/// which decide what is archived; `path_writes` is gated on
@@ -224,17 +221,10 @@ fn observe_fspy(
224221
) -> Option<TrackingOutcome> {
225222
#[cfg(fspy)]
226223
{
227-
use super::tracked_accesses::TrackedPathAccesses;
224+
use super::{rebuildable::files_written, tracked_accesses::TrackedPathAccesses};
228225

229226
path_accesses.map(|raw| {
230227
let tracked = TrackedPathAccesses::from_raw(raw, workspace_root, cache_root);
231-
let mut rebuildable = Rebuildable::new(
232-
tracked.path_writes,
233-
tracked.rename_targets,
234-
tracked.mkdirs,
235-
workspace_root,
236-
cache_root,
237-
);
238228
let filtered_path_reads: HashMap<RelativePathBuf, PathRead> =
239229
// fspy can be attached for auto-output-only tasks. In that
240230
// mode reads must not become inferred inputs.
@@ -253,6 +243,27 @@ fn observe_fspy(
253243
} else {
254244
HashMap::default()
255245
};
246+
let mut written = files_written(
247+
tracked.path_writes,
248+
tracked.rename_targets,
249+
workspace_root,
250+
cache_root,
251+
);
252+
let mut mkdirs = tracked.mkdirs;
253+
let required_writes = if ignored_output_rels.is_empty() {
254+
FxHashSet::default()
255+
} else {
256+
written
257+
.extract_if(|path| {
258+
filtered_path_reads.contains_key(path)
259+
&& is_ignored(path, ignored_output_rels)
260+
})
261+
.collect()
262+
};
263+
for path in &required_writes {
264+
mkdirs.remove(path);
265+
}
266+
let rebuildable = Rebuildable::from_written(written, mkdirs);
256267
let filter_outputs = |paths: &FxHashSet<RelativePathBuf>| {
257268
let Some(fspy) = fspy else {
258269
return FxHashSet::default();
@@ -269,10 +280,10 @@ fn observe_fspy(
269280
// Only fingerprints of the paths the task read ask about folders;
270281
// without them, the archive still takes the empty folders the
271282
// task made.
272-
rebuildable = if filtered_path_reads.is_empty() {
283+
let rebuildable = if filtered_path_reads.is_empty() {
273284
rebuildable.with_empty_folders(workspace_root, cache_root)
274285
} else {
275-
rebuildable.with_folders(workspace_root, cache_root)
286+
rebuildable.with_folders_excluding(workspace_root, cache_root, &required_writes)
276287
};
277288
TrackingOutcome {
278289
path_reads: filtered_path_reads,

‎crates/vt/src/session/execute/rebuildable.rs‎

Lines changed: 75 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
//! What a task can rebuild, so a later run may find it missing.
22
//!
3-
//! Inputs are fingerprinted as the task left them, so they include the files
4-
//! a task read and then wrote, such as a tool's cache file. A clean checkout
5-
//! (CI, a fresh clone) doesn't have those files yet, and running the task
6-
//! would write them again, so a later run may find them missing. A file that
7-
//! is there must still be as the task left it.
3+
//! Inputs are fingerprinted as the task left them, including files it read
4+
//! and then wrote. A rebuildable file may be missing on a later run, as on
5+
//! a clean checkout. A file that is there must still match the fingerprint.
86
//!
9-
//! The same goes for an empty folder the task made (built-in ignored paths
10-
//! such as `.DS_Store` aside), and for a folder that holds only what the task
11-
//! can rebuild: every file (or symlink) in it is one the task wrote, and every
12-
//! folder in it is rebuildable too. None of these is fingerprinted at all. A hit
13-
//! restores the files and the empty folders, which are archived as folders, if
14-
//! they're among the task's outputs, and the files recreate the folders holding
15-
//! them; explicit output config can leave them out. Such folders are found after
16-
//! the run by climbing from the written paths and the empty folders through
17-
//! their parent folders inside the workspace, listing each one once in the real
18-
//! file system. A written path or folder that is gone by then plays no part. A
19-
//! listing of any other folder leaves out its entries that the task can rebuild,
20-
//! which a later run may find missing too.
7+
//! A folder is rebuildable when the task made it and it is empty, or when it
8+
//! contains at least one entry and all entries are rebuildable. Both checks
9+
//! skip built-in ignored entries such as `.DS_Store`. None of these is
10+
//! fingerprinted at all. A hit restores the files and the empty folders, which
11+
//! are archived as folders, if they're among the task's outputs, and the files
12+
//! recreate the folders holding them; explicit output config can leave them
13+
//! out. Such folders are found after the run by climbing from the written
14+
//! paths and the empty folders through their parent folders inside the
15+
//! workspace, listing each one once in the real file system. A written path or
16+
//! folder that is gone by then plays no part. A listing of any other folder
17+
//! leaves out its entries that the task can rebuild, which a later run may
18+
//! find missing too.
2119
//!
22-
//! The written paths are fspy's records before output exclusions and
23-
//! tool-reported `ignoreOutput` paths are applied: those decide what is
24-
//! archived, not what the task can rebuild. A rename target that is a folder
25-
//! after the run, like Vite's `deps` folder renamed into place, stands for
26-
//! writes of every file (and symlink) under it; the folder itself and the
27-
//! folders in it don't count as written. The archive takes those files like
28-
//! any written file. The rename's source, like Vite's `deps_temp_*` folder,
29-
//! isn't recorded, but a path that is gone after the run and that the task
30-
//! wrote in counts as written: the task made or removed it. It is
31-
//! fingerprinted as missing, which a later run must match either way, so this
20+
//! The written paths come from fspy. A file the task reads and writes is a
21+
//! required input when `ignoreOutput` covers it and the read survives input
22+
//! filtering. Its absence makes the next run miss. Output negative globs
23+
//! only decide what is archived.
24+
//!
25+
//! A rename target that is a folder after the run, like Vite's `deps` folder
26+
//! renamed into place, stands for writes of every file (and symlink) under
27+
//! it. The folder itself and the folders in it don't count as written.
28+
//! The archive takes those files like any written file. The rename's source,
29+
//! like Vite's `deps_temp_*` folder, isn't recorded. A path that is gone after
30+
//! the run counts as written if the task wrote in it. It is fingerprinted
31+
//! as missing, which a later run must match either way, so this
3232
//! only tells it apart from a path the task looked for and didn't find. A
3333
//! write record on a path that is a folder, from opening it with write
3434
//! access, is ignored. A mkdir record counts only for a folder that is empty
@@ -45,12 +45,12 @@ use vt_path::{AbsolutePath, RelativePath, RelativePathBuf};
4545

4646
use super::{fingerprint::PathFingerprint, ignored_paths::IgnoredDirEntries};
4747

48-
/// The paths a task wrote, the empty folders it made, and the folders
49-
/// holding only what it can rebuild, relative to the workspace root.
48+
/// The rebuildable paths a task wrote, the empty folders it made, and the
49+
/// folders holding only what it can rebuild, relative to the workspace root.
5050
#[derive(Debug, Default)]
5151
pub struct Rebuildable {
5252
written: FxHashSet<RelativePathBuf>,
53-
/// The folders the task made, or tried to make, inside the workspace.
53+
/// The folders the task made or tried to make, excluding required paths.
5454
mkdirs: FxHashSet<RelativePathBuf>,
5555
/// The `mkdirs` that are empty folders.
5656
empty_folders: FxHashSet<RelativePathBuf>,
@@ -61,19 +61,13 @@ pub struct Rebuildable {
6161
}
6262

6363
impl Rebuildable {
64-
/// Takes the `written` paths and the `rename_targets` as written, with the
65-
/// files under a renamed folder in place of the folder, by looking under
66-
/// `workspace_root`, which must be done after the run, and the `mkdirs`.
64+
/// Takes the rebuildable `written` paths and `mkdirs`.
6765
/// No folder is rebuildable, and none of the `mkdirs` is an empty folder,
68-
/// until [`Self::with_folders`] or [`Self::with_empty_folders`] finds them.
69-
pub fn new(
66+
/// until [`Self::with_folders_excluding`] or [`Self::with_empty_folders`] finds them.
67+
pub(super) fn from_written(
7068
written: FxHashSet<RelativePathBuf>,
71-
rename_targets: FxHashSet<RelativePathBuf>,
7269
mkdirs: FxHashSet<RelativePathBuf>,
73-
workspace_root: &AbsolutePath,
74-
cache_root: Option<&RelativePath>,
7570
) -> Self {
76-
let written = files_written(written, rename_targets, workspace_root, cache_root);
7771
let mut written_in = FxHashSet::default();
7872
for path in &written {
7973
let mut dir = path.parent();
@@ -101,13 +95,14 @@ impl Rebuildable {
10195
/// Only fingerprints of the paths the task read ask about folders, so a
10296
/// run without such reads takes [`Self::with_empty_folders`] instead.
10397
#[must_use]
104-
pub fn with_folders(
98+
pub(super) fn with_folders_excluding(
10599
mut self,
106100
workspace_root: &AbsolutePath,
107101
cache_root: Option<&RelativePath>,
102+
required_writes: &FxHashSet<RelativePathBuf>,
108103
) -> Self {
109104
(self.folders, self.empty_folders) =
110-
find_folders(&self.written, &self.mkdirs, workspace_root, cache_root);
105+
find_folders(&self.written, required_writes, &self.mkdirs, workspace_root, cache_root);
111106
self
112107
}
113108

@@ -129,8 +124,8 @@ impl Rebuildable {
129124
self
130125
}
131126

132-
/// The paths the task wrote or renamed a file to, and the files under the
133-
/// folders it renamed.
127+
/// The rebuildable paths the task wrote or renamed a file to, and the
128+
/// rebuildable files under the folders it renamed.
134129
pub const fn written(&self) -> &FxHashSet<RelativePathBuf> {
135130
&self.written
136131
}
@@ -141,12 +136,12 @@ impl Rebuildable {
141136
&self.empty_folders
142137
}
143138

144-
/// Whether a later run may find `path`, which a read found as
145-
/// `fingerprint`, missing: the task wrote it, or it is gone after the run
146-
/// and the task wrote in it. A write record on a folder, from opening it
147-
/// with write access, is ignored. Only a written path that the read found
148-
/// as a folder is stat'd under `workspace_root`, to tell a folder from a
149-
/// link the task made to one.
139+
/// Whether a later run may find the path missing. A rebuildable write
140+
/// allows this. A post-run `NotFound` also allows it if the task has a
141+
/// rebuildable write below the path. A write record on a folder, from
142+
/// opening it with write access, is ignored. Only a written path that the
143+
/// read found as a folder is stat'd under `workspace_root`, to tell a
144+
/// folder from a link the task made to one.
150145
pub fn may_be_missing(
151146
&self,
152147
path: &RelativePath,
@@ -195,7 +190,7 @@ impl Rebuildable {
195190
/// under it counts, folder entries are checked against the rebuildable
196191
/// folders, and the archive skips folders, so only a read of it has to tell
197192
/// (see [`Rebuildable::may_be_missing`]).
198-
fn files_written(
193+
pub(super) fn files_written(
199194
mut written: FxHashSet<RelativePathBuf>,
200195
rename_targets: FxHashSet<RelativePathBuf>,
201196
workspace_root: &AbsolutePath,
@@ -276,8 +271,11 @@ fn is_empty_folder(
276271
/// candidates too. Climbing stops at the first folder that isn't rebuildable,
277272
/// since no folder above it can be, and at the workspace root. A folder that
278273
/// is gone plays no part: its parent is decided by the entries it holds.
274+
/// Required writes are skipped so a tracked directory link stays required
275+
/// even if the task wrote through it.
279276
fn find_folders(
280277
written: &FxHashSet<RelativePathBuf>,
278+
required_writes: &FxHashSet<RelativePathBuf>,
281279
mkdirs: &FxHashSet<RelativePathBuf>,
282280
workspace_root: &AbsolutePath,
283281
cache_root: Option<&RelativePath>,
@@ -300,7 +298,8 @@ fn find_folders(
300298
empty_folders.insert(dir.to_relative_path_buf());
301299
}
302300
}
303-
let mut candidates: Vec<&RelativePath> = candidates.into_iter().collect();
301+
let mut candidates: Vec<&RelativePath> =
302+
candidates.into_iter().filter(|dir| !required_writes.contains(*dir)).collect();
304303
sort_deepest_first(&mut candidates);
305304

306305
let mut folders = empty_folders.clone();
@@ -351,8 +350,7 @@ fn sort_deepest_first(dirs: &mut [&RelativePath]) {
351350
/// aside, which don't count, as in directory listing fingerprints.
352351
enum Holds {
353352
Nothing,
354-
/// At least one entry, each a file (or symlink) the task wrote or a
355-
/// rebuildable folder.
353+
/// At least one entry, with every entry rebuildable.
356354
OnlyRebuildable,
357355
/// Anything else, or entries that can't be read or named.
358356
Other,
@@ -415,3 +413,27 @@ fn is_rebuildable(
415413
) -> bool {
416414
if is_dir { folders.contains(path) } else { written.contains(path) }
417415
}
416+
417+
#[cfg(test)]
418+
impl Rebuildable {
419+
pub(super) fn new(
420+
written: FxHashSet<RelativePathBuf>,
421+
rename_targets: FxHashSet<RelativePathBuf>,
422+
mkdirs: FxHashSet<RelativePathBuf>,
423+
workspace_root: &AbsolutePath,
424+
cache_root: Option<&RelativePath>,
425+
) -> Self {
426+
Self::from_written(
427+
files_written(written, rename_targets, workspace_root, cache_root),
428+
mkdirs,
429+
)
430+
}
431+
432+
pub(super) fn with_folders(
433+
self,
434+
workspace_root: &AbsolutePath,
435+
cache_root: Option<&RelativePath>,
436+
) -> Self {
437+
self.with_folders_excluding(workspace_root, cache_root, &FxHashSet::default())
438+
}
439+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
2+
import { ignoreInput, ignoreOutput } from '@voidzero-dev/vite-task-client';
3+
4+
const cacheDir = 'tool/cache';
5+
const statePath = `${cacheDir}/state.txt`;
6+
7+
mkdirSync(cacheDir, { recursive: true });
8+
readdirSync('tool');
9+
readdirSync('.');
10+
11+
writeFileSync(statePath, 'seed');
12+
readFileSync(statePath, 'utf8');
13+
if (process.argv[2] !== 'input-negative') ignoreInput(cacheDir);
14+
ignoreOutput(cacheDir);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "ignore-output-rebuildable-inputs",
3+
"private": true
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { existsSync, mkdirSync, readdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
2+
import { ignoreOutput } from '@voidzero-dev/vite-task-client';
3+
4+
const present = existsSync('alias');
5+
if (present) readdirSync('alias');
6+
7+
mkdirSync('real', { recursive: true });
8+
rmSync('alias', { recursive: true, force: true });
9+
symlinkSync('real', 'alias', 'junction');
10+
writeFileSync('alias/child.txt', 'output\n');
11+
ignoreOutput('alias');
12+
writeFileSync('result.txt', present ? 'present\n' : 'missing\n');
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2+
import { ignoreOutput } from '@voidzero-dev/vite-task-client';
3+
4+
const state = existsSync('state.json')
5+
? JSON.parse(readFileSync('state.json', 'utf8'))
6+
: { value: 'missing' };
7+
8+
ignoreOutput('state.json');
9+
writeFileSync('state.json', JSON.stringify(state) + '\n');
10+
writeFileSync('result.json', JSON.stringify({ read: state.value }) + '\n');

0 commit comments

Comments
 (0)