{"record":{"id":"c329181c018b6079","repo":"BoundaryML/baml","slug":"baml-cache-sampled-verify-the-incremental-cache-served-stale","errorCode":null,"errorMessage":"BAML_CACHE_SAMPLED_VERIFY: the incremental cache served STALE diagnostics for `{rel}` ({} served vs {} from an honest check). This is a cache-soundness bug — a warm build would report different errors than a clean one. Re-run with BAML_CACHE_VERIFY=1 for the full compare and please report this (file `{rel}`, artifact: diagnostics).","messagePattern":"BAML_CACHE_SAMPLED_VERIFY: the incremental cache served STALE diagnostics for `(.+?)` \\((.+?) served vs (.+?) from an honest check\\)\\. This is a cache-soundness bug — a warm build would report different errors than a clean one\\. Re-run with BAML_CACHE_VERIFY=1 for the full compare and please report this \\(file `(.+?)`, artifact: diagnostics\\)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/bytecode_cache.rs","lineNumber":2169,"sourceCode":"        plan: &ReusePlan,\n        rel: &str,\n    ) -> anyhow::Result<()> {\n        let root = honest_package.path(honest_db);\n        let full = root.join(rel);\n        let Some(sf) = honest_db.get_file(&full) else {\n            return Ok(()); // file vanished between planning and verify — unserved\n        };\n\n        // (1) Served diagnostics blob vs a fresh per-file check. A blob that\n        // fails to rehydrate would have degraded to a re-check (never served\n        // stale), so it is not a mismatch — skip it, as the full oracle does.\n        if let Some(blob) = plan.clean_diagnostics.get(rel)\n            && let Some(served) =\n                crate::diagnostics_cache::rehydrate_file_blob(honest_db, root, blob)\n        {\n            let fresh = honest_db.check_file(sf);\n            if !diagnostic_sets_equal(&served, &fresh) {\n                anyhow::bail!(\n                    \"BAML_CACHE_SAMPLED_VERIFY: the incremental cache served STALE diagnostics \\\n                     for `{rel}` ({} served vs {} from an honest check). This is a \\\n                     cache-soundness bug — a warm build would report different errors than a \\\n                     clean one. Re-run with BAML_CACHE_VERIFY=1 for the full compare and please \\\n                     report this (file `{rel}`, artifact: diagnostics).\",\n                    served.len(),\n                    fresh.len(),\n                );\n            }\n        }\n\n        // (2) Served `callable_throws` fragment vs an honest derivation. The\n        // served copy is the manifest-resident blob (what the seeds project\n        // from); an empty fragment seeds nothing, so there is no served\n        // artifact to check.\n        if let Some(fragment) = plan.clean_fragments.get(rel)\n            && !fragment.is_empty()\n        {","sourceCodeStart":2151,"sourceCodeEnd":2187,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/bytecode_cache.rs#L2151-L2187","documentation":"Under sampled verification, baml re-runs diagnostics honestly (honest_db.check_file) for a file the incremental cache claims is clean and compares with the rehydrated cached diagnostics blob. If they differ, the cache served stale diagnostics — a warm build would report different errors than a clean one — and it bails as a cache-soundness bug.","triggerScenarios":"Running a build with sampled cache verification where plan.clean_diagnostics[rel] rehydrated via rehydrate_file_blob does not equal diagnostic_sets_equal(&served, &fresh) against honest_db.check_file(sf).","commonSituations":"Editing a file (or its dependencies) that the incremental dependency tracker failed to dirty; running diagnostics across compiler versions with an old cache; CI cache restored from a different commit.","solutions":["Delete the bytecode/diagnostics cache and run a clean build to get correct diagnostics.","Re-run with BAML_CACHE_VERIFY=1 to obtain the full comparison and identify which file served stale data.","Report the reproduction (file `{rel}`, artifact: diagnostics) to baml maintainers."],"exampleFix":"# before\nbaml build  # warm cache, stale diagnostics\n# after\nrm -rf .baml && baml build  # clean diagnostics","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = build() {\n    if e.to_string().contains(\"served STALE diagnostics\") {\n        fs::remove_dir_all(\".baml\");\n        return build(); // clean rebuild gives correct diagnostics\n    }\n    return Err(e);\n}","preventionTips":["Don't share incremental caches across commits/branches in CI","Clear cache after compiler version changes","Enable sampled verification in CI to detect unsound caches before shipping"],"tags":["cache","diagnostics","incremental-compilation","cache-soundness"],"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"}