Skip to content

Commit 627e0ad

Browse files
committed
revert(cache): revert tracked getEnv fingerprint
1 parent 2055bb0 commit 627e0ad

16 files changed

Lines changed: 54 additions & 343 deletions

File tree

CHANGELOG.md

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

3-
- **Added** Runner-aware `getEnv` reads can now participate in task cache fingerprints, so changing a tool-served env value invalidates the cache and names the env var in the miss message.
43
- **Added** Runner-aware tools can now opt the current task run out of caching through the new IPC channel; Vite dev server integration uses this automatically ([#441](https://github.com/voidzero-dev/vite-task/pull/441))
54
- **Fixed** Prefix environment assignments like `PATH=... command` now affect executable lookup during task planning, so tools provided only by the prefixed `PATH` can be resolved correctly ([#440](https://github.com/voidzero-dev/vite-task/pull/440))
65
- **Changed** Cache misses caused by a tracked env var now name the env var inline, for example `cache miss: env 'NODE_ENV' changed`, instead of the generic `envs changed` message ([#438](https://github.com/voidzero-dev/vite-task/pull/438))

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ pub fn format_cache_status_inline(cache_status: &CacheStatus) -> Option<Str> {
195195
FingerprintMismatch::InputChanged { kind, path } => {
196196
format_input_change_str(*kind, path.as_str())
197197
}
198-
FingerprintMismatch::TrackedEnvChanged(mismatch) => {
199-
format_env_changed_inline(&[mismatch.name()])
200-
}
201198
};
202199
Some(vite_str::format!("○ cache miss: {reason}, executing"))
203200
}

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

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
pub mod archive;
44
pub mod display;
55

6-
use std::{
7-
collections::BTreeMap, ffi::OsStr, fmt::Display, fs::File, io::Write, sync::Arc, time::Duration,
8-
};
6+
use std::{collections::BTreeMap, fmt::Display, fs::File, io::Write, sync::Arc, time::Duration};
97

108
// Re-export display functions for convenience
119
pub use display::format_cache_status_inline;
@@ -14,7 +12,6 @@ pub use display::{
1412
format_spawn_change,
1513
};
1614
use rusqlite::{Connection, OptionalExtension as _};
17-
use rustc_hash::FxHashMap;
1815
use serde::{Deserialize, Serialize};
1916
use tokio::sync::Mutex;
2017
use vite_path::{AbsolutePath, RelativePathBuf};
@@ -168,23 +165,6 @@ impl EnvMismatch {
168165
}
169166
}
170167
}
171-
172-
/// Compare a stored env value against the current one, returning the
173-
/// mismatch if they differ. `None` on either side means the env is unset
174-
/// there; two unset or two equal values are not a mismatch.
175-
#[must_use]
176-
pub fn compare(name: &Str, stored: Option<&Str>, current: Option<&Str>) -> Option<Self> {
177-
match (stored, current) {
178-
(None, Some(value)) => Some(Self::Added { name: name.clone(), value: value.clone() }),
179-
(Some(value), None) => Some(Self::Removed { name: name.clone(), value: value.clone() }),
180-
(Some(old_value), Some(new_value)) if old_value != new_value => Some(Self::Changed {
181-
name: name.clone(),
182-
old_value: old_value.clone(),
183-
new_value: new_value.clone(),
184-
}),
185-
_ => None,
186-
}
187-
}
188168
}
189169

190170
impl Display for EnvMismatch {
@@ -218,16 +198,23 @@ pub enum FingerprintMismatch {
218198
kind: InputChangeKind,
219199
path: RelativePathBuf,
220200
},
221-
/// A runner-aware tool-tracked env var changed between runs.
222-
TrackedEnvChanged(EnvMismatch),
223201
}
224202

225-
impl From<crate::session::execute::fingerprint::PostRunMismatch> for FingerprintMismatch {
226-
fn from(mismatch: crate::session::execute::fingerprint::PostRunMismatch) -> Self {
227-
use crate::session::execute::fingerprint::PostRunMismatch;
228-
match mismatch {
229-
PostRunMismatch::InputChanged { kind, path } => Self::InputChanged { kind, path },
230-
PostRunMismatch::TrackedEnvChanged(mismatch) => Self::TrackedEnvChanged(mismatch),
203+
impl Display for FingerprintMismatch {
204+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
205+
match self {
206+
Self::SpawnFingerprint { old, new } => {
207+
write!(f, "Spawn fingerprint changed: old={old:?}, new={new:?}")
208+
}
209+
Self::InputConfig => {
210+
write!(f, "input configuration changed")
211+
}
212+
Self::OutputConfig => {
213+
write!(f, "output configuration changed")
214+
}
215+
Self::InputChanged { kind, path } => {
216+
write!(f, "{}", display::format_input_change_str(*kind, path.as_str()))
217+
}
231218
}
232219
}
233220
}
@@ -253,7 +240,7 @@ pub fn split_path(path: &str) -> (Option<&str>, &str) {
253240
/// its own cache warm across branch switches, and a cache from a different
254241
/// version is simply ignored (it lives in a directory this build never looks
255242
/// at) rather than aborting the run. Bumping the version starts a fresh cache.
256-
const CACHE_SCHEMA_VERSION: u32 = 14;
243+
const CACHE_SCHEMA_VERSION: u32 = 13;
257244

258245
/// Name of the per-version subdirectory (e.g. `v13`) under the task-cache
259246
/// directory that holds the database and output archives for the current
@@ -305,7 +292,6 @@ impl ExecutionCache {
305292
cache_metadata: &CacheMetadata,
306293
globbed_inputs: &BTreeMap<RelativePathBuf, u64>,
307294
workspace_root: &AbsolutePath,
308-
envs: &FxHashMap<Arc<OsStr>, Arc<OsStr>>,
309295
) -> anyhow::Result<Result<CacheEntryValue, CacheMiss>> {
310296
let spawn_fingerprint = &cache_metadata.spawn_fingerprint;
311297
let execution_cache_key = &cache_metadata.execution_cache_key;
@@ -321,11 +307,11 @@ impl ExecutionCache {
321307
return Ok(Err(CacheMiss::FingerprintMismatch(mismatch)));
322308
}
323309

324-
// Validate post-run fingerprint (inferred inputs + tracked envs)
325-
if let Some(mismatch) =
326-
cache_value.post_run_fingerprint.validate(workspace_root, envs)?
327-
{
328-
return Ok(Err(CacheMiss::FingerprintMismatch(mismatch.into())));
310+
// Validate post-run fingerprint (inferred inputs from fspy)
311+
if let Some((kind, path)) = cache_value.post_run_fingerprint.validate(workspace_root)? {
312+
return Ok(Err(CacheMiss::FingerprintMismatch(
313+
FingerprintMismatch::InputChanged { kind, path },
314+
)));
329315
}
330316
// Associate the execution key to the cache entry key if not already,
331317
// so that next time we can find it and report what changed

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

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Post-run cache update: decide whether a finished spawn may be cached and,
22
//! if so, store its fingerprint, captured output, and output archive.
33
4-
use std::{collections::BTreeMap, sync::Arc, time::Duration};
4+
use std::{sync::Arc, time::Duration};
55

66
use vite_path::{AbsolutePath, RelativePathBuf};
77
use vite_str::Str;
@@ -97,19 +97,13 @@ pub(super) async fn update_cache(
9797
return (CacheUpdateStatus::NotUpdated(CacheNotUpdatedReason::FspyUnsupported), None);
9898
}
9999

100-
// Collect tool-reported tracked envs for the post-run fingerprint. Env
101-
// names that the user already declared are skipped because their values
102-
// are already part of the spawn fingerprint.
103-
let tracked_envs = reports.map(|r| collect_tracked_envs(r, metadata)).unwrap_or_default();
104-
105100
// Paths already in globbed_inputs are skipped: the overlap check above
106101
// guarantees no input modification, so the prerun hash is the correct
107102
// post-exec hash.
108103
let empty_path_reads = HashMap::default();
109104
let path_reads = fspy_outcome.as_ref().map_or(&empty_path_reads, |o| &o.path_reads);
110105
let post_run_fingerprint =
111-
match PostRunFingerprint::create(path_reads, workspace_root, &globbed_inputs, tracked_envs)
112-
{
106+
match PostRunFingerprint::create(path_reads, workspace_root, &globbed_inputs) {
113107
Ok(fingerprint) => fingerprint,
114108
Err(err) => {
115109
return (
@@ -172,26 +166,6 @@ fn observe_fspy(
172166
}
173167
}
174168

175-
/// Select tool-reported env records to embed in the post-run fingerprint.
176-
/// Only `tracked: true` records are included, and names that the user already
177-
/// declared as fingerprinted are skipped.
178-
fn collect_tracked_envs(reports: &Reports, metadata: &CacheMetadata) -> BTreeMap<Str, Option<Str>> {
179-
let fingerprinted = &metadata.spawn_fingerprint.env_fingerprints().fingerprinted_envs;
180-
reports
181-
.env_records
182-
.iter()
183-
.filter(|(_, record)| record.tracked)
184-
.filter_map(|(name, record)| {
185-
let name_str = name.to_str()?;
186-
if fingerprinted.contains_key(name_str) {
187-
return None;
188-
}
189-
let value = record.value.as_ref().and_then(|value| value.to_str().map(Str::from));
190-
Some((Str::from(name_str), value))
191-
})
192-
.collect()
193-
}
194-
195169
/// Collect output files matching the configured globs and create a tar.zst
196170
/// archive in the cache directory.
197171
///

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

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,18 @@
55
66
use std::{
77
collections::BTreeMap,
8-
ffi::OsStr,
98
fs::File,
109
io::{self, BufRead},
1110
sync::Arc,
1211
};
1312

1413
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
15-
use rustc_hash::FxHashMap;
1614
use serde::{Deserialize, Serialize};
1715
use vite_path::{AbsolutePath, RelativePathBuf};
1816
use vite_str::Str;
1917
use wincode::{SchemaRead, SchemaWrite};
2018

21-
use crate::{
22-
collections::HashMap,
23-
session::cache::{EnvMismatch, InputChangeKind},
24-
};
19+
use crate::{collections::HashMap, session::cache::InputChangeKind};
2520

2621
/// Path read access info
2722
#[derive(Debug, Clone, Copy)]
@@ -36,21 +31,6 @@ pub struct PostRunFingerprint {
3631
/// Paths inferred from fspy during execution with their content fingerprints.
3732
/// Only populated when `input_config.includes_auto` is true.
3833
pub inferred_inputs: HashMap<RelativePathBuf, PathFingerprint>,
39-
40-
/// Env vars observed via runner-aware IPC `getEnv` with `tracked: true`.
41-
/// Key is the env name; value is the env value at execution time, or
42-
/// `None` if unset. Validated at cache lookup against the same plan env
43-
/// context that served the original request.
44-
pub tracked_envs: BTreeMap<Str, Option<Str>>,
45-
}
46-
47-
/// A mismatch between the stored post-run fingerprint and the current state.
48-
#[derive(Debug, Clone)]
49-
pub enum PostRunMismatch {
50-
/// An inferred input file or directory changed.
51-
InputChanged { kind: InputChangeKind, path: RelativePathBuf },
52-
/// A tool-tracked env var changed value, appeared, or disappeared.
53-
TrackedEnvChanged(EnvMismatch),
5434
}
5535

5636
/// Fingerprint for a single path (file or directory)
@@ -89,13 +69,11 @@ impl PostRunFingerprint {
8969
/// * `inferred_path_reads` - Map of paths that were read during execution (from fspy)
9070
/// * `base_dir` - Workspace root for resolving relative paths
9171
/// * `globbed_inputs` - Prerun glob fingerprint; paths here are skipped
92-
/// * `tracked_envs` - Tool-requested env vars (name -> value), validated on lookup
9372
#[tracing::instrument(level = "debug", skip_all, name = "create_post_run_fingerprint")]
9473
pub fn create(
9574
inferred_path_reads: &HashMap<RelativePathBuf, PathRead>,
9675
base_dir: &AbsolutePath,
9776
globbed_inputs: &BTreeMap<RelativePathBuf, u64>,
98-
tracked_envs: BTreeMap<Str, Option<Str>>,
9977
) -> anyhow::Result<Self> {
10078
let inferred_inputs = inferred_path_reads
10179
.par_iter()
@@ -107,17 +85,16 @@ impl PostRunFingerprint {
10785
})
10886
.collect::<anyhow::Result<HashMap<_, _>>>()?;
10987

110-
Ok(Self { inferred_inputs, tracked_envs })
88+
Ok(Self { inferred_inputs })
11189
}
11290

113-
/// Validates the fingerprint against current filesystem state and env
114-
/// context. Returns `Some(mismatch)` if anything changed, `None` if all valid.
91+
/// Validates the fingerprint against current filesystem state.
92+
/// Returns `Some((kind, path))` if an input changed, `None` if all valid.
11593
#[tracing::instrument(level = "debug", skip_all, name = "validate_post_run_fingerprint")]
11694
pub fn validate(
11795
&self,
11896
base_dir: &AbsolutePath,
119-
envs: &FxHashMap<Arc<OsStr>, Arc<OsStr>>,
120-
) -> anyhow::Result<Option<PostRunMismatch>> {
97+
) -> anyhow::Result<Option<(InputChangeKind, RelativePathBuf)>> {
12198
let input_mismatch = self.inferred_inputs.par_iter().find_map_any(
12299
|(input_relative_path, path_fingerprint)| {
123100
let input_full_path = Arc::<AbsolutePath>::from(base_dir.join(input_relative_path));
@@ -143,25 +120,11 @@ impl PostRunFingerprint {
143120
} else {
144121
input_relative_path.clone()
145122
};
146-
Some(Ok(PostRunMismatch::InputChanged { kind, path }))
123+
Some(Ok((kind, path)))
147124
}
148125
},
149126
);
150-
if let Some(result) = input_mismatch {
151-
return result.map(Some);
152-
}
153-
154-
for (name, stored_value) in &self.tracked_envs {
155-
let current_value =
156-
envs.get(OsStr::new(name.as_str())).and_then(|value| value.to_str().map(Str::from));
157-
if let Some(mismatch) =
158-
EnvMismatch::compare(name, stored_value.as_ref(), current_value.as_ref())
159-
{
160-
return Ok(Some(PostRunMismatch::TrackedEnvChanged(mismatch)));
161-
}
162-
}
163-
164-
Ok(None)
127+
input_mismatch.transpose()
165128
}
166129
}
167130

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,7 @@ async fn lookup_cache(
531531
Report::failed(ExecutionError::Cache { kind: CacheErrorKind::Lookup, source: err })
532532
})?;
533533

534-
match cache
535-
.try_hit(cache_metadata, &globbed_inputs, workspace_root, &cache_metadata.unfiltered_envs)
536-
.await
537-
{
534+
match cache.try_hit(cache_metadata, &globbed_inputs, workspace_root).await {
538535
Ok(Ok(cached)) => Ok(CacheLookup::Hit(cached)),
539536
Ok(Err(miss)) => Ok(CacheLookup::Miss { miss, globbed_inputs }),
540537
Err(err) => {

crates/vite_task/src/session/reporter/summary.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use vite_str::Str;
1717
use super::{CACHE_MISS_STYLE, COMMAND_STYLE, ColorizeExt};
1818
use crate::session::{
1919
cache::{
20-
CacheMiss, EnvMismatch, FingerprintMismatch, InputChangeKind, SpawnFingerprintChange,
20+
CacheMiss, FingerprintMismatch, InputChangeKind, SpawnFingerprintChange,
2121
detect_spawn_fingerprint_changes, format_input_change_str, format_spawn_change,
2222
},
2323
event::{
@@ -135,8 +135,6 @@ pub enum SavedCacheMissReason {
135135
ConfigChanged,
136136
/// An input file or folder changed.
137137
InputChanged { kind: InputChangeKind, path: Str },
138-
/// A runner-aware tool reported a tracked env var that changed between runs.
139-
TrackedEnvChanged(EnvMismatch),
140138
}
141139

142140
/// An execution error, serializable for persistence.
@@ -280,9 +278,6 @@ impl SavedCacheMissReason {
280278
FingerprintMismatch::InputChanged { kind, path } => {
281279
Self::InputChanged { kind: *kind, path: Str::from(path.as_str()) }
282280
}
283-
FingerprintMismatch::TrackedEnvChanged(mismatch) => {
284-
Self::TrackedEnvChanged(mismatch.clone())
285-
}
286281
},
287282
}
288283
}
@@ -572,9 +567,6 @@ impl TaskResult {
572567
let desc = format_input_change_str(*kind, path.as_str());
573568
vite_str::format!("→ Cache miss: {desc}")
574569
}
575-
SavedCacheMissReason::TrackedEnvChanged(mismatch) => {
576-
vite_str::format!("→ Cache miss: {mismatch}")
577-
}
578570
},
579571
},
580572
}

0 commit comments

Comments
 (0)