[issue-217] Precache libdedx WASM + ASR worker after model download; offline SW cache fallback - #218
Open
grzanka wants to merge 2 commits into
Open
[issue-217] Precache libdedx WASM + ASR worker after model download; offline SW cache fallback#218grzanka wants to merge 2 commits into
grzanka wants to merge 2 commits into
Conversation
…offline SW cache fallback Fixes the offline claim failing on first use (#217, verifying/refining #163 §5.4): `wasm/libdedx.mjs` and the ASR worker script are both dynamic-loaded lazily on first query, so the "download models" consent flow never fetched (or cached) either one — a user who went straight offline after finishing that flow hit an uncached dynamic import/Worker fetch and failed, even though they'd just been told they were ready. - `asr-status.svelte.ts`: add `prewarm()`, a fire-and-forget call that triggers the ASR worker's pipeline load via the same singleton worker client `start()` uses, so a later real transcription reuses it instead of spinning up a second worker. - `model-status.svelte.ts`: after `downloadModelWeights()` succeeds, await `getService()` (libdedx WASM) and call `asrStatus.prewarm()` before flipping to "ready". Both failures are logged, not fatal — the model weights are already safely cached at that point, so a WASM/ASR hiccup here shouldn't revert the whole flow to "fresh". - `static/coi-serviceworker.js`: give the vendored fetch handler a Cache Storage fallback. Successful same-origin GET responses it proxies are written into a new `aidedx-coi-runtime-v1` bucket; a failed live fetch (offline) now checks Cache Storage (every bucket, so it also picks up transformers.js's own "transformers-cache" entries for ONNX Runtime Web's wasm/mjs) before re-throwing. Kept same-origin-only so it never duplicates the multi-hundred-MB cross-origin model weight downloads. Test plan: - [x] pnpm run format:check (scoped to changed files — repo-wide run trips on pre-existing untracked `.android-asr-cache/`/`.venv-asr-bench/` directories unrelated to this change) - [x] pnpm run lint (scoped to changed files, same pre-existing caveat) - [x] pnpm run check - [x] pnpm run validate:eval - [x] pnpm test (982 passed, incl. new precache/prewarm coverage) - [x] pnpm build Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #217 by making the “download models” consent flow actually prepare the app for offline first use: it proactively loads the libdedx WASM compute path and warms the ASR worker, and it enhances the COI service worker to persist and serve cached responses when live fetches fail.
Changes:
- Add a runtime Cache Storage bucket + offline fallback behavior to
coi-serviceworker.jsfor proxied fetches. - After
downloadModelWeights()succeeds, precache libdedx (getService()) and prewarm ASR (asrStatus.prewarm()) before marking the model state as"ready"(non-fatal on failure). - Add Vitest coverage for the new post-download precache behavior and the ASR
prewarm()path.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| static/coi-serviceworker.js | Adds runtime caching for successful GETs and a cache fallback on fetch failure to improve offline resilience. |
| src/lib/models/model-status.svelte.ts | Preloads compute WASM and warms ASR right after a successful model download to support offline-first-use. |
| src/lib/models/model-status.test.ts | Tests that post-download precaching occurs and that precache failures remain non-fatal. |
| src/lib/asr/asr-status.svelte.ts | Adds prewarm() to trigger worker pipeline load without changing ASR phase/recording state. |
| src/lib/asr/asr-status.test.ts | Tests prewarm() behavior and verifies the warmed worker client is reused by start()/stop(). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…T, not just same-origin Addresses Copilot review feedback on #218: the read-side fallback in coi-serviceworker.js's catch block was gated by the same isCacheableGet flag as the write side, so it only ever ran for same-origin GETs. That meant a cross-origin GET (the Cyfronet S3 model-weight mirror in particular) could never fall back to Cache Storage on a failed live fetch, even though transformers.js's own "transformers-cache" bucket might already hold a cached response for it — contradicting both the inline comment and the PR description's "search every bucket" claim. Split the single flag into `isSameOriginGet` (still gates the cache *write*, so this SW never duplicates the multi-hundred-MB cross-origin weight downloads into a second bucket) and `isGet` (gates the *read* fallback, any origin). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
What changed
Fixes #217 (verifying/refining #163 §5.4): the "download models" consent
flow never touched
wasm/libdedx.mjsor the ASR worker script — both aredynamic-loaded lazily, only on a query's first use — so a user who went
offline right after finishing that flow hit an uncached fetch and failed,
even though they'd just been told they were ready.
Implements both parts of the issue's suggested fix:
Precache the compute/ASR code paths as part of the download flow.
model-status.svelte.ts'sstartDownload()now awaitsgetService()(libdedx WASM) and calls a new
asrStatus.prewarm()(fire-and-forget,reuses the same singleton worker client
start()later uses) rightafter
downloadModelWeights()succeeds, before flipping to"ready".Failures from either are logged only, never fatal — the model weights
are already safely cached at that point, so a WASM/ASR hiccup shouldn't
revert the whole flow to
"fresh"and force a re-download.Give
coi-serviceworker.js's fetch handler acaches.match()fallback. Every successful same-origin GET response it proxies is now
also written into a new
aidedx-coi-runtime-v1Cache Storage bucket. Ona failed live fetch (offline), it now checks Cache Storage — every
bucket, so it also benefits from transformers.js's own
"transformers-cache"entries for ONNX Runtime Web's wasm/mjs — beforere-throwing. Kept same-origin-only so it never duplicates the
multi-hundred-MB cross-origin model weight downloads (Cyfronet S3
mirror) into a second cache.
Test plan
pnpm run format:check— scoped to the changed files; a repo-widerun trips on pre-existing untracked
.android-asr-cache/and.venv-asr-bench/directories unrelated to this change (confirmedthe same failure exists on
main)pnpm run lint— scoped to the changed files, same pre-existingcaveat
pnpm run check— 0 errorspnpm run validate:evalpnpm test— 982 passed, including new coverage forasrStatus.prewarm()andmodelStatus's post-download precache(success path + both failure paths staying non-fatal)
pnpm buildmodels → disconnect networking → no prior online query → submit a
query) — not done as part of this PR; see [issue-163] §5.4: offline claim fails on first use — libdedx WASM + ASR worker never precached #217's own repro steps
🤖 Generated with Claude Code