{"record":{"id":"07ad10ab24f6689f","repo":"jdx/mise","slug":"compiler-environment-input-changed-name","errorCode":null,"errorMessage":"compiler environment input changed: {name}","messagePattern":"compiler environment input changed: (.+?)","errorType":"exception","errorClass":"eyre::Report","httpStatus":null,"severity":"error","filePath":"src/cache/rustc.rs","lineNumber":259,"sourceCode":"            _ => bail!(\"cache agent returned an unexpected prediction response\"),\n        }\n    })();\n    if let Err(error) = result {\n        eprintln!(\"mise rustc cache warning: action prediction was not recorded: {error:#}\");\n    }\n}\n\nfn verify_environment(environment: &BTreeMap<String, Option<String>>) -> Result<()> {\n    for (name, expected) in environment {\n        let actual = std::env::var_os(name)\n            .map(|value| {\n                value.into_string().map_err(|_| {\n                    eyre::eyre!(\"compiler environment input is not valid UTF-8: {name}\")\n                })\n            })\n            .transpose()?;\n        if &actual != expected {\n            bail!(\"compiler environment input changed: {name}\");\n        }\n    }\n    Ok(())\n}\n\nfn restore_result(\n    action: &RustcAction,\n    outputs: &RustcOutputs,\n    discovered: &DiscoveredInputs,\n    restore_outputs: bool,\n) -> Result<Option<CachedCompilation>> {\n    let responses = session::request_agent(&[AgentRequest::FindActionResult {\n        action: action.digest.clone(),\n    }])?;\n    let Some(response) = responses.into_iter().next() else {\n        bail!(\"cache agent did not return an action lookup response\");\n    };\n    let result = match response {","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/jdx/mise/blob/9dcfcaa0dc8747a2577d3270b69bb9d8313b2807/src/cache/rustc.rs#L241-L277","documentation":"The cache records compiler-relevant environment variables as part of the invocation identity. On replay, verify_environment re-reads each recorded variable and requires the exact same value (including unset-vs-empty); any difference bails with 'compiler environment input changed: NAME' (src/cache/rustc.rs:259). This is a correctness guard: reusing cached outputs under a changed env would be wrong.","triggerScenarios":"Building with a recorded cache hit while an environment variable the compilation captured (e.g. RUSTFLAGS, CARGO_*, CC, SDKROOT) differs from when the entry was recorded — set in one shell and not another, toggled by CI matrix jobs, or changed by a direnv/config update.","commonSituations":"CI jobs sharing a cache but differing in RUSTFLAGS or target env; developer shells with per-project .envrc exports; RUSTC_WRAPPER/toolchain updates changing recorded env between record and replay.","solutions":["Make the environment deterministic: export the same RUSTFLAGS/CARGO_*/CC values in every build that shares the cache","Re-run the build once with the new env so a fresh entry is recorded for it","Don't share one cache agent/store across environments that intentionally differ in these variables"],"exampleFix":"# before: one shell recorded with default flags\nexport RUSTFLAGS=\"\"\n# later shell replays with\nexport RUSTFLAGS=\"-C target-cpu=native\"\n\n# after: keep env identical across cached builds\nexport RUSTFLAGS=\"-C target-cpu=native\"  # used for both record and replay","handlingStrategy":"validation","validationCode":"# Rust: snapshot the recorded env and diff before replaying\nfn env_matches(recorded: &std::collections::BTreeMap<String, Option<String>>) -> Result<(), String> {\n    for (k, expected) in recorded {\n        let actual = std::env::var_os(k).map(|v| v.to_string_lossy().into_owned());\n        if actual.as_ref().map(|s| Some(s.clone())) != Some(expected.clone()) {\n            return Err(format!(\"compiler environment input changed: {k}\"));\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Export identical RUSTFLAGS/CARGO_*/CC in every job sharing a cache","Re-run once after intentional env changes to re-record","Don't share cache stores across CI matrix legs with different env"],"tags":["mise","rustc-cache","environment","cache-invalidation","rustflags"],"backgroundTag":"environment-mismatch","analyzedSha":"9dcfcaa0dc8747a2577d3270b69bb9d8313b2807","analyzedAt":"2026-08-17T14:28:50.624Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}