{"record":{"id":"f7f9e2adeaffb821","repo":"BoundaryML/baml","slug":"honest-interface-fragment-for-failed-to-serialize-e","errorCode":null,"errorMessage":"honest interface fragment for `{}` failed to serialize: {e}","messagePattern":"honest interface fragment for `(.+?)` failed to serialize: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/bytecode_cache.rs","lineNumber":2047,"sourceCode":"        // served artifact is the manifest-resident fragment blob (seeds\n        // project from the manifest, not from unit payloads), so that copy is\n        // what the oracle must compare.\n        let clean_files = compute_dirty_partition(db, package, &manifest).clean_files;\n\n        for entry in &manifest.files {\n            if !clean_files.contains(&entry.rel_path) || entry.callable_throws_fragment.is_empty() {\n                continue;\n            }\n            let full = root.join(&entry.rel_path);\n            let Some(sf) = db.get_file(&full) else {\n                continue; // file removed — never seeded\n            };\n            let honest =\n                baml_db::baml_compiler2_hir_ty::package_interface::export_callable_throws_fragment(\n                    db, sf,\n                );\n            let honest_bytes = borsh::to_vec(&honest).map_err(|e| {\n                anyhow::anyhow!(\n                    \"honest interface fragment for `{}` failed to serialize: {e}\",\n                    entry.rel_path\n                )\n            })?;\n            if honest_bytes != entry.callable_throws_fragment {\n                anyhow::bail!(\n                    \"BAML_CACHE_VERIFY: cached interface fragment for `{}` differs from a fresh \\\n                     derivation ({} cached vs {} fresh bytes). A clean file's stored fragment is \\\n                     a stale substitute — the throws-taint closure failed to dirty a file whose \\\n                     `callable_throws` changed, so the seeded value would be \\\n                     wrong. Please report this.\",\n                    entry.rel_path,\n                    entry.callable_throws_fragment.len(),\n                    honest_bytes.len(),\n                );\n            }\n        }\n        Ok(())","sourceCodeStart":2029,"sourceCodeEnd":2065,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/bytecode_cache.rs#L2029-L2065","documentation":"During bytecode cache validation, baml re-derives a file's 'honest' interface fragment (callable throws set) via export_callable_throws_fragment and serializes it with borsh. If borsh serialization of the freshly derived fragment fails, this error is thrown, aborting the cache verify flow. It indicates the freshly derived type data could not be encoded to bytes.","triggerScenarios":"Running `baml build`/cache verification with BAML_CACHE_VERIFY enabled (or the internal honest-recompute path) where borsh::to_vec on export_callable_throws_fragment(db, sf) returns Err — e.g. a fragment containing a container exceeding borsh's u32 length limits, or a serialization schema mismatch in the HIR type structures.","commonSituations":"Very large generated interfaces with thousands of callables tripping borsh length encodings; internal schema drift between the hir_ty fragment type and its borsh derive after a compiler upgrade; corrupted incremental compilation state producing a fragment borsh cannot encode.","solutions":["Delete the `.baml` bytecode cache directory and re-run the build to recompute fragments from scratch.","Update baml-cli and baml_db crates to matching versions (schema drift between crates causes encode failures).","If reproducible on a clean cache, reduce interface size or file a bug with the offending .baml file; borsh encode failures on derived fragments are compiler-internal bugs."],"exampleFix":"// before\nlet honest_bytes = borsh::to_vec(&honest).map_err(|e| anyhow!(\"honest interface fragment for `{}` failed to serialize: {e}\", entry.rel_path))?;\n// after\n// no user-side fix; clear cache and retry\n// rm -rf .baml && baml build","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// match on the anyhow error and check message starts with \"honest interface fragment\"\nif let Err(e) = baml_build() {\n    if e.to_string().contains(\"failed to serialize\") {\n        std::fs::remove_dir_all(\".baml\").ok(); // clear cache and retry\n    }\n}","preventionTips":["Keep baml_cli and baml_db crates version-locked together","Clear .baml cache after compiler upgrades","Avoid extremely large single-file interfaces that push borsh length encodings"],"tags":["cache","serialization","rust","compiler"],"backgroundTag":"json-marshal-failed","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"}