Skip to content

SIGABRT crash on tokio-rt-worker during embeddings after fresh document import (release build) #990

Closed

Description

@malibio

Summary

The app crashes with SIGABRT on a tokio-rt-worker thread when computing embeddings after importing documents into a fresh database. This only occurs in release builds — debug builds work fine.

Reproducible: Yes — fresh database → import docs → crash when embeddings start (~1-2 minutes after launch).

Crash Report

Process: nodespace-app
Exception Type: EXC_CRASH (SIGABRT)
Triggered by Thread: tokio-rt-worker
Termination Reason: Namespace SIGNAL, Code 6, Abort trap: 6
Application Specific Information: abort() called
Platform: ARM-64 (Apple Silicon), macOS 26.3.1

No useful stack trace — release builds have `strip = true`.

Root Cause Analysis

Primary: Unsafe unwrap on Metal context creation

File: `packages/nlp-engine/src/embedding.rs:291`
```rust
Ok(self.context.as_mut().unwrap())
```
If Metal context creation fails silently on ARM64, this unwrap panics on a tokio worker thread → SIGABRT.

Contributing: Unsafe transmute of context lifetime

File: `packages/nlp-engine/src/embedding.rs:276-281`
```rust
// SAFETY: We're extending the lifetime of the context to 'static.
let ctx: LlamaContext<'static> = unsafe { std::mem::transmute(ctx) };
self.context = Some(ctx);
```
With aggressive LTO + opt-level 3, the compiler may reorder operations around this transmute.

Contributing: Aggressive release optimizations

File: `Cargo.toml:35-40`
```toml
[profile.release]
panic = "unwind"
codegen-units = 1
lto = true
opt-level = 3
strip = true
```
LTO + opt-level 3 + codegen-units 1 can trigger edge cases in llama.cpp Metal kernel compilation on ARM64.

Contributing: Immediate processor wake after init

File: `packages/desktop-app/src-tauri/src/commands/db.rs:104-109`
```rust
processor.wake(); // <-- IMMEDIATE WAKE after init
```
During fresh import, nodes are created and marked stale. `processor.wake()` fires immediately, spawning embedding tasks while imports may still be in flight.

Proposed Fixes (in priority order)

  1. Replace unwrap with proper error handling in `embedding.rs:291` — return an error instead of panicking
  2. Add tokio panic hook to log context before abort on worker threads
  3. Delay embedding wake — wait for import to complete before waking the processor
  4. Test with reduced optimization — try `opt-level = 2` or `lto = "thin"` for the nlp-engine crate
  5. Remove strip = true temporarily to get useful crash stack traces

Steps to Reproduce

  1. Build release: `bunx tauri build --target aarch64-apple-darwin`
  2. Install the .dmg
  3. Launch app with fresh/empty database
  4. Import documentation via MCP or import script
  5. App crashes ~1-2 minutes in when embeddings processing starts

Environment

  • macOS 26.3.1, Apple Silicon (Mac16,8)
  • NodeSpace v0.1.5
  • Rust release profile: opt-level=3, lto=true, strip=true

Activity

  1. added
    bug
    on Mar 20, 2026
  2. malibio commented on Mar 20, 2026

    @malibio
    CollaboratorAuthor

    Investigation Update

    Tested local release builds to isolate the cause:

    Build Rust version Result
    GitHub Actions 1.94.0 SIGABRT on embeddings
    Local release 1.91.0 Works fine
    Local release 1.94.0 Works fine

    Conclusion: Not a Rust version issue. The crash is specific to the GitHub Actions macos-latest runner environment — likely differences in macOS version, Metal GPU drivers, or the runner's hardware/virtualization layer.

    Both local release builds processed the same stale embeddings queue that crashed the GitHub-built binary without issues.

    Next steps:

    • Low priority — the app works correctly when built locally
    • If needed, could try adding RUST_BACKTRACE=1 to the GitHub build environment to capture more info on next crash
    • Could also test with macos-14 or macos-15 runner instead of macos-latest to see if a specific runner version is the issue
  3. malibio commented on Mar 20, 2026

    @malibio
    CollaboratorAuthor

    Definitive Root Cause Found

    With strip=false, the crash trace is now clear:

    Thread 9 Crashed:: tokio-rt-worker
    3   ggml_abort + 160
    4   ggml_mul_mat + 236
    5   llm_graph_context::build_pooling(...) + 184
    6   llama_model::build_graph(...) + 2092
    7   llama_context::graph_reserve(...) + 668
    8   llama_context::sched_reserve() + 1540
    9   llama_context::llama_context(...) + 4332
    10  llama_init_from_model + 488
    11  llama_new_context_with_model + 60
    12  EmbeddingService::generate_embedding_internal + 3624
    

    The crash is a tensor shape assertion in ggml's ggml_mul_mat during build_pooling → build_graph → context constructor. This is inside llama.cpp's C code — not our Rust code.

    Additionally, Thread 15 shows __ggml_metal_rsets_init_block_invoke running concurrently — Metal resource initialization racing with graph construction.

    Why GitHub-only: The GitHub Actions macos-latest runner is a VM. Its Metal implementation differs from real Apple Silicon hardware — either missing Metal GPU entirely or providing a software Metal implementation that causes ggml's pooling graph to fail a matrix dimension assertion.

    Local builds work because they run on real Apple Silicon with proper Metal hardware.

    Current llama-cpp-2 version: 0.1.132

    Fix options:

    1. Set n_gpu_layers = 0 when Metal is unavailable — detect VM/headless and fall back to CPU
    2. Catch the abort — not possible since it's a C-level abort(), not a Rust panic
    3. Update llama-cpp-2 — newer versions may have fixed the pooling graph assertion
    4. Accept it — this only affects GitHub-built binaries, local builds work fine. Users install from GitHub releases though, so this needs fixing.
  4. malibio commented on Apr 5, 2026

    @malibio
    CollaboratorAuthor

    Fixed across multiple commits: pinned llama-cpp-2 to 0.1.132 (v0.1.139 had ggml_mul_mat regression), bumped MACOSX_DEPLOYMENT_TARGET to 14.0 for Metal ggml compatibility, committed Cargo.lock for reproducible builds, and restored strip=true after diagnosis.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions