Repository navigation
fix(embeddings): guard against macOS onnxruntime mutex crash (#68) - #147
PatrickSys wants to merge 1 commit into
Conversation
Pin onnxruntime-node 1.24.3 for npm installs, assert a minimum runtime before Transformers.js embedding/rerank work, and add regression tests. Fixes #68
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7b823d2720
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "vitest": "^4.0.18" | ||
| }, | ||
| "overrides": { | ||
| "@huggingface/transformers>onnxruntime-node": "1.24.3" |
There was a problem hiding this comment.
Use npm's nested-object syntax for the runtime override
When this checkout is used as the project root, npm rejects the pnpm-style > selector before resolving dependencies. With npm 11.4.2, both npm install --offline --ignore-scripts --package-lock=false --dry-run and npx --no-install codebase-context memory list fail with Override without name: @huggingface/transformers>onnxruntime-node. This blocks npm installation and local npx usage, contrary to the root AGENTS.md zero-infra requirement. The bundled npm package-json documentation specifies that “Keys can be nested to any arbitrary length”; represent this as an @huggingface/transformers object containing "onnxruntime-node": "1.24.3" instead.
AGENTS.md reference: AGENTS.md:L107-L107
Useful? React with 👍 / 👎.
[Medium impact] The change affects local Transformers.js embedding and search reranking setup. Fix the npm override syntax before merging; it breaks root npm installs. FindingsSummaryAdds a minimum
Reviews (1) · Last reviewed commit: "fix(embeddings): guard against macOS onn..." · Reviewed by Greptile |
| "vitest": "^4.0.18" | ||
| }, | ||
| "overrides": { | ||
| "@huggingface/transformers>onnxruntime-node": "1.24.3" |
There was a problem hiding this comment.
The new overrides key uses pnpm's parent>child syntax, which npm does not accept. Running npm install at the repository root treats this as an invalid package name and fails before installing dependencies. Use npm's nested form: "@huggingface/transformers": { "onnxruntime-node": "1.24.3" }. Keep the existing selector under pnpm.overrides.
| it('accepts onnxruntime-node 1.24.x when installed with Transformers.js', () => { | ||
| expect(() => assertMinimumOnnxRuntimeNodeVersion()).not.toThrow(); |
There was a problem hiding this comment.
The only test that calls assertMinimumOnnxRuntimeNodeVersion checks that it does not throw. It also passes when package lookup fails, because the guard silently returns in that case. None of the tests checks that an installed 1.21.0 is rejected, so a broken lookup or an unconditional return would leave this crash regression suite green. Add controlled fixtures or mocks that test an old runtime, a safe runtime, and a missing package separately.
| throw new Error( | ||
| `onnxruntime-node@${installed} can crash on macOS during embedding (mutex lock failed; see microsoft/onnxruntime#24579). ` + | ||
| `Install @huggingface/transformers@^4.2.0 so onnxruntime-node resolves to >=${minimum}, ` + | ||
| `or set EMBEDDING_PROVIDER=openai to bypass local Transformers.js.` |
There was a problem hiding this comment.
OpenAI workaround still triggers reranking
The shared error recommends EMBEDDING_PROVIDER=openai to bypass local Transformers.js, but ensureModelLoaded also calls this guard for reranking. Search still runs the local reranker with OpenAI embeddings, so following that advice does not avoid this error on that path. Limit the advice to local embeddings, or explain that reranking also needs the runtime upgraded or disabled.
| `or set EMBEDDING_PROVIDER=openai to bypass local Transformers.js.` | |
| `or set EMBEDDING_PROVIDER=openai to bypass local embeddings. Local reranking still requires upgrading onnxruntime-node or disabling reranking.` |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
Fixes #68.
onnxruntime-node@1.21.0(pulled in by Transformers.js v3) has a macOS C++ mutex destructor bug (microsoft/onnxruntime#24579) that hard-crashes during embedding.Changes
overridessonpx/npm installs pinonnxruntime-node@1.24.3(pnpm override already existed).onnxruntime-node >= 1.24.0before Transformers.js embedding and reranker initialization, with an actionable error when an older runtime is present.Verification
pnpm run type-checkpnpm test(1308 passed)