Skip to content

feat(web): retry transient failures when fetching frontend assets and resources - #1053

Merged
kyasbal merged 3 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-qvzqkmmnvuqx
Sep 28, 2026
Merged

kyasbal merged 3 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-qvzqkmmnvuqx

Conversation

@kyasbal

@kyasbal kyasbal commented Sep 28, 2026

Copy link
Copy Markdown
Member

Background & Problem

When KHI runs behind reverse proxies or load balancers, static frontend asset requests (such as WebGL .glsl shader files, BMFont .json configurations, texture atlas images, and release notes markdown) or idempotent Connect-RPC requests occasionally encounter transient HTTP 502 Bad Gateway, 503 Service Unavailable, or 504 Gateway Timeout responses, as well as brief network interruptions.

Previously, raw fetch() calls and HTMLImageElement.src loads in WebGLUtil and ReleaseNotesDialogSmartComponent did not retry on transient failures. A single transient 502 when fetching a shader or font asset caused WebGL timeline canvas initialization to fail permanently until the user manually reloaded the page. Additionally, several idempotent unary Connect-RPC methods added in recent features were not registered in DEFAULT_RETRYABLE_METHODS.

Solution Approach

  1. Fetch Retry Utility (fetchWithRetry):
    • Introduced isRetryableHttpStatus(status) and fetchWithRetry(input, options) in retry-util.ts, reusing the existing exponential backoff with jitter (calculateBackoffDelayMs), abort-aware delay (delayWithSignal), and network error detection (isRetryableError).
    • fetchWithRetry automatically retries when fetch() returns a retryable HTTP status (502, 503, 504) or throws a transient network TypeError, while respecting AbortSignal cancellation and returning non-retryable responses (200, 404, 500, etc.) immediately without extra attempts.
  2. Resilient WebGL Asset & Release Notes Loading:
    • Updated WebGLUtil.getShaderString, WebGLUtil.loadBMFontConfig, and ReleaseNotesDialogSmartComponent to fetch assets via fetchWithRetry.
    • Updated WebGLUtil.loadImage to fetch image bytes via fetchWithRetry, decode the resulting Blob via URL.createObjectURL and image.decode(), and deterministically revoke the object URL in a finally block. Failed loads continue to be evicted from imageLoadingCache so subsequent requests can retry cleanly.
  3. Connect-RPC Retry Coverage:
    • Added the remaining idempotent unary RPCs (GetTimelineIDsForLogs, GetInspectionTaskRegistry, ResolveInspectionTaskGraph, PullInspectionRunTaskGraph, DryRunInspection, and ValidatePopupAnswer) to DEFAULT_RETRYABLE_METHODS in retry.interceptor.ts.

Alternatives Considered

  • Retrying HTMLImageElement.src directly via onerror callbacks: Rejected because browser HTMLImageElement error events do not expose the underlying HTTP status code, making it impossible to distinguish transient 502/503/504 responses from permanent 404 Not Found errors. Fetching via fetchWithRetry and decoding a Blob object URL enables status-aware retries and matches the existing pattern in StyleStore.setIconAtlas.

Remaining Issues & Future Work

  • None.
@kyasbal kyasbal added type:feature New feature or request area:frontend Web frontend application and UI components labels Sep 28, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new utility function fetchWithRetry to handle automatic retries with exponential backoff on transient HTTP statuses (502, 503, 504) and network errors. This utility is integrated into the release notes component and WebGL utility functions, and several API methods are added to the retryable methods list. The changes are well-supported by comprehensive unit tests. The review feedback suggests two key improvements: extracting the AbortSignal from the input parameter if it is a Request object, and simplifying the fetch call while throwing a custom CancellationError instead of a DOMException when an abort occurs.

Comment thread web/src/app/services/api/retry-util.ts Resolved
Comment thread web/src/app/services/api/retry-util.ts Resolved
@kyasbal
kyasbal added this pull request to the merge queue Sep 28, 2026
Merged via the queue into GoogleCloudPlatform:main with commit c90493c Sep 28, 2026
17 checks passed
@kyasbal
kyasbal deleted the push-qvzqkmmnvuqx branch September 28, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:frontend Web frontend application and UI components type:feature New feature or request

1 participant