{"record":{"id":"d418efd013845881","repo":"BoundaryML/baml","slug":"bamlvalue-header-boundary-id-must-be-16-bytes-got","errorCode":null,"errorMessage":".bamlvalue header boundary id must be 16 bytes, got {}","messagePattern":"\\.bamlvalue header boundary id must be 16 bytes, got (.+?)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_events/src/history/mod.rs","lineNumber":638,"sourceCode":"            ),\n        ));\n    }\n    fallback_dir\n        .and_then(boundary_id_from_dir_name)\n        .ok_or_else(|| {\n            io::Error::new(\n                io::ErrorKind::InvalidData,\n                format!(\n                    \"history boundary for project {} omitted canonical boundary id\",\n                    started.request.project_id.0\n                ),\n            )\n        })\n}\n\nfn boundary_id_from_header(bytes: &[u8]) -> io::Result<BoundaryId> {\n    let bytes: [u8; 16] = bytes.try_into().map_err(|_| {\n        io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\n                \".bamlvalue header boundary id must be 16 bytes, got {}\",\n                bytes.len()\n            ),\n        )\n    })?;\n    Ok(BoundaryId::from_bytes(bytes))\n}\n\nfn boundary_id_from_dir_name(dir: &Path) -> Option<BoundaryId> {\n    let name = dir.file_name()?.to_str()?;\n    name.char_indices()\n        .rev()\n        .find_map(|(index, _)| BoundaryId::from_wire_str(&name[index..]))\n}\n\nfn capture_loss_replay_diagnostic(record: CaptureLossRecord) -> RunDiagnostic {","sourceCodeStart":620,"sourceCodeEnd":656,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_events/src/history/mod.rs#L620-L656","documentation":"boundary_id_from_header converts the 16-byte boundary ID stored in a .bamlvalue file header into a [u8; 16] BoundaryId; if the header field is any other length, InvalidData is returned with the actual byte count. This guards against corrupt, truncated, or hand-written segment headers.","triggerScenarios":"open_boundary_from_segments reading a .bamlvalue file whose header boundary-id field is not exactly 16 bytes — produced by an older/newer writer format, truncation, or manual file editing.","commonSituations":"Mixed bex_events versions writing incompatible header layouts; partially written files after a crash; tests crafting malformed byte segments directly.","solutions":["Regenerate the .bamlvalue segments with the current library version so headers are well-formed.","Check whether the file was truncated (compare size with the writer's expectation) and re-record if so.","Ensure all producers and consumers of history files use the same bex_events version.","Don't hand-edit segment files; craft test segments via the library's writer APIs."],"exampleFix":"// before\nlet id = boundary_id_from_header(header_bytes)?;\n// after\nif header_bytes.len() != 16 {\n    eprintln!(\"corrupt .bamlvalue header ({} bytes), re-recording\", header_bytes.len());\n    return re_record();\n}\nlet id = boundary_id_from_header(header_bytes)?;","handlingStrategy":"validation","validationCode":"if header_bytes.len() != 16 {\n    return Err(format!(\n        \".bamlvalue header boundary id is {} bytes, expected 16\",\n        header_bytes.len()\n    ));\n}","typeGuard":"fn is_valid_header(bytes: &[u8]) -> bool {\n    bytes.len() >= 16\n}","tryCatchPattern":"match boundary_id_from_header(header_bytes) {\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidData => {\n        Err(ArtifactError::CorruptHeader)\n    }\n    other => other,\n}","preventionTips":["Use the same bex_events version for writers and readers of .bamlvalue files.","Detect truncated files by size before parsing headers.","Never hand-edit binary segment files; build test fixtures via the writer API."],"tags":["io","invalid-data","format","history"],"backgroundTag":"invalid-argument-format","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}