{"record":{"id":"d5c76d7d3dbb61b9","repo":"BoundaryML/baml","slug":"failed-to-read-value-segment-error","errorCode":null,"errorMessage":"failed to read value segment {}: {error}","messagePattern":"failed to read value segment (.+?): (.+?)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_events/src/history/mod.rs","lineNumber":356,"sourceCode":"}\n\n#[cfg(not(target_arch = \"wasm32\"))]\nfn open_boundary_from_dir(dir: &Path) -> io::Result<Run> {\n    open_boundary_from_segments(&read_value_segments(dir)?, Some(dir))\n}\n\n#[cfg(not(target_arch = \"wasm32\"))]\nfn read_value_segments(dir: &Path) -> io::Result<Vec<HistoryValueSegment>> {\n    value_segment_paths(dir)\n        .into_iter()\n        .map(|path| {\n            std::fs::read(&path)\n                .map(|bytes| HistoryValueSegment {\n                    label: path.display().to_string(),\n                    bytes,\n                })\n                .map_err(|error| {\n                    io::Error::new(\n                        error.kind(),\n                        format!(\"failed to read value segment {}: {error}\", path.display()),\n                    )\n                })\n        })\n        .collect()\n}\n\npub fn open_boundary_from_value_segments(\n    value_segments: &[HistoryValueSegment],\n) -> io::Result<Run> {\n    open_boundary_from_segments(value_segments, None)\n}\n\nfn open_boundary_from_segments(\n    value_segments: &[HistoryValueSegment],\n    fallback_dir: Option<&Path>,\n) -> io::Result<Run> {","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_events/src/history/mod.rs#L338-L374","documentation":"read_value_segments reads each .bamlvalue segment file with std::fs::read; any I/O failure is wrapped in an io::Error preserving the OS error kind, with a message naming the failed path and underlying error. It indicates a value segment file exists in the listing but cannot be read.","triggerScenarios":"Boundary directory contains a .bamlvalue file that is unreadable: deleted between listing and read, permission-restricted, or a hardware/OS read error.","commonSituations":"Concurrent cleanup deleting segments while replay reads them; running replay as a user without read permission; truncated files on a failing disk.","solutions":["Check the preserved io::ErrorKind (e.g. PermissionDenied vs NotFound) and address that condition.","Re-run the recording session to regenerate complete, consistent segment files.","Avoid deleting history files concurrently with replay.","Verify filesystem permissions on the boundary directory."],"exampleFix":"// before\nlet segs = read_value_segments(&dir)?;\n// after\nlet segs = match read_value_segments(&dir) {\n    Ok(s) => s,\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {\n        eprintln!(\"segment vanished mid-replay, restarting\");\n        return restart_replay();\n    }\n    Err(e) => return Err(e),\n};","handlingStrategy":"retry","validationCode":"for p in segment_paths {\n    let meta = std::fs::metadata(&p)\n        .map_err(|e| format!(\"segment {} unreadable: {e}\", p.display()))?;\n    if meta.len() == 0 { return Err(format!(\"segment {} empty\", p.display())); }\n}","typeGuard":null,"tryCatchPattern":"let segs = loop {\n    match read_value_segments(&dir) {\n        Ok(s) => break s,\n        Err(e) if e.kind() == std::io::ErrorKind::NotFound && tries < 3 => { tries += 1; continue; }\n        Err(e) => return Err(e),\n    }\n};","preventionTips":["Never clean up history files concurrently with replay.","Grant the replaying process read access to the boundary directory.","Retry transient NotFound/Permission errors; regenerate artifacts for permanent ones."],"tags":["io","file-read","history","filesystem"],"backgroundTag":"file-read-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"}