Skip to content

fix(onlion): only the big wasm is deferred; callbacks.wasm stays a module - #138

Merged
wefio merged 2 commits into
mainfrom
fix/callbacks-wasm-eager
Oct 30, 2026
Merged

wefio merged 2 commits into
mainfrom
fix/callbacks-wasm-eager

Conversation

@wefio

@wefio wefio commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Doc owner: docs/decisions/implemented/2026-10-30-defer-wasm-load.{md,zh-CN.md} (corrected in this PR).

Live defect from f86d384, caught on the deployed endpoint: the inline-wasm plugin matched every *.wasm, so callbacks.wasm also became a factory. The generated loader imports it as a real WebAssembly.Module, so new WebAssembly.Instance(callbacksModule, ...) threw Argument 0 must be a WebAssembly.Module inside runSQLite3PostLoadInit — every /search that needed SQLite answered 503 in 75-150 ms, while /add kept succeeding because the accept never touches SQLite.

Fix: callbacks.wasm (19 KB) stays eager; sqlite3.wasm (1.5 MB, the actual cold-start cost) stays lazy.

Not verified

The suite did not catch it: Miniflare runs the wrangler build, which never executes this plugin. npm run test:edgeone drives the built bundle with a real COS bucket and does load SQLite, so it covers this class — it reports 13/14 with a /capacity expectation that predates the log-mode default (a fresh user has no manifest until a fold), which is a separate test defect.

wefio added 2 commits October 30, 2026 19:08
…dule

f86d384 shipped a defect: the inline-wasm plugin matched every *.wasm, so
callbacks.wasm became a factory function too. The generated loader imports it as
a real WebAssembly.Module and does `new WebAssembly.Instance(callbacksModule,
...)`, which threw "Argument 0 must be a WebAssembly.Module" inside
runSQLite3PostLoadInit - every /search that needed SQLite answered 503 in
75-150 ms, while /add kept succeeding (the accept never touches SQLite).

callbacks.wasm (19 KB) is back to an eager module; sqlite3.wasm (the 1.5 MB one,
the actual cold-start cost) stays behind the lazy factory.

Caught on the deployed endpoint, not by the suite: Miniflare exercises the
wrangler build, which never runs this plugin. `npm run test:edgeone` does drive
the built bundle and does load SQLite, so it covers this class.
…ead, and stops retrying OPFS

Two behaviour-preserving transforms, both measured:

1. search loaded SQLite before reading anything (worker.mjs, `sqliteReady()` in
   search). A user whose writes are still in the log has no partitions at all -
   the harness's first questions are exactly that - so the module was decoded and
   compiled for nothing. `readSearchCandidates` now takes a memoised
   `getSqlite` and resolves it inside the partition loop. Verified: a search on
   an unknown user returns 200 in 19 ms with `sqlite_loaded: false`.

2. every SQLite load tried to install the OPFS VFS twice and threw twice
   (no `location` in this runtime), printing two stack traces per cold start.
   The loader gates those installers on `config.disable.vfs`, whose source is
   `globalThis.sqlite3ApiConfig` (worker-loader.mjs 3064, gates at 15699 and
   16964) - not init()'s argument, which is why passing it there changed
   nothing. Verified: the two stacks per load went from 2 to 0 in a full verify
   run (22 occurrences before, 0 after).

Full suite 37 PASS.
@wefio
wefio merged commit 8d08df7 into main Oct 30, 2026
8 checks passed
@wefio
wefio deleted the fix/callbacks-wasm-eager branch October 30, 2026 11:17
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.

1 participant