{"record":{"id":"e00065aaecb99772","repo":"jdx/mise","slug":"watch-file-mtime-changed-expected-curren","errorCode":null,"errorMessage":"watch file mtime changed: {} (expected: {}, current: {})","messagePattern":"watch file mtime changed: (.+?) \\(expected: (.+?), current: (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/toolset/env_cache.rs","lineNumber":73,"sourceCode":"        .map_err(|e| eyre::eyre!(\"decryption failed: {}\", e))?;\n    Ok(plaintext)\n}\n\nfn validate_watch_files(watch_files: &[PathBuf], expected_mtimes: &[u64]) -> Result<()> {\n    if watch_files.len() != expected_mtimes.len() {\n        bail!(\"watch file count mismatch\");\n    }\n    for (path, expected_mtime) in watch_files.iter().zip(expected_mtimes.iter()) {\n        if !path.exists() {\n            // mtime=0 means file didn't exist when cached - skip if still doesn't exist\n            if *expected_mtime == 0 {\n                continue;\n            }\n            bail!(\"watch file no longer exists: {}\", path.display());\n        }\n        if let Some(current_mtime) = get_file_mtime(path) {\n            if current_mtime != *expected_mtime {\n                bail!(\n                    \"watch file mtime changed: {} (expected: {}, current: {})\",\n                    path.display(),\n                    expected_mtime,\n                    current_mtime\n                );\n            }\n        } else {\n            bail!(\"could not get mtime for watch file: {}\", path.display());\n        }\n    }\n    Ok(())\n}\n\n/// Represents the cached environment data\n#[derive(Debug, Clone, Serialize, Deserialize)]\npub(crate) struct CachedEnv {\n    /// Cached environment variables\n    pub env: BTreeMap<String, String>,","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/toolset/env_cache.rs#L55-L91","documentation":"The env cache stores mtimes of watched files to detect changes. If any watched file's current mtime differs from the cached expected mtime, `validate_watch_files` bails so `load` treats the cached environment as stale rather than serving possibly-outdated env vars.","triggerScenarios":"Calling `load` after editing, touching, or regenerating a watched file so `get_file_mtime(path) != expected_mtime`.","commonSituations":"Editing a .env or config file that mise watches; a tool rewriting the file on checkout; switching branches where the file differs.","solutions":["Re-run the mise command — the cache invalidates and a fresh environment is computed and re-cached.","If the mtime change is spurious (file content identical), it will still invalidate; re-caching fixes it.","Avoid tools that gratuitously rewrite watched files in place.","Clear the cache directory if stale entries persist."],"exampleFix":"// before: .env edited\ntouch .env && mise run dev\n// after: cache revalidated and rebuilt automatically","handlingStrategy":"fallback","validationCode":"// before trusting the cache, verify freshness yourself\nfor p in watch_files { let m = p.metadata()?.modified()?; if m > cached_at { return Ok(None); } }","typeGuard":null,"tryCatchPattern":"match env_cache::load(...) { Err(e) if e.to_string().contains(\"mtime changed\") => { cacheMiss = true; recompute_env() }, other => other? }","preventionTips":["Expect cache misses after touching/watched-file edits — design callers to recompute.","Avoid tools that rewrite watched files in place without changing content.","Version-control .env style files so edits are intentional."],"tags":["cache","mtime","invalidation"],"backgroundTag":"checksum-mismatch","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}