{"record":{"id":"a93803c0132ac959","repo":"BoundaryML/baml","slug":"value-record-mixed-run-started-with-run-completed-lifecycle","errorCode":null,"errorMessage":"value record mixed run_started with run_completed lifecycle metadata","messagePattern":"value record mixed run_started with run_completed lifecycle metadata","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_events/src/value/read.rs","lineNumber":60,"sourceCode":"        records.push(file_record_from_proto(record)?);\n        buf = rest;\n    }\n\n    Ok(BamlvalueContents {\n        header,\n        records,\n        truncated,\n    })\n}\n\nfn file_record_from_proto(record: pb::ValueRecordV1) -> io::Result<ValueFileRecord> {\n    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()?));","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_events/src/value/read.rs#L42-L78","documentation":"When decoding a value file record (file_record_from_proto), a record carrying both run_started and run_completed lifecycle metadata is rejected: one record may describe at most one lifecycle event. This protects the event-file format's invariant that lifecycle bookkeeping is stored in dedicated records, and is surfaced as an io::Error with InvalidData kind from read_bamlvalue_from_bytes.","triggerScenarios":"read_bamlvalue_from_bytes() on a value file whose protobuf record has both the run_started and run_completed oneofs set — typically a corrupted, hand-edited, or incorrectly merged file.","commonSituations":"Files corrupted by concurrent writers appending to the same value file, buggy external tooling that rewrites records, or merging/truncation mishaps that splice records together.","solutions":["Regenerate the value file by re-running the workflow; do not attempt to repair the mixed record by hand.","If you author .bamlvalue files programmatically, emit run_started and run_completed as separate records.","Check for concurrent writers — each run must write to its own value file."],"exampleFix":"// before\nrecord.run_started = Some(started);\nrecord.run_completed = Some(completed); // same record\n// after\nwrite_record(ValueFileRecord::RunStarted(started));\nwrite_record(ValueFileRecord::RunCompleted(completed));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match read_bamlvalue_from_bytes(&bytes) {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"lifecycle\") => {\n        eprintln!(\"value file corrupted (mixed lifecycle record): {e}\");\n        // fall back to re-running the workflow / restoring a backup\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Write run_started and run_completed as separate records, one per record.","Never append to a value file from multiple processes concurrently.","Avoid post-processing or rewriting .bamlvalue files with external tools."],"tags":["rust","event-file","protobuf","corruption"],"backgroundTag":"mutually-exclusive-options","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"}