BoundaryML/baml · error

failed to create engine: {e:?}

Error message

failed to create engine: {e:?}

What it means

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.

Source

Thrown at baml_language/crates/baml_cli/src/test_command.rs:420

            crate::bytecode_cache::cache_debug(format_args!(
                "stdlib interface: {} honest derivation(s) this process",
                baml_db::baml_compiler2_hir_ty::package_interface::stdlib_honest_derivations()
            ));
            // Warm-incremental evidence: with the diagnostics cache serving clean
            // files this counts only the dirty files' scopes.
            crate::bytecode_cache::cache_debug(format_args!(
                "body inferences: {} this process",
                baml_db::baml_compiler2_hir_ty::infer::body_inferences()
            ));

            Arc::new(
                BexEngine::new_with_runtime_compiler(
                    compiled.program,
                    Arc::new(sys_native::SysOps::native()),
                    Vec::new(),
                    bex_project::runtime_compiler(),
                )
                .map_err(|e| anyhow!("failed to create engine: {e:?}"))?,
            )
        };
        let unhandled_spawn_failures = Arc::new(AtomicUsize::new(0));
        let unhandled_spawn_failures_for_handler = Arc::clone(&unhandled_spawn_failures);
        engine.set_unhandled_spawn_error_handler(Some(Arc::new(move |report| {
            let cancelled = report.cancelled;
            let error = report.into_engine_error();
            if cancelled {
                eprintln!("WARN cancelled spawned task failed: {error}");
            } else {
                eprintln!("FAIL testing::unhandled_spawn_error");
                eprintln!("  => {error}");
                unhandled_spawn_failures_for_handler.fetch_add(1, Ordering::SeqCst);
            }
        })));
        let rt = tokio::runtime::Runtime::new().context("failed to create tokio runtime")?;
        let cancel = CancellationToken::new();
        let run_ctx = RunCtx {

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Inspect the debug payload after "failed to create engine:" for the engine-side rejection reason.
  2. 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.
  3. Retry after a clean rebuild of the project to rule out transient native-runtime issues.
  4. Update or reinstall the baml toolchain if the engine and CLI versions are mismatched; report as a bug if reproducible on valid sources.

Example fix

// before
rm -rf .baml-cache && baml test  // stale artifacts can poison engine construction
// after
baml agent/CLI upgraded to matching version; clear cache:
rm -rf .baml-cache && baml test
Defensive patterns

Strategy: retry

Try / catch

if ! baml test 2>err.log; then
  if grep -q 'failed to create engine' err.log; then
    rm -rf .baml-cache   // clear stale artifacts and retry once
    baml test || { cat err.log; exit 1; }
  fi
fi

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/469150edb4d1bf7e. Report an issue: GitHub.