macOS: app aborts on quit after ONNX Runtime was initialized
Describe the bug
On macOS, quitting with Cmd+Q sometimes aborts with SIGABRT during exit-time static destruction. The main thread in both crash reports:
abort
__abort_message
demangling_terminate_handler()
_objc_terminate()
std::terminate()
__cxa_finalize_ranges
exit
-[NSApplication terminate:]
No app frames are involved. Apart from the app binary, the only non-system image loaded in both processes is libonnxruntime.1.22.0.dylib.
Both crash reports come from app sessions in which ONNX Runtime was initialized for embeddings. Sessions without an ORT init have no crash reports. Not every session with ORT crashed: 2 of 6 in my logs did.
Likely cause
This matches pykeio/ort#409. With the official ONNX Runtime 1.22.0 macOS binaries, static destruction at exit can throw mutex lock failed: Invalid argument from the logger while an OrtEnv is still alive. The upstream patch, microsoft/onnxruntime#25134, was closed without merging. The ONNX Runtime maintainer recommends either releasing the environment before main returns or leaking it on newer ONNX Runtime versions.
I could not capture the libc++abi message itself because the GUI app's stderr is not retained, so the exact exception is inferred from the matching stack and the ORT correlation.
To Reproduce
- Start LettuceAI on macOS and trigger an embedding, for example with a dynamic memory chat.
- Quit with Cmd+Q.
- Sometimes a crash report appears in
~/Library/Logs/DiagnosticReports.
Expected behavior
The app quits without a crash report.
Possible fixes
- Drop the cached embedding session and release the ORT environment on
RunEvent::Exitbefore the process exits. - Move to an ONNX Runtime version where the environment can be leaked safely, as suggested upstream.
Environment
- LettuceAI 2.2.5 desktop, macos-arm64.
- macOS 27.2, Apple Silicon.
- ONNX Runtime 1.22.0, the copy the app downloads at runtime.