Skip to content

Wrapper: catch C++ exceptions at the C ABI so a llama.cpp throw is an error, not a process abort #102

Closed

Description

@leehack

llama_dart_sampler_sample (and the other guarded wrapper calls) forward straight to llama.cpp with no exception barrier. When llama.cpp throws — e.g. std::runtime_error: Unexpected empty grammar stack after accepting piece from llama_grammar_accept_token — the exception crosses the C ABI into Dart FFI and the process aborts (SIGABRT in the Dart worker).

Seen on a Pixel 9 Pro in leehack/llamadart#948, where wrong Vulkan logits make the sampler pick a token the grammar rejects. Upstream closed the general report as not planned: ggml-org/llama.cpp#29715. The same abort existed before the wrapper (v0.5.0, direct llama_sampler_sample).

Ask

Wrap each exported llama_dart_* call that can reach throwing llama.cpp code in try/catch (...), return a distinguishable failure value, and expose the last error message so llamadart can raise a typed LlamaException. Cover at least sample, decode/encode, model/context creation and the mtmd calls.

Acceptance

  • A test that forces a grammar-stack throw and shows the call returns an error and the process survives.
  • llamadart maps the failure to a typed exception.

Activity

  1. added
    bug
    priority:P2
    on Oct 7, 2026
  2. leehack commented on Oct 14, 2026

    @leehack
    OwnerAuthor

    Fixed by #103 (exception barrier), released in v0.6.0-1 and adopted in llamadart#974.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority:P2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions