{"record":{"id":"7c9de3079e8e6f2b","repo":"BoundaryML/baml","slug":"no-optimization-runs-found-in-run-baml-cli-optimize-first-to","errorCode":null,"errorMessage":"No optimization runs found in {}.\nRun 'baml-cli optimize' first to create an optimization run.","messagePattern":"No optimization runs found in (.+?)\\.\nRun 'baml-cli optimize' first to create an optimization run\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/cli/optimize.rs","lineNumber":744,"sourceCode":"            }\n\n            // Find the most recent run_* directory\n            let mut runs: Vec<_> = std::fs::read_dir(&optimize_base_dir)?\n                .filter_map(|entry| {\n                    let entry = entry.ok()?;\n                    let path = entry.path();\n                    if path.is_dir() {\n                        let name = path.file_name()?.to_string_lossy().to_string();\n                        if name.starts_with(\"run_\") {\n                            return Some(path);\n                        }\n                    }\n                    None\n                })\n                .collect();\n\n            if runs.is_empty() {\n                anyhow::bail!(\n                    \"No optimization runs found in {}.\\n\\\n                     Run 'baml-cli optimize' first to create an optimization run.\",\n                    optimize_base_dir.display()\n                );\n            }\n\n            // Sort by name (which includes timestamp) and take the most recent\n            runs.sort();\n            runs.pop().unwrap()\n        };\n\n        println!(\"Opening optimization viewer for: {}\", run_dir.display());\n\n        // Launch the TUI\n        crate::optimize::tui::run_tui(&run_dir)?;\n\n        Ok(OptimizeRunResult::ViewCompleted)\n    }","sourceCodeStart":726,"sourceCodeEnd":762,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/cli/optimize.rs#L726-L762","documentation":"Deeper into run_view_mode, the command lists entries inside .baml_optimize and collects valid optimization runs. If the directory exists but contains no parseable runs (runs list empty), it bails with this message naming the directory. Distinct from 907: the base directory exists but is empty or contains no valid run folders.","triggerScenarios":"Running `baml-cli optimize --view` when .baml_optimize exists but yields zero run entries — empty directory, only stray files (no run subdirectories), or all subdirectories failing the run-detection predicate.","commonSituations":"Previously interrupted optimize run that never wrote run data, manually cleaned .baml_optimize leaving the folder behind, runs produced by an older/incompatible CLI version with different folder naming.","solutions":["Run `baml-cli optimize` to produce a fresh optimization run.","Inspect .baml_optimize/ contents (`ls -la`) and delete stray/empty entries if they came from older versions.","Ensure the same CLI version is used for optimizing and viewing (upgrade both).","Verify your --from path matches the project whose runs you want to view."],"exampleFix":"// before (empty .baml_optimize/)\nbaml-cli optimize --view\n// after\nrm -rf .baml_optimize && baml-cli optimize --from baml_src && baml-cli optimize --view","handlingStrategy":"validation","validationCode":"# require at least one run subdirectory\nls -d .baml_optimize/*/ >/dev/null 2>&1 || { echo 'no runs in .baml_optimize'; exit 1; }","typeGuard":null,"tryCatchPattern":"catch (e) {\n  if (String(e.message).includes('No optimization runs found in')) {\n    // rm -rf the stale .baml_optimize and re-run optimize\n  }\n}","preventionTips":["Delete .baml_optimize entirely when clearing (don't leave an empty dir).","Avoid interrupted optimize runs; let them complete or clean up fully.","Use matching CLI versions for optimize and view."],"tags":["cli","optimize","empty"],"backgroundTag":"empty-result-set","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}