Skip to content

fix: Retry and time out boot downloads - #1095

Merged
MartinZikmund merged 10 commits into
mainfrom
dev/mazi/resilient-loading
Oct 8, 2026
Merged

MartinZikmund merged 10 commits into
mainfrom
dev/mazi/resilient-loading

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #1091

What changed

On an unstable connection, one failed download out of the ~100–200 at startup broke the app. The .NET loader retries only when a request fails before the response headers arrive; a connection reset mid-body failed startup, and nothing timed out, so a stalled response hung it forever.

  • Downloads (ResourceLoader.ts) go through the runtime's withResourceLoader hook. Each one gets a headers timeout (20 s) and an idle watchdog (8 s without bytes). Failures (network errors, mid-body resets, 5xx/408/429, stalls) are retried with jittered exponential backoff, up to 8 attempts, and wait for online while the browser reports offline. Subresource integrity is checked after the download, since fetch({ integrity }) exposes no bytes until the body is complete, which would hide a stall.
  • dotnet.native.wasm: after the verified download, the runtime gets a force-cache response for the same URL. The browser only reuses compiled WebAssembly (its code cache) for a fetched response, not one built from a buffer. Hosts sending no-store keep the buffered copy.
  • The runtime's own JS modules (dotnet.runtime, dotnet.native) are imported in onConfigLoaded, which the runtime awaits, so its later import() resolves from the module map. A failed import stays in the module map, so retries use ?r=N, and loadBootResource hands the runtime the URL that worked. blob: URLs don't work, because emscripten resolves paths against import.meta.url. A stalled import() can't be aborted, so it's abandoned after the headers timeout.
  • uno-config.js, dotnet.js, and the require.js dependencies, including AppManifest.js, are retried the same way.
  • DOMContentLoaded: the bootstrapper only called preInit() from a listener for it. When uno-bootstrap.js was imported after the document was parsed, the loader was never set up, and the first progress report threw Cannot set properties of undefined (setting 'max').
  • Timeouts and attempts can be overridden with UNO_BOOTSTRAP_FETCH_HEADERS_TIMEOUT_MS, _IDLE_TIMEOUT_MS and _MAX_ATTEMPTS. Docs: new "Resilient loading" page.

Not covered: the files index.html references directly (require.js, uno-bootstrap.js, stylesheets) are loaded by the browser. #1097 makes the stylesheets non-blocking.

Validation

New Uno.Wasm.Tests.ResilientLoading (CI, linux): a server fails the first request of every boot resource, rotating through a reset mid-body, a stall and a 503, and also serves late.html, which imports uno-bootstrap.js after load. The RayTracer must start on both.

  • Before: the first fault (uno-config.js) fails startup; late.html never starts.
  • After: both start, with 21 faults injected; stalls account for most of the ~38 s.

On a Uno 7.0 template app, through a test server simulating 4G with injected faults (cold loads, all PRs of this series combined):

Faults Before After
One network handover (every connection drops once) 5/6 6/6
2% resets mid-body, 1% dropped connections, 1% 503 1/6 6/6
2% of responses stall after the headers 0/6 6/6
~9% of requests failing (this PR alone) — 8/10

