Skip to content

feat: enable asset load retries by default#8744

Merged
mvaligursky merged 1 commit into
mainfrom
mv-default-asset-retries
May 18, 2026
Merged

feat: enable asset load retries by default#8744
mvaligursky merged 1 commit into
mainfrom
mv-default-asset-retries

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

Previously the engine only retried failed asset loads when the integrator explicitly opted in via the maxAssetRetries application property. Any transient network glitch (slow CDN, mobile connectivity hiccup, server flap) would immediately surface as a permanent load failure.

Changes:

  • AppBase now calls this.loader.enableRetry(5) immediately after the built-in resource handlers are registered, so every application gets 5 retries with exponential backoff out of the box.
  • The maxAssetRetries application property continues to override the default when set to a positive number (Editor-driven scenes are unaffected).
  • Promotes ResourceLoader.enableRetry() / ResourceLoader.disableRetry() to public API by removing their @ignore JSDoc tags, giving engine-only users a clean way to configure retries without going through the scene-settings path. The maxRetries parameter on enableRetry is also marked optional in the JSDoc.

Behaviour change:

  • Apps that previously relied on the implicit "fail on first network error" default will now retry up to 5 times with exponential backoff (200ms, 400ms, 800ms, 1600ms, 3200ms, capped at 5000ms).
  • To opt out, call app.loader.disableRetry() after constructing the application, or pass a positive override via the maxAssetRetries application property and a custom value.

API Changes:

  • ResourceLoader.enableRetry(maxRetries?: number): void is now public (was @ignore).
  • ResourceLoader.disableRetry(): void is now public (was @ignore).

Example usage for engine-only projects:

const app = new pc.Application(canvas, { /* ... */ });

// optional - change from the default of 5
app.loader.enableRetry(3);

// or turn retries off entirely
app.loader.disableRetry();

Previously the engine only retried failed asset loads when the
integrator explicitly opted in via the maxAssetRetries application
property. Any transient network glitch would immediately surface as a
permanent load failure.

AppBase now calls loader.enableRetry(5) after registering resource
handlers, so every app gets 5 retries with exponential backoff out of
the box. The maxAssetRetries application property still overrides the
default when set to a positive number.

Also promotes ResourceLoader.enableRetry / disableRetry to public API
(removing @ignore) so engine-only users can configure retries without
going through the scene-settings path.
@mvaligursky mvaligursky self-assigned this May 18, 2026
@mvaligursky mvaligursky requested a review from Copilot May 18, 2026 14:03
@mvaligursky mvaligursky merged commit 5e1549d into main May 18, 2026
10 checks passed
@mvaligursky mvaligursky deleted the mv-default-asset-retries branch May 18, 2026 14:05

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.

Pull request overview

Enables asset load retries by default to improve resilience against transient network failures, and exposes retry controls (enableRetry / disableRetry) as public API on ResourceLoader.

Changes:

  • Default asset load retries are enabled for all new applications (configured in AppBase).
  • maxAssetRetries application property continues to override retry behavior when set.
  • ResourceLoader.enableRetry() / disableRetry() are promoted to public API by removing @ignore and updating JSDoc.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/framework/handlers/loader.js Updates JSDoc and exposes retry configuration methods as public API.
src/framework/app-base.js Enables retries by default during app init and keeps maxAssetRetries override logic.
Comments suppressed due to low confidence (3)

src/framework/app-base.js:806

  • With retries now enabled by default in the constructor, this override logic no longer allows configs to explicitly disable retries via maxAssetRetries: 0. If maxAssetRetries is present and set to 0, the app will still retry 5 times. Consider treating any numeric value as an override (e.g., call enableRetry(props.maxAssetRetries) when it’s a number, or explicitly call disableRetry() when it’s 0) to preserve an opt-out path via application properties.
        // configure retrying assets - overrides the default set in the constructor
        if (typeof props.maxAssetRetries === 'number' && props.maxAssetRetries > 0) {
            this.loader.enableRetry(props.maxAssetRetries);
        }

src/framework/handlers/loader.js:344

  • Now that enableRetry is part of the public API, it would help to normalize maxRetries to an integer (e.g., via Math.floor) after clamping. Passing a non-integer today results in a non-obvious number of attempts because Http compares an integer retry counter against this value.
    enableRetry(maxRetries = 5) {
        maxRetries = Math.max(0, maxRetries) || 0;

src/framework/app-base.js:633

  • This changes the default network behavior for all apps (retries enabled by default). Consider adding a unit test that asserts a newly constructed Application/AppBase has non-zero maxRetries on its handlers, and that _parseApplicationProperties correctly overrides (including disabling when configured).
        // default to retrying failed asset loads to make apps more resilient to transient network
        // errors
        this.loader.enableRetry(5);


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/framework/app-base.js

// default to retrying failed asset loads to make apps more resilient to transient network
// errors
this.loader.enableRetry(5);
mvaligursky added a commit to playcanvas/developer-site that referenced this pull request May 18, 2026
Documents the engine's asset load retry behaviour, which now defaults
to 5 retries with exponential backoff (playcanvas/engine#8744), and
the newly-public ResourceLoader.enableRetry / disableRetry API.

Adds a new "Configuring Retries" section to the Loading and Unloading
page covering the default, global override, per-handler override and
a cross-link to the Editor Network Settings page. Mirrors the change
to the Japanese translation.

Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
mvaligursky added a commit that referenced this pull request May 18, 2026
…#8745)

Small follow-up to #8744 addressing review comments on
ResourceLoader.enableRetry.

- AppBase now calls this.loader.enableRetry() without arguments, so the
  default retry count (5) lives in a single place - the enableRetry
  signature - instead of being duplicated in AppBase.
- enableRetry now floors maxRetries before clamping, so non-integer
  inputs produce a predictable number of attempts.

Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
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.

2 participants