Repository navigation
fix(cli): stub onnxruntime-node and sharp out of the Node bundle (#1615) - #1617
Merged
Merged
Conversation
|
Warning Review limit reachedYou'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. View limit details
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. |
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. |
This was referenced Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1615.
The Node bundle crashed at initialisation on every command:
embeddings.tsstatically importsembeddings-native, whose lazyawait import("onnxruntime-node")is flattened into the startup graph byinlineDynamicImports, and onnxruntime-node's inlined loader dynamically requires its platform.nodebinding, 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 existingfffNodePluginprecedent for ffi-rs:nativeStubPluginresolvesonnxruntime-nodeandsharpto 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 — thecreateRequireloader insrc/backends/onnx-node.js, and the singlerequireFromHere("onnxruntime-node")call in the publisheddist/transformers.node.mjs(with a turndown-style build error if the rewrite stops matching).nativeStubGraphPluginis the fast guard: atgenerateBundleit 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.embeddings-native.tspackaging 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-installcompletes, including build-node's own--version/--helpruns; independently:node dist-node/opencode.mjs --versionexits 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).nativeStubPlugintemporarily disabled, the build fails at generateBundle naming the leaked onnxruntime-node + sharp module paths (BUILD_EXIT=1); restored afterwards.packages/coreembeddings tests —embeddings.test.ts14/14 pass; the 4 native-backend tests inembeddings-native.test.tsfail 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.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.