Sitelet https://github.com/flutter/flutter/pull/192090
Skip to content

[flutter_tools] Fix cache download progress calculation for non-downloading artifacts - #192090

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
bkonyi:issue-192023
Sep 9, 2026
Merged

auto-submit[bot] merged 5 commits into
flutter:masterfrom
bkonyi:issue-192023

Conversation

@bkonyi

@bkonyi bkonyi commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes an issue where flutter precache reported an incorrect artifact progress count (e.g. [1/3] Web SDK) and terminated without downloading items 2 or 3.

Root Cause

  1. ArtifactSet.downloadCount defaulted to 1, causing non-downloading maintenance artifacts (LegacyCanvasKitRemover, PubDependencies, AndroidMavenArtifacts) to increment the progress total in Cache.updateAll.
  2. For flutter precache --web, artifactsToUpdate contained FlutterWebSdk (downloadable) along with LegacyCanvasKitRemover and PubDependencies (non-downloadable cleanup/resolution tasks), resulting in total = 3.
  3. FlutterWebSdk was tracked as [1/3], and the remaining non-downloading artifacts ran without invoking ArtifactUpdater, leaving the impression of incomplete progress.

Changes

  • Default ArtifactSet.downloadCount to 0.
  • Override CachedArtifact.downloadCount to return 1.
  • In Cache.updateAll, compute total and progress index based only on artifacts with downloadCount > 0.
  • Add artifactUpdater constructor parameter to Cache and Cache.test for dependency injection.
  • Add unit tests in cache_test.dart verifying downloadCount defaults and progress calculation.

Issues Fixed

Fixes #192023

Pre-launch Checklist

…oading artifacts

`ArtifactSet.downloadCount` defaulted to 1, causing non-downloading artifact sets (such as `LegacyCanvasKitRemover`, `PubDependencies`, and `AndroidMavenArtifacts`) to increment the progress total in `Cache.updateAll`. When running `flutter precache --web`, this led to reporting `[1/3] Web SDK` and completing without ever reporting on items 2 and 3.

This change:
- Sets `ArtifactSet.downloadCount` to default to 0.
- Overrides `downloadCount` to return 1 in `CachedArtifact`.
- Updates `Cache.updateAll` to calculate `artifactTotal` and index based only on artifacts with `downloadCount > 0`.
- Adds regression unit tests for `downloadCount` defaults and `Cache.updateAll` progress context.

Fixes flutter#192023
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Sep 1, 2026
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Sep 1, 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 updates the Cache class to allow overriding the ArtifactUpdater and refactors the updateAll method to calculate progress and display status only for artifacts that require downloading (where downloadCount > 0). It also changes the default downloadCount for ArtifactSet from 1 to 0, overriding it to 1 in CachedArtifact, and adds corresponding tests. The reviewer suggested a performance improvement in Cache.updateAll to avoid allocating an intermediate list with .toList() when calculating the total number of downloadable artifacts.

Comment thread packages/flutter_tools/lib/src/cache.dart Outdated
@bkonyi
bkonyi requested a review from gaaclarke September 4, 2026 20:10

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, one question about the logic for tallying the download jobs. I think it's practically no difference but the way the code and api look to me, it may be a sleeper bug

Comment on lines +807 to +809
final int total = artifactsToUpdate
.where((ArtifactSet artifact) => artifact.downloadCount > 0)
.length;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be

artifactsToUpdate.map(x => x.downloadCount).reduce((x, y) => x + y)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, total represents the number of downloadable ArtifactSets being updated rather than the total count of individual downloaded files across all sets.

The progress display uses a two-level hierarchy:

  1. At the top level, artifactTotal (total) and artifactIndex (current) track the ArtifactSets being processed (e.g., [1/3] Android SDK dependencies or [2/3] Material fonts).
  2. Within an ArtifactSet that contains multiple downloads (artifact.downloadCount > 1), downloadTotal (artifact.downloadCount) tracks the individual downloads under that set (e.g., ├─ [1/4] ...).

If we used the sum of all download counts for total, current (which increments once per ArtifactSet) would be comparing the set index against the total file download count (e.g., reaching only [3/10] when finishing the 3rd and final artifact set).

@bkonyi
bkonyi requested a review from gaaclarke September 9, 2026 15:30

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm!

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

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flutter precache --web reports wrong artifact count

2 participants