fix(activation): repair reranker WASM load under Bun source/dev runs - #86
Merged
Merged
Conversation
The reranker set ort.env.wasm.wasmPaths.mjs to the path string returned by
Bun's `with { type: "file" }` import attribute. onnxruntime-web's WASM
loader then does `await import(mjsPath).default` internally, but Bun's
module cache for that path already holds the path string (from the
type: "file" attribute), so the dynamic import returns { default: "<path>" }
instead of the ortWasmThreaded factory — producing:
TypeError: c is not a function. (In 'c(m)', 'c' is
".../ort-wasm-simd-threaded.asyncify.mjs")
In `bun build --compile` single-file binaries the // virtual path
imports correctly, so the bug only affected source/dev runs (every
non-binary install).
Append a cache-busting `?import` query suffix to real filesystem paths so
Bun treats the dynamic import() as a fresh ESM load returning the actual
factory; leave // paths untouched. Verified: model loads in 0.3s,
reranking active.
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.
Problem
On every source/dev startup (
bun run src/index.ts), the reranker fails to load:Reranking silently falls back to dense-only ordering, so precision degrades with no visible cause. The previous fix (ce4552c) made the reranker work in
bun build --compilebinaries but introduced this regression for non-binary installs.Root cause
src/activation/rerank.tsimports the ORT WASM runtime MJS via Bun'swith { type: "file" }import attribute, which yields the file path string:This path is then handed to ORT:
onnxruntime-web's WASM loader resolves
wasmPaths.mjsby doingawait import(mjsPath).defaultinternally. But Bun's module cache for that path already holds the path string (from thetype: "file"attribute), so the dynamicimport()returns{ default: "<path string>" }instead of theortWasmThreadedfactory function — hencec is not a function(wherecis the cached path string).In
bun build --compilesingle-file binaries the/$bunfs/virtual path imports correctly, so the bug only manifests in source/dev runs (every non-binary install).Fix
Append a cache-busting
?importquery suffix to real filesystem paths so Bun treats the dynamicimport()as a fresh ESM load returning the actualortWasmThreadedfactory./$bunfs/virtual paths (compiled binaries) already work and are left untouched:Verification
Before:
After:
typecheckclean; lint unchanged (only pre-existing warnings on unrelated lines). Fail-open behavior is preserved — any load failure still falls back to dense-only ordering.