Skip to content

fix(studio): keep scoped download progress tied to current files - #12390

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
Imagineer99:fix/scoped-download-progress
Oct 1, 2026
Merged

danielhanchen merged 5 commits into
unslothai:mainfrom
Imagineer99:fix/scoped-download-progress

Conversation

@Imagineer99

Copy link
Copy Markdown
Member

When a scoped media download reuses a repository with a different file set, progress can read the previous manifest and retain its larger total indefinitely. For example, switching to a 6.3 GB file can leave the queue showing 6.7 GB and initially omit bytes already transferred.

Validate scoped manifests against the current job's file paths and resolved hashes before using them for sizing, disk counts, or completion. While a new manifest is pending, use the current job's hashes and caller estimate. Once variant metadata is resolved, allow its authoritative total to replace an oversized hint. Preserve conservative sizing for full snapshots and hint fallback when metadata is unavailable.

Validation:

  • 18 new regression tests pass, covering both existing diffusion and Hub scopes, larger/smaller/equal-size switches, same-file retries, changed revisions, missing manifests/hashes, restored jobs, companions, completion, and full-snapshot fallback.
  • Before the fix, 15 of the original 16 regression cases failed; the same-file retry control passed.
  • Existing Hub suite: 755 pass on both baseline and fixed backend, with the same five pre-existing deletion fixture failures (SimpleNamespace missing source). Full run with the initial 16 added cases: 771 pass, same five failures. Final focused run after two additional controls: 41 pass.
  • Ruff and git diff --check pass.
  • Playwright renders the unchanged production download panel against each backend progress service in isolated seeded-cache harnesses: BEFORE 8.0 MB / 6.7 GB; AFTER 8.0 MB / 6.3 GB. The fixed first poll also reports the current 8 MB. No live Hugging Face download was performed in this evidence scene.

Independent of asset-disclosure PR #12387. No frontend changes in this patch.

@shimmyshimmer

Copy link
Copy Markdown
Member

Review record for #12390, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#265.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 0702ec0c9 (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] on studio/backend/hub/services/snapshot_progress.py (on the mirror)

@@ -343,6 +343,22 @@ def _snapshot_resolves_to(
     return True
 
 
+def manifest_matches_download(
+    manifest: Optional[download_manifest.Manifest],
+    metadata: Optional[download_registry.DownloadMetadata],
+) -> bool:
+    """A reused scope must not read a previous file set or revision's manifest."""
+    files = frozenset(getattr(metadata, "scoped_files", ()) or ())
+    if manifest is None or not files:
+        return True
+    if frozenset(file.path for file in manifest.expected_files) != files:
+        return False
+    hashes = frozenset(getattr(metadata, "progress_blob_hashes", ()) or ())
+    return not hashes or hashes == frozenset(
+        file.sha256 for file in manifest.expected_files if file.sha256
+    )

P2 Badge Bind manifest validation to the launched job

If the repository changes between the parent’s scoped_file_blob_hashes preflight and the worker’s later _model_info_with_retry, the worker downloads the newer revision and publishes its manifest, but progress_blob_hashes still describes the older revision. This equality check then rejects the manifest produced by the current worker; subsequent polls filter out its new blobs and never report complete_on_disk, even after the job succeeds. Associate the manifest with the job generation or refresh the registered hashes rather than treating the preflight hash set as permanently authoritative.

Useful? React with 👍 / 👎.

Rejected on the mirror

Reply from danielhanchen:

Not changing this. The registry hashes and the worker's manifest are both resolved from model_info at claim time, seconds apart; a mismatch needs the upstream repo to replace these exact files inside that window (or during a same-job transport retry). A fresh start re-resolves both. Treating the manifest as authoritative instead would reopen the stale-manifest window this PR closes.

chatgpt-codex-connector[bot] on studio/backend/hub/services/snapshot_progress.py (on the mirror)

@@ -373,10 +389,18 @@ def compute_snapshot_progress(
     active_root = Path(metadata_hub_cache) if metadata_hub_cache else None
 
     expected_total = max(expected_bytes, 0)
-    # Always resolve the revision's blob hashes so stale blobs from a superseded revision cannot inflate the count; they degrade to empty (count-all) only when metadata is unavailable (e.g. offline). Take the larger total so a low caller hint cannot cap the bar.
+    # Resolve revision hashes so superseded blobs cannot inflate the count.
+    # Unavailable metadata falls back to the caller's estimate.
     meta_total, expected_hashes = metadata_resolver(repo_id, hf_token)
     meta_total = max(0, meta_total)
-    expected_total = max(expected_total, meta_total)
+    # A resolved variant's total is exact: max() with a hint left over from an earlier scoped pick never shrinks.
+    expected_total = (
+        meta_total if variant is not None and meta_total > 0 else max(expected_total, meta_total)
+    )

P2 Badge Preserve the hint when the total comes from an old manifest

When remote variant metadata is unavailable, _metadata_resolver can obtain meta_total from _variant_manifest_decision, which may be an older locally installed revision rather than an authoritative current total. Unconditionally replacing a larger caller hint for every variant lets that old manifest shrink the total; its old snapshot can then satisfy the completion check and report the current, larger variant as fully downloaded. Only allow totals from current remote metadata or a manifest verified against the active scoped job to reduce the caller’s estimate.

Useful? React with 👍 / 👎.

Accepted on the mirror

Reply from danielhanchen:

Fixed in 0554a1b: a quant variant whose total comes only from a local manifest (remote metadata unavailable) now keeps max(manifest, caller estimate); remote requirements and scope manifests stay authoritative. Regression test test_offline_variant_manifest_does_not_shrink_hint fails without it.

Round 2: reviewed mirror 220876ce25 (this PR's 0554a1b20)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 220876ce25

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 220876ce25 (this PR's 0554a1b20).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

@danielhanchen
danielhanchen marked this pull request as ready for review October 1, 2026 10:24
@danielhanchen
danielhanchen self-requested a review as a code owner October 1, 2026 10:24
@danielhanchen
danielhanchen merged commit 543acd5 into unslothai:main Oct 1, 2026
29 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants