BoundaryML/baml · warning · VmPanic

baml.panics.Cancelled

baml.panics.Cancelled

Error message

operation cancelled

What it means

Raised when a running BAML operation is cancelled, typically because the host or user requested termination of the execution (e.g. a cancellation token or deadline fired). It is the VM's cooperative cancellation signal for long-running work.

Source

Thrown at baml_language/crates/bex_vm_types/src/errors.rs:57

    #[error("invalid field access: field {field_index} of {field_count}")]
    InvalidFieldAccess {
        field_index: usize,
        field_count: usize,
    },

    #[error("key not found in map")]
    MapKeyNotFound,

    #[error("stack overflow")]
    StackOverflow,

    #[error("assertion failed")]
    AssertionFailed,

    #[error("unreachable code executed")]
    Unreachable,

    #[error("operation cancelled")]
    Cancelled,

    /// A user-caused panic from `baml.sys.panic`, and the stdlib's panic of
    /// record for a user-violated native invariant (e.g. a reflection kind
    /// view's `_ty` field overwritten with a type of a different kind).
    #[error("baml.sys.panic: {message}")]
    UserPanic { message: String },

    /// A clean process-termination request from `baml.sys.exit(code)`.
    ///
    /// Catchable in user code as `baml.panics.Exit` — patterned after
    /// Python's `SystemExit`: code can intercept it for cleanup or
    /// testing, and if nothing catches it the engine surfaces the code
    /// as `EngineError::Exit` and the host terminates with it.
    ///
    /// BAML `int` is `i64`, so the signal carries the full value the
    /// user wrote; the host narrows to `i32` for `std::process::exit`.
    #[error("baml.sys.exit({code})")]

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Treat it as an expected cancellation: catch `baml.panics.Cancelled` and unwind cleanly.
  2. Check the cancellation source (timeout, user abort) and retry with a longer budget if cancellation was premature.
  3. Make long-running BAML code hit cancellation checkpoints regularly so it stops promptly.

Example fix

// host side: catch and treat as cooperative stop
match vm.run(func) {
  Err(Panic::Cancelled) => info!("execution cancelled by host"),
  other => other?,
}
Defensive patterns

Strategy: try-catch

Try / catch

// BAML
try {
  long_task();
} catch (e: baml.panics.Cancelled) {
  cleanup();
  return err("cancelled");
}

Prevention

When it happens

Trigger: The host calls the VM's cancel/abort API while execution is in progress, a timeout elapses, or a user interrupts a long-running LLM call; the next cancellation check point panics with `Cancelled`.

Common situations: CLI Ctrl+C during a BAML function run, request timeouts in a server wrapping the VM, test harnesses cancelling stuck executions.

Related errors


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