{"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":"exception","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/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/toolset/env_cache.rs#L55-L91","documentation":"mise caches environment output keyed on the mtimes of watched files. If validation finds a file whose current mtime differs from the mtime recorded in the cache, the cached env may be stale, so mise rejects the cache and recomputes.","triggerScenarios":"env_cache::load compares get_file_mtime(path) against expected_mtime and they differ — any write, touch, or regeneration of a watched file after the cache was created.","commonSituations":"Editing .env or mise.toml between runs; CI/cron regenerating env files; tools rewriting config files (changing content or just mtime) even when contents are identical; git operations that update file timestamps.","solutions":["Nothing to fix if the edit was intended — mise simply recomputes the env; re-run the command","If the file's mtime changes spuriously (e.g. a tool rewrites it on every run), stop that tool from rewriting the file or write only when content changes","Clear caches (`mise cache clear`) if you suspect bad cache state","Avoid `touch`ing config files in scripts when contents don't change"],"exampleFix":"// before: script rewrites file every run, invalidating cache\necho \"KEY=val\" > .env\n// after: only write when changed\n[ -f .env ] || echo \"KEY=val\" > .env","handlingStrategy":"retry","validationCode":"// stat files yourself and compare to cached mtimes to predict invalidation\nconst changed = watchFiles.some(f => fs.statSync(f).mtimeMs !== cachedMtime(f));","typeGuard":null,"tryCatchPattern":"try { loadEnvCache() } catch (e) { if (String(e).includes('mtime changed')) { /* expected: recompute env */ recomputeEnv(); } else { throw e; } }","preventionTips":["Avoid touching/rewriting config files whose content didn't change","Make generators write files only when content differs","Exclude volatile files from watch lists","Be aware git operations update mtimes and will invalidate cache (harmless)"],"tags":["cache","mtime","env"],"backgroundTag":"cache-invalidation-mtime-changed","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}