{"record":{"id":"469150edb4d1bf7e","repo":"BoundaryML/baml","slug":"failed-to-create-engine-e-test-command","errorCode":null,"errorMessage":"failed to create engine: {e:?}","messagePattern":"failed to create engine: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/test_command.rs","lineNumber":420,"sourceCode":"            crate::bytecode_cache::cache_debug(format_args!(\n                \"stdlib interface: {} honest derivation(s) this process\",\n                baml_db::baml_compiler2_hir_ty::package_interface::stdlib_honest_derivations()\n            ));\n            // Warm-incremental evidence: with the diagnostics cache serving clean\n            // files this counts only the dirty files' scopes.\n            crate::bytecode_cache::cache_debug(format_args!(\n                \"body inferences: {} this process\",\n                baml_db::baml_compiler2_hir_ty::infer::body_inferences()\n            ));\n\n            Arc::new(\n                BexEngine::new_with_runtime_compiler(\n                    compiled.program,\n                    Arc::new(sys_native::SysOps::native()),\n                    Vec::new(),\n                    bex_project::runtime_compiler(),\n                )\n                .map_err(|e| anyhow!(\"failed to create engine: {e:?}\"))?,\n            )\n        };\n        let unhandled_spawn_failures = Arc::new(AtomicUsize::new(0));\n        let unhandled_spawn_failures_for_handler = Arc::clone(&unhandled_spawn_failures);\n        engine.set_unhandled_spawn_error_handler(Some(Arc::new(move |report| {\n            let cancelled = report.cancelled;\n            let error = report.into_engine_error();\n            if cancelled {\n                eprintln!(\"WARN cancelled spawned task failed: {error}\");\n            } else {\n                eprintln!(\"FAIL testing::unhandled_spawn_error\");\n                eprintln!(\"  => {error}\");\n                unhandled_spawn_failures_for_handler.fetch_add(1, Ordering::SeqCst);\n            }\n        })));\n        let rt = tokio::runtime::Runtime::new().context(\"failed to create tokio runtime\")?;\n        let cancel = CancellationToken::new();\n        let run_ctx = RunCtx {","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/test_command.rs#L402-L438","documentation":"After compiling successfully, `baml test` instantiates the Bex execution engine with `BexEngine::new_with_runtime_compiler`. If engine construction fails, the CLI wraps the debug-formatted error in `anyhow!(\"failed to create engine: {e:?}\")` and aborts the run. This is a runtime-initialization failure, distinct from compilation errors.","triggerScenarios":"`BexEngine::new_with_runtime_compiler(compiled.program, Arc::new(SysOps::native()), Vec::new(), bex_project::runtime_compiler())` returns Err during `TestArgs::run` — e.g. the compiled program is rejected by the engine or native runtime setup fails.","commonSituations":"A program that compiles but violates an engine-level invariant; a corrupted or incompatible bytecode-cache reuse plan feeding a bad program; platform/native runtime issues in the sandboxed environment; an engine/toolchain version mismatch after an upgrade.","solutions":["Inspect the debug payload after \"failed to create engine:\" for the engine-side rejection reason.","Clear the bytecode/build cache (e.g. remove the project's cache directory or run with cache verification env vars like BAML_CACHE_VERIFY/BAML_NO_DISCOVERY_CACHE) and retry to rule out stale artifacts.","Retry after a clean rebuild of the project to rule out transient native-runtime issues.","Update or reinstall the baml toolchain if the engine and CLI versions are mismatched; report as a bug if reproducible on valid sources."],"exampleFix":"// before\nrm -rf .baml-cache && baml test  // stale artifacts can poison engine construction\n// after\nbaml agent/CLI upgraded to matching version; clear cache:\nrm -rf .baml-cache && baml test","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if ! baml test 2>err.log; then\n  if grep -q 'failed to create engine' err.log; then\n    rm -rf .baml-cache   // clear stale artifacts and retry once\n    baml test || { cat err.log; exit 1; }\n  fi\nfi","preventionTips":["Clear the bytecode/build cache after toolchain upgrades.","Keep the baml CLI and engine/runtime components version-aligned.","Treat this as a bug report trigger if it reproduces on valid sources."],"tags":["cli","engine","runtime","testing","baml"],"backgroundTag":"module-init-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}