Cold load speed without faults is unchanged (10.70 s vs 10.70 s median, n=5). The remaining failures under the harshest profile come from fetches made later by the app itself (Uno's uno-assets.txt manifest), which unoplatform/uno needs to make resilient as well.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N5azy6DU7ujLte16VPVYQs

Copilot AI balanced review requested due to automatic review settings October 1, 2026 11:42
@MartinZikmund MartinZikmund self-assigned this Oct 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Retry exhaustion and cache misses can still hang startup, compatibility and initialization defects remain, and the test server permits path traversal.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Adds resilient startup loading to address issue #1091.

Changes:

  • Adds retry, timeout, integrity, and module-preloading logic.
  • Adds fault-injection browser testing and CI coverage.
  • Documents resilient-loading configuration.
File Description
ResourceLoader.ts Implements resilient resource loading.
Bootstrapper.ts Integrates retries and late initialization.
fault-server.js Injects transient network faults.
app.js Runs browser startup scenarios.
run-test.sh Orchestrates the resilience test.
package.json Defines test dependencies.
package-lock.json Locks test dependencies.
features-resilient-loading.md Documents behavior and configuration.
toc.yml Adds the documentation page.
stage-build-linux-tests.yml Runs the test in CI.
Files not reviewed (1)
  • src/Uno.Wasm.Tests.ResilientLoading/package-lock.json: Generated file

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 05:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Resource compatibility, integrity enforcement, terminal error propagation, and an unguarded WebAssembly refetch remain unresolved.

Review effort: Balanced
Findings: 3 High severity

Open (3)
Resolved since last review (3)
Files not reviewed (1)
  • src/Uno.Wasm.Tests.ResilientLoading/package-lock.json: Generated file
Previously missed (2)

In code that hasn't changed since last review

Medium severity Extract fingerprinted filenames from object-form manifests

src/​Uno.Wasm.Bootstrap/​ts/​Uno/​WebAssembly/​Bootstrapper.ts:417

Object-form resource manifests can store the fingerprinted filename in each value's name field. Returning only the keys here preloads a logical/nonexistent URL and can exhaust all retries before startup on that supported manifest format. Match the extraction already used in Embedded/service-worker.js:108-120.

Medium severity Fail when module-script replacement does not occur

src/​Uno.Wasm.Tests.ResilientLoading/​fault-server.js:36

If the published index.html markup changes so this regex no longer matches, replace() returns the original page and /late.html becomes a normal startup. The late-import test then passes without exercising the DOMContentLoaded regression. Fail explicitly when no module-script replacement was made.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 14:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Legacy manifests, terminal RequireJS failures, unbounded cache refetches, and WebWorker coverage remain unresolved.

Review effort: Balanced
Findings: 4 High severity

Open (4)
Files not reviewed (1)
  • src/Uno.Wasm.Tests.ResilientLoading/package-lock.json: Generated file
Previously missed (1)

In code that hasn't changed since last review

Medium severity Apply resilient loading to the WebWorker bootstrapper

doc/​features-resilient-loading.md:11

This coverage claim excludes the supported WebWorker mode without saying so. WorkerBootstrapper.ts still fetches uno-config.js, imports dotnet.js, and configures the runtime without withResourceLoader, so worker startup retains the original no-retry/no-timeout failure modes. Integrate the resilient loader into the separately compiled worker bootstrapper, or document WebWorker mode as an explicit limitation.

@mergify

mergify Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

MartinZikmund and others added 9 commits October 8, 2026 10:21
The bootstrapper only ran preInit() from a DOMContentLoaded listener. When
uno-bootstrap.js is imported after the document was parsed, the event never
fires, the progress element is never set up, and the first progress report
throws "Cannot set properties of undefined (setting 'max')".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01N5azy6DU7ujLte16VPVYQs
The .NET loader retries a download only when it fails before the response
headers arrive, and nothing has a timeout. On an unstable connection, a
connection reset mid-body fails startup, and a response that stops sending
bytes hangs it forever. The runtime's own JS module imports, uno-config.js,
dotnet.js and the require.js dependencies had no retry at all.

Route the runtime's resources through withResourceLoader with a headers
timeout, an idle watchdog and a jittered exponential backoff that waits for
the browser to be back online. SRI is verified after the download, since
fetch({ integrity }) exposes no bytes until the body is complete. Module
imports are retried with a distinct URL, as a failed import stays in the
module map, and time out since import() can't be aborted. The runtime's JS
modules are imported in onConfigLoaded, which the runtime awaits, and
loadBootResource hands it the URL that succeeded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01N5azy6DU7ujLte16VPVYQs
fault-server.js fails the first request of each boot resource with a reset
mid-body, a stall or a 503, and serves late.html, which imports
uno-bootstrap.js after the load event. The RayTracer must start on both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01N5azy6DU7ujLte16VPVYQs
The resilient download builds a Response from a buffer, which the browser
can't match to its WebAssembly code cache. Once downloaded and verified, the
file is in the HTTP cache: fetch it again from there (force-cache) and hand
that response to the runtime. Hosts that send no-store keep the buffered
copy.

Measured on a Uno 7.0 app, simulated 4G, warm reload (median, n=5): 3.37 s,
against 3.22 s when the runtime fetches dotnet.native.wasm itself (without
retries) and 3.53 s for the shipped bootstrapper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01N5azy6DU7ujLte16VPVYQs
uno-config.js moved next to index.html, out of the package folder, so
the fault server stopped failing it and the config retry went untested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ADrzrqtw3RQdHan77rypBM
Copilot AI balanced review requested due to automatic review settings October 8, 2026 08:22
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/resilient-loading branch from 244fa6d to 97193d2 Compare October 8, 2026 08:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

- Look dotnet.native.wasm up in the HTTP cache with only-if-cached, so the
  lookup can't go back to the network and stall.
- Report a dependency's final failure through requirejs.onError instead of
  only logging it.
- Let the browser verify integrity where crypto.subtle is unavailable,
  instead of skipping the check.
- Read the fingerprinted name of object-shaped runtime module entries.
- Spell out the full environment variable names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ADrzrqtw3RQdHan77rypBM
Copilot AI balanced review requested due to automatic review settings October 8, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

Startup fails or hangs on unstable connections

3 participants