Skip to content

Async-safe log forwarding for FFI consumers #3

Closed

Description

@leehack

Release triage — 2026-10-05

Priority: P2 · not a release blocker. llamadart cannot forward runtime logs or quote load-failure reasons and names the missing file roles instead; diagnostics are weaker but behavior is correct. Schedule after the release (leehack/llamadart#778, leehack/llamadart#802).

sd_set_log_callback passes a const char* valid only during the call, and it may be invoked from worker threads. Dart can only receive it asynchronously (NativeCallable.listener), by which time the pointer is dangling, so the llamadart prototype could not forward runtime logs.

Add a small exported helper (for example sd_native_set_log_sink) that copies each line into an owned buffer before handing it to the callback, with a matching free function. Keep it outside upstream sources, add it to the export allowlist, and document ownership.

Needed by leehack/llamadart#778.

Activity

  1. leehack commented on Oct 1, 2026

    @leehack
    OwnerAuthor

    Another consumer of this: load diagnostics (leehack/llamadart#802). When new_sd_ctx fails, the reason exists only as [ERROR] log lines, for example VAE tensor 'first_stage_model.decoder.conv_in.bias' not in model metadata for an SD 3.5 GGUF passed as diffusion_model_path, or Conditioner model tensor 'text_encoders.llm...' not in model metadata for Z-Image without llm_path. llamadart cannot quote them, so it now names the missing file roles instead.

    Some of these lines come from the model loader's worker threads (model_loader.cpp logs read failures inside its std::thread workers), so an isolate-local Dart callback would abort the process; NativeCallable.isolateGroupBound is experimental and crashed in a quick test on Dart 3.13.1. A copying sink that also keeps the last N ERROR lines retrievable after a failed new_sd_ctx (for example sd_native_take_error_log) would let llamadart put them in the exception.

  2. added
    priority:P2Important improvement or regression; schedule next
    on Oct 6, 2026
  3. leehack commented on Oct 24, 2026

    @leehack
    OwnerAuthor

    Met by #17: a polled, copying log recorder (sd_dart_log_enable/read/dropped) plus sd_dart_last_error, shipped in v0.2.0-2 and in v0.3.0, adopted by llamadart in leehack/llamadart#971. It differs from the suggested callback sink but covers the same need without a cross-thread callback.

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

    enhancementNew feature or requestpriority:P2Important improvement or regression; schedule next

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions