{"record":{"id":"7862448db5c510e3","repo":"BoundaryML/baml","slug":"value-record-mixed-capture-loss-metadata-with-body-metadata","errorCode":null,"errorMessage":"value record mixed capture loss metadata with body metadata","messagePattern":"value record mixed capture loss metadata with body metadata","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_events/src/value/read.rs","lineNumber":85,"sourceCode":"            || !record.body.is_empty()\n            || has_log_event\n            || has_capture_loss\n            || record.blob.is_some())\n    {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            \"value record mixed body metadata with lifecycle metadata\",\n        ));\n    }\n    if let Some(started) = record.run_started {\n        return Ok(ValueFileRecord::RunStarted(started.try_into()?));\n    }\n    if let Some(completed) = record.run_completed {\n        return Ok(ValueFileRecord::RunCompleted(completed.try_into()?));\n    }\n    if let Some(loss) = record.capture_loss {\n        if record.metadata.is_some() || has_log_event {\n            return Err(io::Error::new(\n                io::ErrorKind::InvalidData,\n                \"value record mixed capture loss metadata with body metadata\",\n            ));\n        }\n        return Ok(ValueFileRecord::CaptureLoss(loss.try_into()?));\n    }\n    let metadata = record.metadata.ok_or_else(|| {\n        io::Error::new(io::ErrorKind::InvalidData, \"value record omitted metadata\")\n    })?;\n    if let Some(log_event) = record.log_event {\n        return Ok(ValueFileRecord::LogEvent(LogRecord {\n            value_ref: metadata.try_into()?,\n            body: record.body,\n            blob_ref: record.blob.map(TryInto::try_into).transpose()?,\n            event: log_event.try_into()?,\n        }));\n    }\n    Err(io::Error::new(","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_events/src/value/read.rs#L67-L103","documentation":"A capture_loss record must not carry value-body metadata. file_record_from_proto rejects a record where capture_loss is set together with metadata or a log_event, keeping capture-loss bookkeeping separate from event payloads. Raised as io::Error(InvalidData) when decoding the value file.","triggerScenarios":"read_bamlvalue_from_bytes() on a record with capture_loss set plus record.metadata or record.log_event — indicates a corrupted file or a writer violating the record schema.","commonSituations":"Buggy custom writers, concurrent appenders interleaving records, external post-processing that merges fields, or format version mismatches.","solutions":["Regenerate the value file from the source run instead of patching the corrupted record.","Fix the producer to write CaptureLoss records with only the capture_loss field populated.","Verify no external tooling rewrites or merges records in the .bamlvalue file."],"exampleFix":"// before\nrecord.capture_loss = Some(loss);\nrecord.metadata = Some(meta); // not allowed\n// after\nwrite_record(ValueFileRecord::CaptureLoss(loss));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match read_bamlvalue_from_bytes(&bytes) {\n    Err(e) if e.to_string().contains(\"capture loss\") => {\n        eprintln!(\"capture-loss record contaminated with body fields: {e}\");\n        // treat file as corrupt; regenerate or skip record\n    }\n    other => other?,\n}","preventionTips":["Write CaptureLoss records with only the capture_loss field set.","Serialize records through the library's enum types so field exclusivity is enforced by construction.","Do not merge or rewrite records with ad-hoc tooling."],"tags":["rust","event-file","protobuf","corruption"],"backgroundTag":"schema-validation-failed","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"}