Skip to content

fix(embeddings): guard against macOS onnxruntime mutex crash (#68) - #147

Open
PatrickSys wants to merge 1 commit into
masterfrom
cursor/mac-mutex-onnx-fix-6395
Open

PatrickSys wants to merge 1 commit into
masterfrom
cursor/mac-mutex-onnx-fix-6395

Conversation

@PatrickSys

Copy link
Copy Markdown
Owner

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

  • Add top-level npm overrides so npx/npm installs pin onnxruntime-node@1.24.3 (pnpm override already existed).
  • Assert onnxruntime-node >= 1.24.0 before Transformers.js embedding and reranker initialization, with an actionable error when an older runtime is present.
  • Add regression tests for peer dependency policy, override pins, lockfile resolution, and runtime version checks.

Verification

  • pnpm run type-check
  • pnpm test (1308 passed)
Open in Web Open in Cursor 

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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T22:31:02.137565Z 7b823d2 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread package.json
"vitest": "^4.0.18"
},
"overrides": {
"@huggingface/transformers>onnxruntime-node": "1.24.3"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[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.

Findings

  1. P1 npm installs fail ▶
  2. P2 Tests miss a disabled guard ▶
  3. P2 OpenAI workaround still triggers reranking ▶

Summary

Adds a minimum onnxruntime-node version check before local embeddings and reranking.

  • Local embedding and reranking check the ONNX runtime before setup.

Reviews (1) · Last reviewed commit: "fix(embeddings): guard against macOS onn..." · Reviewed by Greptile

Comment thread package.json
"vitest": "^4.0.18"
},
"overrides": {
"@huggingface/transformers>onnxruntime-node": "1.24.3"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 npm installs fail

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.

Comment on lines +44 to +45
it('accepts onnxruntime-node 1.24.x when installed with Transformers.js', () => {
expect(() => assertMinimumOnnxRuntimeNodeVersion()).not.toThrow();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests miss a disabled guard

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.`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Suggested change
`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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: Mutex Lock Failed During Indexing on Intel Mac

2 participants