Repository navigation
Conversation
`/<repo>/resolve/<rev>/<file>` on `<ns>.<host>` serves the entry `<repo>/<file>` of the pointed bundle under `main` or the bundle's commit, with `X-Repo-Commit`, `ETag`/`X-Linked-Etag` and `X-Linked-Size`, so `huggingface_hub` downloads and resumes from it. Part of #2593. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Download consistency, byte preservation, resolve-path parsing, and Hub error handling have unresolved correctness issues.
5 open issues
Pin successful resolve HEAD responses to a commit · New Return RevisionNotFound error code for unknown revisions · New Serve resolve downloads as raw files with stable size metadata · New Mark missing resolved entries with Hub error metadata · New Parse resolve delimiter after full repository prefix · New
What changed in this PR
Adds Hugging Face file-download support to public namespace gateways, building on namespace pointers so hub clients can use a namespace host as HF_ENDPOINT.
Changes:
- Maps resolve URLs to bundle entries and adds Hub metadata headers.
- Adds blob-hash ETags to streamed responses.
- Adds routing, header, and end-to-end coverage, plus documentation of supported behavior and limitations.
| File | Description |
|---|---|
crates/e2e/tests/gateway_pointer.rs |
Tests HF metadata and unknown revisions through a public gateway. |
crates/cli/src/commands/gateway/tests.rs |
Tests namespace resolve requests, ranges, and host isolation. |
crates/cli/src/commands/gateway/hf/tests.rs |
Tests path parsing, commit derivation, and metadata headers. |
crates/cli/src/commands/gateway/hf.rs |
Implements resolve-path parsing and Hub headers. |
crates/cli/src/commands/gateway.rs |
Integrates namespace resolve handling and streamed ETags. |
CHANGELOG.md |
Records the new gateway capability. |
adr/architecture.md |
Adds HF support to the gateway overview. |
adr/appendix-gateway.md |
Documents endpoint behavior and limitations. |
Review effort: Balanced
| if response.status().is_success() { | ||
| hf::decorate(response.headers_mut(), &site.hash); | ||
| } |
There was a problem hiding this comment.
Fixed in 143809d: HEAD /<repo>/resolve/main/<file> answers 302 to the same path under the bundle's commit (hf::pinned), a path-absolute Location the hub client follows as a relative redirect, so the GET that follows names one bundle; if the pointer moved in between, that commit path is 404 RevisionNotFound instead of another bundle's bytes under the first commit. GET under main still serves directly, nothing redirects off the host, and the namespace bucket is unchanged (the redirect costs no pull). Tests: a_namespace_host_resolves_hf_paths (302 + Location, then 200 with the headers on the commit path) and the e2e's step 5. A pointer update between HEAD and GET is not simulated in a test: the unit fixture can set the pointer between the two requests, but the commit-path 404 it would produce is the UnknownRevision case already asserted.
| return text( | ||
| StatusCode::NOT_FOUND, | ||
| "unknown revision: a namespace host serves `main` and the bundle's \ | ||
| commit\n", | ||
| ); |
There was a problem hiding this comment.
Fixed in 3419437: an unknown revision answers X-Error-Code: RevisionNotFound; a missing entry answers X-Error-Code: EntryNotFound with X-Repo-Commit, on GET and HEAD (hf::not_found). Asserted in a_namespace_host_resolves_hf_paths.
| Ok(uri) => DecdnUri::new(uri.hash, uri.target, site.namespace), | ||
| Err(e) => return text(StatusCode::NOT_FOUND, &format!("{e}\n")), | ||
| }; | ||
| self.paid(&page_host, pointer, &uri, Present::Site, range) |
There was a problem hiding this comment.
Fixed in 3419437: resolve paths are served as Present::Download on GET and HEAD, so the body is the entry byte for byte (no URI rewrite), Content-Length/X-Linked-Size stay on HTML and CSS entries, and a Range is a 206. a_resolved_page_is_served_byte_exact_with_its_length covers an HTML entry with a decdn: link: exact on the resolve path, still rewritten on its literal site path.
| if response.status().is_success() { | ||
| hf::decorate(response.headers_mut(), &site.hash); | ||
| } |
There was a problem hiding this comment.
Fixed in 3419437: an unknown revision answers X-Error-Code: RevisionNotFound; a missing entry answers X-Error-Code: EntryNotFound with X-Repo-Commit, on GET and HEAD (hf::not_found). Asserted in a_namespace_host_resolves_hf_paths.
| return HfPath::NotResolve; | ||
| }; | ||
| let segments: Vec<&str> = rest.split('/').collect(); | ||
| let Some(at) = segments.iter().position(|s| *s == "resolve") else { |
There was a problem hiding this comment.
Fixed in 143809d + the follow-up commit: resolve is looked for after the repo id ([<type>/]org/name, with datasets/ or spaces/ as the types; models/ is no prefix on the hub, so an org of that name is an org), so /org/resolve/resolve/main/f.bin and /datasets/org/resolve/resolve/main/f.bin resolve their entries and a deeper path before the delimiter is a literal entry path. All four shapes are in the path table.
…4s carry X-Error-Code A page on a resolve path is a download, never rewritten, so it keeps its length and matches the etag the hub client stores it under. An unknown revision answers `X-Error-Code: RevisionNotFound`; a missing entry `EntryNotFound` with the commit, so the client tells either from a lost connection. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 3 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
… resolve is found after the repo id A `HEAD /<repo>/resolve/main/<file>` answers 302 to the same path under the bundle's commit, so the download that follows names one bundle, and a pointer that moves in between fails it instead of caching another bundle's bytes under the first commit. The `resolve` delimiter is looked for after `[<type>/]org/name`, so a repo named `resolve` resolves. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Only `datasets/` and `spaces/` lead a resolve path; an org named `models` is an org, so `/models/demo/resolve/main/a.bin` resolves. The pointer e2e covers that shape. Co-Authored-By: Claude Fable 5.1 <[email protected]>


Part of #2593 (PR 6 of 6, after #2614). A namespace host on a public gateway doubles as an
HF_ENDPOINT:huggingface_hubdownloads and resumes fromhttps://<ns>.<host>with no redirect and nothing installed beyond the hub client (the transport in #2604 can point here too).What
gateway/hf.rs: on a namespace host,GET|HEAD /<a>/<b>[/…]/resolve/<rev>/<file…>is the entry<a>/<b>[/…]/<file…>of the pointed bundle when<rev>ismainor the bundle's commit (the first forty hex of the manifest hash); another revision is 404; anything not of that shape falls through to the ordinary entry lookup. Successful answers carryX-Repo-Commit,X-Linked-Etag(=ETag, the entry hash) andX-Linked-Size(the whole entry's size, taken fromContent-Rangeon a 206), plus theAccept-Ranges: bytesa sized entry already had.HEADis answered from the manifest at no pull, as before..html/.cssentry keeps its length onHEADandGETand the body matches the etag the client stores it under (a reviewer caught that the first cut rewrote them). A 404 carriesX-Error-Code: RevisionNotFoundorEntryNotFound(withX-Repo-Commit), which is howhuggingface_hubtells a missing file from a lost connection instead of falling back to a stale cache.HEADundermainanswers 302 to the same path under the bundle's commit (a path-absoluteLocationthe hub client follows as a relative redirect), so theGETthat follows names one bundle: a pointer that moves between the two requests fails the download withRevisionNotFoundinstead of caching another bundle's bytes under the first commit.GETundermainserves directly; nothing redirects off the host.resolvedelimiter is looked for after the repo id ([datasets/|spaces/]org/name), so a repo namedresolveresolves and a deeper path before it is a literal entry path.models/is no prefix on the hub, so an org of that name is an org.pointer.is_some()), never on<hash32>.<host>sites or loopback, and never under/_decdn/.ETag: "<blob hash hex>"(HEAD and empty entries already did).adr/appendix-gateway.md§HF_ENDPOINT(including that resolve paths shadow literal entries on the namespace host, and that/api/forsnapshot_downloadis not served), CHANGELOG, architecture.md.Tests
hf/tests.rs: commit derivation; the pinned commit path; the path table (including repos namedresolve, amodels/org, deeper paths that are not resolve paths) (models, datasets, nested files, percent-encoded names, the commit revision; unknown revisions including uppercase and the full hash; non-resolve shapes); header decoration for full, partial and unsized answers.gateway/tests.rs::a_namespace_host_resolves_hf_paths: GET undermainand the commit with all headers, HEAD undermain→ 302 to the commit path → HEAD 200 with the headers, a 206 whose linked size is the whole, unknown revision 404 (RevisionNotFound), missing file 404 (EntryNotFound+ commit, on GET and HEAD), the literal entry still served, the hash site untouched;a_resolved_page_is_served_byte_exact_with_its_length: an HTML entry with adecdn:link is byte-exact withContent-Length/X-Linked-Sizeon the resolve path and still rewritten on its literal site path.crates/e2e/tests/gateway_pointer.rsgains aHEAD /models/demo/resolve/main/a.binstep (commit, linked size, linked etag) and an unknown-revision 404. Passes locally withgateway_public.Gates run locally: clippy
--workspace --all-targets --all-features -D warnings,cargo docwith warnings denied,cargo fmt --check,cargo nextest run -p decdn-cli -p decdn-common,make -C adr check-refs check-book-list, pre-commit on the touched docs.Follow-ups (filed)
#2617 (
/api/revision + tree forsnapshot_download), #2616 (raw-blobContent-Length/Range), #2618 (allowance across restarts), #2619 (nodedecdn_bytes_served_totalratio), decdn/devops#176 (wildcard DNS/TLS, role, PSL, proxy rate limits).🤖 Generated with Claude Code