Skip to content

Stop SAM from timing out while its files are still downloading - #7800

Open
jpggvilaca wants to merge 9 commits into
developfrom
jvilaca/sam-timeouts
Open

jpggvilaca wants to merge 9 commits into
developfrom
jvilaca/sam-timeouts

Conversation

@jpggvilaca

@jpggvilaca jpggvilaca commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Download first, then build. The worker downloads the assets into the browser cache before building. A download only fails if no data arrives for 30 s, so slow connections are fine. Build/init timeouts now only measure setup (build 10 → 30 s, init 20 → 60 s) and worker startup retries twice.
  • Recover from a stuck decoder. If a decode times out, the worker is terminated and recreated instead of staying broken.
  • Surface decode errors. Failed decodes show a toast instead of failing silently.
  • Keep workers alive. Smart-tool workers (SAM/SSIM/scissors) are no longer terminated when leaving the dataset section. Re-entering the annotator is instant, at the cost of ~100 MB of WASM memory kept for the life of the window.
  • Backend: cache headers. Fingerprinted assets are cached as immutable; everything else (index.html, opencv/*, ort/*) is no-cache with ETag revalidation. Previously the non-fingerprinted files were cached for a year, so browsers served stale copies after an upgrade.

Notes:

  • Desktop (Tauri) bundles these assets locally, so the prefetch is cheap there; desktop mainly benefits from the timeout, restart and toast changes.
  • Chromium does not store responses from an origin with certificate errors in its HTTP cache, so on web installs using the default self-signed certificate the assets are downloaded twice (once by the prefetch, once by ORT/OpenCV). Works as intended over HTTP or with a trusted certificate.

How to test

  1. Throttle the network in DevTools (e.g. "Slow 4G"), open the annotator and select SAM: it should load without a timeout error.
  2. Leave the dataset section and come back: SAM should be ready immediately.
  3. Desktop app: SAM loads and works on first use.

How to test

Checklist

  • The PR title and description are clear and descriptive
  • I have manually tested the changes
  • All changes are covered by automated tests
  • All related issues are linked to this PR (if applicable)
  • Documentation has been updated (if applicable)

@jpggvilaca
jpggvilaca requested a review from a team as a code owner October 19, 2026 12:12
Copilot AI lite review requested due to automatic review settings October 19, 2026 12:12
@jpggvilaca jpggvilaca changed the title stop SAM from timing out while its files are still downloading Stop SAM from timing out while its files are still downloading Oct 19, 2026
@github-actions github-actions Bot added the Geti UI Issues related to Geti application frontend label Oct 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread application/ui/src/router.tsx Resolved
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🐳 Docker image sizes

Device Size
xpu 10668.9 MB (10.42 GB)
cuda 8391.1 MB (8.19 GB)
cpu 4018.6 MB (3.92 GB)

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

📊 Test coverage report

Metric Coverage
Lines 77.2%
Functions 75.3%
Branches 67.3%
Statements 77.0%

@jpggvilaca
jpggvilaca force-pushed the jvilaca/sam-timeouts branch 3 times, most recently from fcae375 to b11a9ce Compare October 26, 2026 13:42
@jpggvilaca
jpggvilaca requested a review from a team as a code owner October 26, 2026 14:46
@github-actions github-actions Bot added TEST Any changes in tests Geti Backend Issues related to the Geti application server labels Oct 26, 2026
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

⏱️ Backend import time — app.main

Accelerator Cumulative (s) Self (s)
cpu 5.768 0.003
xpu 5.832 0.003
cuda 5.399 0.003

@leoll2

leoll2 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

PR needs a rebase if still applicable

@jpggvilaca
jpggvilaca force-pushed the jvilaca/sam-timeouts branch from 1a6170c to 911c7e2 Compare November 9, 2026 09:01
@jpggvilaca
jpggvilaca force-pushed the jvilaca/sam-timeouts branch from 7948e4a to f4f2620 Compare November 9, 2026 10:43

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Geti Backend Issues related to the Geti application server Geti UI Issues related to Geti application frontend TEST Any changes in tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants