Skip to content

fix(cli): stub onnxruntime-node and sharp out of the Node bundle (#1615) - #1617

Merged
dezren39 merged 1 commit into
mainfrom
queue/9407-1615-onnx-stub
Nov 4, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/9407-1615-onnx-stub

Conversation

@dezren39

@dezren39 dezren39 commented Nov 4, 2026 •

Copy link
Copy Markdown

Fixes #1615.

The Node bundle crashed at initialisation on every command: embeddings.ts statically imports embeddings-native, whose lazy await import("onnxruntime-node") is flattened into the startup graph by inlineDynamicImports, and onnxruntime-node's inlined loader dynamically requires its platform .node binding, which @rollup/plugin-commonjs cannot resolve.

Mechanism (Route B from triage task 9380 — behaviour-preserving today). In packages/cli/vite.node.config.ts, following the existing fffNodePlugin precedent for ffi-rs:

  • nativeStubPlugin resolves onnxruntime-node and sharp to stubs for the Node bundle only: module load succeeds; any actual use throws a clear "unavailable in the Node bundle" error. It also rewrites @huggingface/transformers' own loaders, which bypass resolveId — the createRequire loader in src/backends/onnx-node.js, and the single requireFromHere("onnxruntime-node") call in the published dist/transformers.node.mjs (with a turndown-style build error if the rewrite stops matching).
  • nativeStubGraphPlugin is the fast guard: at generateBundle it fails the build in seconds if the real onnxruntime-node/sharp packages re-enter the graph or the stub goes missing — instead of the failure surfacing inside the 60–140s serve-handover tests.
  • The embeddings-native.ts packaging note now documents the Node-bundle rule alongside the Nix-closure note, so the next native dependency pulled into core gets the same treatment.

Safe because the native-onnx backend is opt-in per registration (core embeddings.ts: it becomes a backend only by the deliberate #1554 step-3 flip, which has not happened — the only registered model uses the HTTP backend), and the Bun build never sees this config: under Bun the lazy import still resolves the real package from node_modules on first embed call. No registration, pricing, or backend behaviour changes.

Verification (laptop worktree at main 27656e6, builds under the fleet build lock):

  • bun script/build-node.ts --bundle-only --skip-install completes, including build-node's own --version/--help runs; independently: node dist-node/opencode.mjs --version exits 0 and prints the version.
  • bun test test/serve-handover.test.ts (packages/cli): 7 pass, 0 fail — both Node tests pass in ~6s (previously failing at 140938ms / 60098ms).
  • Guard check: with nativeStubPlugin temporarily disabled, the build fails at generateBundle naming the leaked onnxruntime-node + sharp module paths (BUILD_EXIT=1); restored afterwards.
  • Bun path: packages/core embeddings tests — embeddings.test.ts 14/14 pass; the 4 native-backend tests in embeddings-native.test.ts fail identically on pristine main in this environment (they need the local model snapshot/sidecar), pre-existing and untouched by this change (the embeddings-native.ts edit is comment-only).

Queue task 9407 (fix packet from triage task 9380), lane opencode-a.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 09113622-ec99-4fde-bb60-fcbae006ffc0
Commits

Reviewing files that changed from the base of the PR and between d5f6296 and 573903d.

Files selected for processing: 2
  • packages/cli/vite.node.config.ts
  • packages/core/src/embeddings-native.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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-11-04T11:30:35.010099Z 573903d 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.

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.

fix(cli): Node bundle crashes at startup on every command — onnxruntime-node native binding dynamically required inside the Rollup bundle

1 participant