{"record":{"id":"e64a68e8cb1a9c67","repo":"BoundaryML/baml","slug":"baml-cache-verify-cached-diagnostics-for-differ-from-a-fresh","errorCode":null,"errorMessage":"BAML_CACHE_VERIFY: cached diagnostics for `{}` differ from a fresh check ({} cached vs {} fresh). The cached per-file diagnostics are a stale substitute — please report this.","messagePattern":"BAML_CACHE_VERIFY: cached diagnostics for `(.+?)` differ from a fresh check \\((.+?) cached vs (.+?) fresh\\)\\. The cached per-file diagnostics are a stale substitute — please report this\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/bytecode_cache.rs","lineNumber":1957,"sourceCode":"        let clean_files = compute_dirty_partition(db, package, &manifest).clean_files;\n        for entry in &manifest.files {\n            if !clean_files.contains(&entry.rel_path) {\n                continue; // dirty — always re-checked, never served from cache\n            }\n            let full = root.join(&entry.rel_path);\n            let Some(sf) = db.get_file(&full) else {\n                continue; // file removed — never served\n            };\n            let Some(served) =\n                crate::diagnostics_cache::rehydrate_file_blob(db, root, &entry.diagnostics)\n            else {\n                continue; // poison / undecodable — would degrade to a re-check\n            };\n            // What an honest run produces for this file: `check_file` output only\n            // (the package-level set is never cached, so it is excluded here too).\n            let fresh = db.check_file(sf);\n            if !diagnostic_sets_equal(&served, &fresh) {\n                anyhow::bail!(\n                    \"BAML_CACHE_VERIFY: cached diagnostics for `{}` differ from a fresh check \\\n                     ({} cached vs {} fresh). The cached per-file diagnostics are a stale \\\n                     substitute — please report this.\",\n                    entry.rel_path,\n                    served.len(),\n                    fresh.len(),\n                );\n            }\n        }\n        Ok(())\n    }\n\n    /// Load the previous manifest for the verify oracle, bypassing the\n    /// `plan_reuse` verify short-circuit (verify must still compare against\n    /// whatever manifest is on disk).\n    fn load_prev_manifest_for_verify(&self) -> Option<ProjectManifest> {\n        self.load_decoded(&self.manifest_key, \"manifest\")\n    }","sourceCodeStart":1939,"sourceCodeEnd":1975,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/bytecode_cache.rs#L1939-L1975","documentation":"This is BAML's built-in cache verification check (BAML_CACHE_VERIFY). After serving diagnostics from the bytecode cache, it re-runs db.check_file on the same source and compares; if the cached diagnostic set differs from the freshly computed one, the cache served stale per-file diagnostics and the library deliberately fails loudly and asks for a report, because silent staleness would mislead users.","triggerScenarios":"verify_and_store (or the verify pass) loads cached diagnostics for entry.rel_path, computes the fresh result with db.check_file(sf), and diagnostic_sets_equal finds a mismatch — e.g. the cache key missed an input that affects diagnostics (dependency, config, compiler version change), or the cached blob was written by a different compiler version.","commonSituations":"Upgrading baml without clearing the cache so old diagnostic blobs are replayed; project config (source root, generator settings) changed in ways the cache key doesn't capture; a genuine cache-correctness bug — the message explicitly requests a bug report.","solutions":["Clear the bytecode cache directory and re-run — stale blobs are discarded and diagnostics are recomputed.","Upgrade or align baml CLI/library versions across the team so cache writers and readers use the same compiler version.","Report this to the baml maintainers as the message requests, including the cache state and versions.","Temporarily disable the bytecode cache (run uncached) if you need unverified diagnostics immediately."],"exampleFix":"// before: replaying cache across compiler versions\n// (cache dir from baml 0.x reused by 0.y)\n// after: invalidate on upgrade\nrm -rf .baml_cache && baml build","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"BAML_CACHE_VERIFY\") => {\n        eprintln!(\"cache served stale diagnostics; bypassing cache\");\n        clear_cache_dir();\n        run_uncached()\n    }\n    other => other?,\n}","preventionTips":["Clear the cache directory after upgrading the baml toolchain.","Pin the same baml version across all team members and CI so cached blobs are compatible.","Bump/rotate the cache directory when project configuration that affects diagnostics changes.","Never edit or hand-craft cached diagnostic blobs; treat the cache as opaque.","If it fires on a stable setup, file the bug report the message requests instead of working around it silently."],"tags":["cache","stale-data","diagnostics","verification"],"backgroundTag":"checksum-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}