{"record":{"id":"cb17be3ea16b1cb9","repo":"BoundaryML/baml","slug":"baml-cache-verify-cached-bytecode-for-key-differs-from-a","errorCode":null,"errorMessage":"BAML_CACHE_VERIFY: cached bytecode for key {} differs from a fresh compile ({} vs {} bytes). This means emit is nondeterministic or a compile input is missing from the cache key — please report this.","messagePattern":"BAML_CACHE_VERIFY: cached bytecode for key (.+?) differs from a fresh compile \\((.+?) vs (.+?) bytes\\)\\. This means emit is nondeterministic or a compile input is missing from the cache key — please report this\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/bytecode_cache.rs","lineNumber":217,"sourceCode":"        }\n    }\n\n    pub(crate) fn load(&self) -> Option<Program> {\n        self.cache.load_shared(&self.key)\n    }\n\n    /// The `BAML_CACHE_VERIFY` tripwire: byte-compare a fresh compile against\n    /// any existing entry under the same key. A mismatch is a hard error —\n    /// it means emit is nondeterministic or a compile input is missing from\n    /// the cache key.\n    pub(crate) fn verify_against(&self, program: &Program) -> anyhow::Result<()> {\n        if !Self::verify_enabled() {\n            return Ok(());\n        }\n        if let Some(cached) = self.cache.load_raw(&self.key) {\n            let fresh = borsh::to_vec(program)?;\n            if fresh != cached {\n                anyhow::bail!(\n                    \"BAML_CACHE_VERIFY: cached bytecode for key {} differs from a fresh \\\n                     compile ({} vs {} bytes). This means emit is nondeterministic or a \\\n                     compile input is missing from the cache key — please report this.\",\n                    self.key.hex(),\n                    cached.len(),\n                    fresh.len(),\n                );\n            }\n        }\n        Ok(())\n    }\n\n    /// Write-through after a successful compile. Best-effort: a cache write\n    /// problem must never fail the run.\n    pub(crate) fn store(&self, program: &Program) -> std::io::Result<()> {\n        self.cache.store_shared(&self.key, program)?;\n        self.cache.maybe_trim();\n        Ok(())","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/bytecode_cache.rs#L199-L235","documentation":"Error \"BAML_CACHE_VERIFY: cached bytecode for key {} differs from a fresh compile ({} vs {} bytes). This means emit is nondeterministic or a compile input is missing from the cache key — please report this.\" thrown in BoundaryML/baml.","triggerScenarios":"Thrown at baml_language/crates/baml_cli/src/bytecode_cache.rs:217 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not disable BAML_CACHE_VERIFY while iterating; keep it on so the drift is caught early","If the error is reproducible, minimize the .baml project that triggers it and report it to the BAML maintainers — a deterministic emit or a complete cache key is required","For the missing-cache-key case, check whether any compile inputs (env vars, file mtimes, generated files) participate in compilation but are absent from the key computation"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}