Repository navigation
Stop SAM from timing out while its files are still downloading - #7800
Open
jpggvilaca wants to merge 9 commits into
Open
jpggvilaca wants to merge 9 commits into
jpggvilaca wants to merge 9 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical and moderate findings affect SAM worker recovery and asset loading.
2 open issues
What changed in this PR
This PR addresses SAM startup timeouts by prefetching dependencies before worker setup and keeping annotator workers alive across navigation.
Changes:
- Adds SAM asset prefetching, caching, stall detection, and lifecycle APIs.
- Adjusts worker timeouts, retries, and decode error handling.
- Removes route-level worker termination and updates related documentation.
| File | Reviewed change |
|---|---|
application/ui/src/router.tsx |
Removes route-level worker cleanup. Critical: retain recovery for failed decoder calls. |
application/ui/src/modules/annotator/webworkers/segment-anything.worker.ts |
Exposes asset lifecycle methods. |
application/ui/src/modules/annotator/webworkers/segment-anything.worker.interface.ts |
Extends the worker API. |
application/ui/src/modules/annotator/webworkers/segment-anything-assets.ts |
Prefetches and caches SAM assets. Moderate: prefetch the matching ONNX Runtime .mjs glue. |
application/ui/src/modules/annotator/webworkers/segment-anything-assets.test.ts |
Tests asset caching and stalled downloads. |
application/ui/src/modules/annotator/webworkers/opencv-source.ts |
Exports the OpenCV asset path. |
application/ui/src/modules/annotator/tools/terminate-annotator-workers-on-unmount.hook.ts |
Removes obsolete worker termination. |
application/ui/src/modules/annotator/tools/ssim-tool/use-ssim.hook.ts |
Updates worker lifetime documentation. |
application/ui/src/modules/annotator/tools/segment-anything-tool/use-segment-anything.hook.ts |
Prefetches assets and adjusts retries/timeouts. Moderate: retain prefetched assets through worker recovery. |
application/ui/src/modules/annotator/tools/segment-anything-tool/segment-anything-tool.component.tsx |
Reports decoding failures. |
application/ui/src/modules/annotator/tools/segment-anything-tool/sam-timeouts.ts |
Updates browser timeout constants. |
application/ui/src/modules/annotator/tools/segment-anything-tool/sam-timeouts.tauri.ts |
Updates Tauri timeout constants. |
application/ui/src/modules/annotator/tools/hooks/use-intelligent-scissors-worker.hook.ts |
Updates worker lifetime documentation. |
Review effort: Lite
🐳 Docker image sizes
|
📊 Test coverage report
|
jpggvilaca
force-pushed
the
jvilaca/sam-timeouts
branch
3 times, most recently
from
October 26, 2026 13:42
fcae375 to
b11a9ce
Compare
⏱️ Backend import time —
|
| Accelerator | Cumulative (s) | Self (s) |
|---|---|---|
cpu |
5.768 | 0.003 |
xpu |
5.832 | 0.003 |
cuda |
5.399 | 0.003 |
Contributor
|
PR needs a rebase if still applicable |
jpggvilaca
force-pushed
the
jvilaca/sam-timeouts
branch
from
November 9, 2026 09:01
1a6170c to
911c7e2
Compare
jpggvilaca
force-pushed
the
jvilaca/sam-timeouts
branch
from
November 9, 2026 10:43
7948e4a to
f4f2620
Compare
This branch has not been deployed
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.


Summary
SAM kept failing with "SAM worker build timed out after 10000ms" or "SAM worker init timed out after 20000ms", in the browser and in the desktop app. Sometimes it worked after a few tries, then broke again after creating a new project.
Before SAM can run, the browser downloads ~45 MB: OpenCV (2.4 MB), the ONNX Runtime wasm (27 MB) and the SAM decoder (16.5 MB). That download ran inside the same 10 s / 20 s limits meant to catch a frozen worker, so on a slow connection it timed out no matter what else we fixed.
Changes:
immutable; everything else (index.html,opencv/*,ort/*) isno-cachewith ETag revalidation. Previously the non-fingerprinted files were cached for a year, so browsers served stale copies after an upgrade.Notes:
How to test
How to test
Checklist