Skip to content

Task-scoped download counting - #85

Merged
wangxingjun778 merged 4 commits into
mainfrom
fix/download_identifier
Nov 24, 2026
Merged

wangxingjun778 merged 4 commits into
mainfrom
fix/download_identifier

Conversation

@wangxingjun778

Copy link
Copy Markdown
Member

Fix

  • Snapshot downloads send one snapshot-identifier per task. download_repo, snapshot_download, ms-hub download and report mode previously generated a fresh UUID for every file request (and thus counted repeatedly). The identifier is now created once at the task entry and propagated down through every file, worker, range part, route probe, resume and integrity retry.
  • Standalone file downloads no longer send the header. download_file, model_file_download, dataset_file_download, compat single-file calls and CLI explicit file arguments now omit snapshot-identifier, so the dataset service applies its per-file counting to them instead of attributing a whole-snapshot hit.
  • Resumed report-mode tasks reuse the identifier. The task ID and an open flag are persisted in the existing hidden tracker JSON; a task that ends PARTIAL or CANCELLED keeps its ID on rerun, while the run after a COMPLETE tracker starts a new task.
  • Cached dataset meta files no longer cost a counted request. LegacyHubApi now checks the local meta-file cache before calling the datasets/.../repo endpoint instead of after.

Enhance

  • Tracker hardening: the persisted snapshot ID is validated against a 32-char hex pattern and folded into the existing scope check; malformed, foreign-scope or unreadable hints clear it and fall back to normal actual-file validation, never implying success.
  • Explicit API surface: _build_download_headers(..., snapshot_id=...), download_repo(..., _snapshot_id=...), _download_file(..., _snapshot_id=...) and _download_with_resume(..., snapshot_id=...); a non-blank caller-supplied ID is preserved, and the header builder never generates one itself.
  • No extra disk writes: the ID rides in the same JSON scope header, adding no per-file state writes.

Docs

  • README: new "Download counting" section documenting task granularity, the two-hour server deduplication window, counted-at-first-request/irreversible-cancellation semantics, and the absence of exactly-once guarantees; tracker notes extended with ID reuse rules; v0.7.2 news entry.
  • Docstrings: download_file, download_repo, download_repo_report, download_snapshot and module header now describe identifier scope and cached-file behavior.

Tests

  • New tests/test_download_snapshot_identifier.py (454 lines): whole-repo inline+LFS, multi-worker, sequential and concurrent tasks on one instance, Range/disconnect/integrity retries, single-file and filtered downloads, full cache hit, root vs nested metadata files, report cancel/cross-process resume/post-COMPLETE rerun, corrupt/unwritable trackers, real PreparedRequest header capture.
  • Extended tests/test_modelscope_download_compatibility.py and tests/test_download_integrity.py for compat passthrough and identifier stability.

@wangxingjun778
wangxingjun778 merged commit 6bc39d1 into main Nov 24, 2026
3 of 6 checks passed
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