jdx/mise · info

watch file mtime changed

Error message

watch file mtime changed: {} (expected: {}, current: {})

What it means

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.

Solutions

  1. Re-run the mise command — the cache invalidates and a fresh environment is computed and re-cached.
  2. If the mtime change is spurious (file content identical), it will still invalidate; re-caching fixes it.
  3. Avoid tools that gratuitously rewrite watched files in place.
  4. Clear the cache directory if stale entries persist.

Example fix

// before: .env edited
touch .env && mise run dev
// after: cache revalidated and rebuilt automatically
Defensive patterns

Strategy: fallback

Validate before calling

// before trusting the cache, verify freshness yourself
for p in watch_files { let m = p.metadata()?.modified()?; if m > cached_at { return Ok(None); } }

Try / catch

match env_cache::load(...) { Err(e) if e.to_string().contains("mtime changed") => { cacheMiss = true; recompute_env() }, other => other? }

Prevention

When it happens

Trigger: Calling `load` after editing, touching, or regenerating a watched file so `get_file_mtime(path) != expected_mtime`.

Common situations: Editing a .env or config file that mise watches; a tool rewriting the file on checkout; switching branches where the file differs.

Understand the failure class

Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/e00065aaecb99772. Report an issue: GitHub.

Appendix: source

Thrown at src/toolset/env_cache.rs:73

        .map_err(|e| eyre::eyre!("decryption failed: {}", e))?;
    Ok(plaintext)
}

fn validate_watch_files(watch_files: &[PathBuf], expected_mtimes: &[u64]) -> Result<()> {
    if watch_files.len() != expected_mtimes.len() {
        bail!("watch file count mismatch");
    }
    for (path, expected_mtime) in watch_files.iter().zip(expected_mtimes.iter()) {
        if !path.exists() {
            // mtime=0 means file didn't exist when cached - skip if still doesn't exist
            if *expected_mtime == 0 {
                continue;
            }
            bail!("watch file no longer exists: {}", path.display());
        }
        if let Some(current_mtime) = get_file_mtime(path) {
            if current_mtime != *expected_mtime {
                bail!(
                    "watch file mtime changed: {} (expected: {}, current: {})",
                    path.display(),
                    expected_mtime,
                    current_mtime
                );
            }
        } else {
            bail!("could not get mtime for watch file: {}", path.display());
        }
    }
    Ok(())
}

/// Represents the cached environment data
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct CachedEnv {
    /// Cached environment variables
    pub env: BTreeMap<String, String>,

View on GitHub (pinned to 533346cc37)