{"record":{"id":"5e2cd6d253e25358","repo":"BoundaryML/baml","slug":"value-record-mixed-body-metadata-with-lifecycle-metadata","errorCode":null,"errorMessage":"value record mixed body metadata with lifecycle metadata","messagePattern":"value record mixed body metadata with lifecycle metadata","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_events/src/value/read.rs","lineNumber":72,"sourceCode":"    let has_run_started = record.run_started.is_some();\n    let has_run_completed = record.run_completed.is_some();\n    let has_lifecycle = has_run_started || has_run_completed;\n    let has_log_event = record.log_event.is_some();\n    let has_capture_loss = record.capture_loss.is_some();\n    if has_run_started && has_run_completed {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            \"value record mixed run_started with run_completed lifecycle metadata\",\n        ));\n    }\n    if has_lifecycle\n        && (record.metadata.is_some()\n            || !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()?));","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_events/src/value/read.rs#L54-L90","documentation":"file_record_from_proto rejects a record that has lifecycle metadata (run_started or run_completed) together with any body content: metadata, non-empty body, log_event, capture_loss, or blob. Lifecycle records must stand alone; mixing them with payload data violates the value-file record schema. Raised as io::Error(InvalidData) during read_bamlvalue_from_bytes.","triggerScenarios":"Reading a value file record where a run_started/run_completed oneof is set alongside metadata/body/log_event/capture_loss/blob fields — produced by a buggy writer, corrupted file, or incompatible format version.","commonSituations":"External tools rewriting event files incorrectly, concurrent appends interleaving two records into one, or writing with an older/newer schema that packed fields differently.","solutions":["Regenerate the value file; treat it as corrupted rather than repairing bytes by hand.","Fix the writer to emit lifecycle metadata in its own record with all other fields unset.","Confirm the file was written by a compatible version of bex_events and not post-processed externally."],"exampleFix":"// before\nrecord.run_started = Some(started);\nrecord.metadata = Some(meta); // lifecycle + body\n// after\nwrite_record(ValueFileRecord::RunStarted(started));\nwrite_record(ValueFileRecord::LogEvent(LogRecord { .. }));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let value = read_bamlvalue_from_bytes(&bytes).map_err(|e| {\n    if e.to_string().contains(\"mixed body metadata with lifecycle\") {\n        eprintln!(\"value file record schema violated: {e}\");\n    }\n    e\n})?;","preventionTips":["Emit lifecycle metadata (run_started/run_completed) in dedicated records with all other fields unset.","Use the library's writer types (ValueFileRecord enum) rather than hand-filling protobuf records.","Validate written files by reading them back once at end of run."],"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"}