Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,41 @@ After changing the upload path, check whether the following must be updated as w
- **Arguments and exceptions:** Propagate `revision`, `cache_dir`, and `local_files_only` through every layer (shim → compat → implementation). An empty revision at a compatibility entry point selects the default revision; an explicit revision missing from the standard snapshots must not fall back to the default. Shim modules must keep exporting the exceptions callers import from them, such as `InvalidParameter` from `modelscope.hub.snapshot_download`.
- **Offline:** `local_files_only=True` resolution performs no network access, credential initialization, or writes, and raises `CacheNotFound` when the cache is missing.
- **Regression:** Changes affecting this integration must be verified against a real vLLM installation: online multimodal serving by repository ID, offline serving, and legacy caches. Unit tests mock only the lowest-level dependency and verify network attempts and disk writes; high-level mocks alone do not prove compatibility.

---

## 9. Download-Count Contract (`snapshot-identifier`)

### 9.1 Task Granularity and Implementation Boundary

- `snapshot-identifier` identifies one logical snapshot task, not a file, HTTP request, thread, process, or UA session. Generate it once at the `download_repo` / `download_repo_report` entry point and pass it down explicitly; header builders only read it and never generate a UUID.
- Every file, worker, transport retry, integrity retry, Range resume, parallel part, and route probe of one task must reuse that identifier. Reuse inside a single file-transfer loop does not prove repository-wide granularity; the outer integrity-retry chain must carry it too.
- Standalone `download_file`, compat single-file calls, an explicit file list in normal CLI mode, and kernels `hf_hub_download` must not send the header. In CLI report mode the file list is a snapshot filter and still shares the task identifier. The HTTP layer must never infer the task type.
- Never store the identifier in a mutable shared field on `DownloadManager` or `HubApi`; concurrent or successive tasks on one instance must stay isolated. A non-blank caller-supplied identifier must not be overwritten, replaced by the UA `session_id`, derived from file paths, merged with `X-Request-ID`, or rotated over time.
- Return a local file that passes the current size/hash check before building any download request; metadata compatibility paths are cache-first too. Never send requests only to increment counters, and never block or fake success on counting failures.
- Report mode reuses `snapshot: {id, open}` in the existing hidden JSON: an unfinished task reuses the ID, and a new ID starts after `COMPLETE`. Healthy files are not persisted individually and no per-file writes are added. A corrupt, missing, or unwritable hint may only reduce recovery/deduplication and never replaces file-integrity validation.
- Strict mode treats each call as a new task; report-mode resume must distinguish new from resumed tasks. For unpersisted boundaries such as a hard kill right after a `COMPLETE` tracker, state the possible over-count; never claim strict deduplication under arbitrary crashes.

### 9.2 Server-Side Counting and Evidence Boundary

- Scope is the dataset file endpoint. The deduplication key is dataset ID + identifier and excludes user, IP, file, revision, and UA. A qualifying request with a non-blank new identifier counts +1 for the dataset; a missing or blank identifier accrues fractionally against the server denominator N. The SDK never submits weights and never assumes N=1000. `Source=SDK` and UA are channel attribution only; they never replace or correct the snapshot identifier, and integrations must confirm the target protocol version.
- HEAD, `View=true`, and exactly root-level `README.md`, `dataset_infos.json`, and `.gitattributes` are neither counted nor deduplicated. Same-named files in nested directories do not inherit the root-path exclusion.
- The TTL is 7200 s from first insertion and repeats do not refresh it, so reusing an ID after two hours may count again. The +1 occurs on the first qualifying request, not at completion. A 302 does not prove full receipt, cancellation or failure has no rollback protocol, and asynchronous deduplication is not atomic with the DB increment. Never claim exactly-once.
- Snapshots with include/exclude filters still count as one task. Model, skill archive, explicit `download/increase`, and other download paths must be verified separately; dataset semantics must not be generalized. Model counts remain 0 for both SDK generations and are recorded as unconfirmed only.
- For every scenario, take a stable baseline, then observe asynchronous persistence within a stability window while verifying actual request headers, request count, unique-ID count, and integer/fractional delta. When an expected value exists, assert equality with the measured delta; a broad oracle range is not sufficient.
- Legacy `Downloads` and OpenAPI `downloads` must not be assumed equivalent. Probe fractional conversion with independent requests at integer multiples of N and record both readings. Without action logs, SQL, or deployment metadata, state the evidence gap; never treat a page integer or a log-line count as the exact DB value.
- Inspect the actual `PreparedRequest` with case-insensitive header lookup and record only required fields plus credential presence. Never persist tokens, cookie values, or presigned URLs. A WAF cookie is not a login credential; anonymous assertions must distinguish `Authorization` / `m_session_id` from ordinary cookies.

### 9.3 Mandatory Regression Matrix

- Changes touching task context, request headers, recovery state, or delegating entry points must cover: inline+LFS repositories, multiple workers, sequential and same-instance concurrent tasks, Range/disconnect/integrity retries, single file, filters, full cache hit, root metadata plus same-named nested files, report-mode cancellation / cross-process resume / a new task after `COMPLETE`, and a corrupt or unwritable tracker.
- Offline tests mock only the lowest-level dependency and capture real HTTP requests; a high-level `snapshot_download` mock cannot prove argument, UA, task-ID, or compatibility propagation. Online runs use isolated local output, compare downloaded size/hash against the server-side file listing, and never substitute client-side upload routing for server echo.
- Online verification pins the HTTPS endpoint and an authorized owner and prefers registered private test repositories. Public visibility is opened only in an approved whitelist window and restored to private in `finally`. Creation, upload, visibility change, and deletion are never self-authorized by "verification" needs; deletion requires prior approval of the exact list plus hard scope checks.
- Preserve unmodified baseline and failure request evidence. When a framework assertion is found incorrect, record why and re-judge or rerun; never turn a failure into a pass by relaxing SDK invariants. Reproduce pre-existing dependency/API failures on the unmodified baseline, then isolate the version and verify, without folding them into the current fix.

### 9.4 `modelscope` and Hub Dual-Package Compatibility

- "Latest version" means the official stable release: verify its dependency constraint and record the wheel SHA-256, both package versions, and the actual import path. A local `+main` tree, a stale editable install, or egg-info is not evidence of a release. Use an isolated workspace environment with Hub pointing at local `src`; never replace the user's global environment.
- Verify from real `modelscope` entry points: snapshot, dataset snapshot, model and dataset single file, `HubApi.download_model`, and the branded CLI. Preserve historical positional arguments, `revision`, `cache_dir`, `local_dir`, token and endpoint propagation, `str` return values, exceptions, and the UA markers `invoked_by/compat` / `invoked_by/cli`.
- Cover online download, cache reuse, and `local_files_only`. Offline must not only return the correct path but also prove no network attempt, credential initialization, or disk write. Report parameters unsupported by a shim are recorded as capability boundaries and never faked by dynamic patching.
- Never deliver a download-count fix by modifying consumers or vLLM, adding a Hugging Face dependency, or runtime hooks; optional installs serve isolated regression only. A change that affects the Section 8 integration still requires its real-vLLM verification.
Loading
Loading