macOS: ONNX Runtime dylib check never matches otool output, so the runtime is re-downloaded on every init
Describe the bug
On macOS, macos_dylib_is_loadable in src-tauri/src/embedding/ort_runtime.rs runs otool -hV and checks the output for MH_DYLIB. otool -hV prints the file type as DYLIB:
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
MH_MAGIC_64 ARM64 ALL 0x00 DYLIB 28 3440 NOUNDEFS DYLDLINK TWOLEVEL BINDS_TO_WEAK NO_REEXPORTED_DYLIBS MH_HAS_TLV_DESCRIPTORS
As a result, is_valid_macos_ort_dylib rejects every valid library whenever otool is available, which is the case on any machine with the Xcode Command Line Tools. Without otool the check returns true, so the bug only shows up on machines that have the tools.
Consequences:
- The bundled
Contents/Resources/onnxruntime/libonnxruntime.1.22.0.dylib, a valid arm64 dylib, is rejected withORT_DYLIB_PATH points to ... but it is not a usable macOS MH_DYLIB for this arch; ignoring it. - The cached copy in
<app data>/lettuce/onnxruntime/fails the same check on the next init, so it is deleted and the ~26 MB archive is downloaded again. On my machine the cached files carry the timestamp of the latest ORT init, not of the first download. - A user-supplied
ORT_DYLIB_PATHis ignored for the same reason.
To Reproduce
- Install the Xcode Command Line Tools on macOS.
- Start LettuceAI and trigger an embedding, for example with a dynamic memory chat.
- See the warning above in the log and the files in
lettuce/onnxruntime/rewritten on each launch that initializes ORT.
Expected behavior
A valid dylib for the current architecture is accepted, the bundled runtime is used, and the cached runtime is not downloaded again.
Proposed fix
Match the file type column instead of the MH_DYLIB string, for example by accepting a whitespace-separated DYLIB token. I can open a pull request.
Environment
- LettuceAI 2.2.5 desktop, macos-arm64. The check is unchanged on
mainat b9d1728. - macOS 27.2, Apple Silicon, Command Line Tools installed.