You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix ggml_metal crash on app exit (llama.cpp Metal cleanup) #1063
The app crashes on exit with a ggml_metal_device_init / ggml_metal_device_free backtrace from llama.cpp's Metal backend cleanup. This happens consistently during app shutdown:
The crash occurs in the C++ destructor chain during process exit (__cxa_finalize_ranges), when llama.cpp's static Metal device vector is destroyed. The Metal context has already been torn down by the time the static destructor runs, causing a use-after-free abort.
Impact
Crash report dialog appears on every app close
No data loss (crash happens after all Rust cleanup completes)
Bad UX — users see a crash every time they quit the app
Likely Root Cause
llama.cpp stores Metal devices in a static vector<unique_ptr<ggml_metal_device>>. During process exit, C++ static destructors run in reverse order. If the Metal framework has already been cleaned up by macOS before the static vector destructor runs, ggml_metal_device_free accesses freed Metal resources and aborts.
Explicitly drop llama.cpp contexts before process exit — ensure all LlamaModel, LlamaContext, and related objects are dropped in our Rust shutdown sequence, before the process exits and C++ static destructors run
Check if our llama.cpp binding version has a fix — the linked PR may address this
As a fallback: suppress the crash dialog on macOS by catching the signal during shutdown
Activity
malibio commentedon Apr 7, 2026
Baseline: 128 test files passed, 3918 tests passed
Fix ggml_metal crash on app exit by resetting inference engine before…
Add ManagedAgentState reset methods for shutdown cleanup
Remove unused import SchemaNode from tools.rs
Fix ggml_metal crash on app exit (llama.cpp Metal cleanup) (#1065)
malibio commentedon Apr 7, 2026
✅ Issue #1063 resolved and merged to main via PR #1065
Summary
Fixed the ggml_metal crash on app exit by implementing proper cleanup ordering:
Verification
The fix ensures ChatEngine Arc is explicitly dropped before Metal backend teardown, preventing use-after-free crashes during shutdown.
Fix retroactive review findings for Metal crash fix (#1063)
Fix retroactive review findings for PRs #1063, #1065, #1069
Fix: semantic search service-layer filtering and skill pipeline (retr…
Fix: retroactive review findings for Metal crash fix (#1063)
Fix ggml_metal crash on app exit (llama.cpp Metal cleanup) (#1065)
Fix: semantic search service-layer filtering and skill pipeline (retr…
Fix: retroactive review findings for Metal crash fix (#1063)