Skip to content

fix(cdn): defer lastUpdatedAt commit until manifest fetch succeeds#2284

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-remediation-7f90
Draft

fix(cdn): defer lastUpdatedAt commit until manifest fetch succeeds#2284
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-remediation-7f90

Conversation

@cursor

@cursor cursor Bot commented Jun 15, 2026

Copy link
Copy Markdown

Description

Fixes a CDN freshness bug where a successful lastUpdateTime.json check could permanently skip manifest re-download for the rest of the app session if the actual manifest fetch failed.

Bug and impact

Trigger: A CDN-backed app checks for updates; lastUpdateTime.json reports a newer lastUpdatedAt, but the manifest download fails (network timeout, 5xx, decrypt error, etc.).

Impact: _lastUpdatedAt was advanced before the manifest was successfully fetched and cached. Subsequent refresh checks saw matching timestamps and skipped the download until the CDN published another update. Apps could remain on stale screens, scripts, and translations for the entire session.

Root cause

_shouldFetchManifest() mutated _lastUpdatedAt to the remote timestamp as soon as lastUpdateTime.json was read, before _fetchManifest() completed. A failed download left the in-memory timestamp advanced with no corresponding cached manifest.

Fix

  • Replace _shouldFetchManifest() with _evaluateManifestFreshness() that returns {shouldFetch, remoteLastUpdatedAt} without mutating _lastUpdatedAt.
  • Commit the remote timestamp only after a manifest is successfully parsed and cached via _commitRemoteLastUpdatedAt().
  • Extract cdnShouldFetchManifest / cdnIsIncomingManifestNewer helpers for unit testing.

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

What Has Changed

  • CdnDefinitionProvider._evaluateManifestFreshness() evaluates freshness without side effects.
  • _commitRemoteLastUpdatedAt() is called only after successful manifest parse/cache in _loadManifest and _doRefreshIfStale.
  • Added unit tests for freshness evaluation and deferred timestamp commit.

How to Test

  1. From modules/ensemble, run flutter test test/cdn_provider_test.dart.
  2. All tests pass, including new coverage for freshness evaluation and deferred timestamp commit.

Duplicate check

Checklist

  • I have run flutter analyze and addressed any new warnings
  • I have run flutter test and all tests pass
  • I have tested my changes on the relevant platform(s)
  • I have updated documentation if needed
  • My changes do not introduce new warnings or errors
Open in Web View Automation 

When lastUpdateTime.json reports a newer timestamp but the manifest
download fails, advancing _lastUpdatedAt before a successful fetch caused
subsequent refresh checks to skip the download for the rest of the session.

Evaluate freshness without mutating _lastUpdatedAt and commit the remote
timestamp only after the manifest is parsed and cached.

Co-authored-by: Sharjeel Yunus <sharjeelyunus@users.noreply.github.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.

1 participant