Skip to content

feat(cli): a namespace host on the public gateway is an HF_ENDPOINT - #2615

Closed
thiras wants to merge 5 commits into
mainfrom
feat/gateway-hf-resolve
Closed

thiras wants to merge 5 commits into
mainfrom
feat/gateway-hf-resolve

Conversation

@thiras

@thiras thiras commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2593 (PR 6 of 6, after #2614). A namespace host on a public gateway doubles as an HF_ENDPOINT: huggingface_hub downloads and resumes from https://<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> is main or 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 carry X-Repo-Commit, X-Linked-Etag (= ETag, the entry hash) and X-Linked-Size (the whole entry's size, taken from Content-Range on a 206), plus the Accept-Ranges: bytes a sized entry already had. HEAD is answered from the manifest at no pull, as before.
  • Resolve paths are served as downloads: byte for byte, never through the site rewrite, so an .html/.css entry keeps its length on HEAD and GET and the body matches the etag the client stores it under (a reviewer caught that the first cut rewrote them). A 404 carries X-Error-Code: RevisionNotFound or EntryNotFound (with X-Repo-Commit), which is how huggingface_hub tells a missing file from a lost connection instead of falling back to a stale cache.
  • HEAD under main answers 302 to the same path under the bundle's commit (a path-absolute Location the hub client follows as a relative redirect), so the GET that follows names one bundle: a pointer that moves between the two requests fails the download with RevisionNotFound instead of caching another bundle's bytes under the first commit. GET under main serves directly; nothing redirects off the host.
  • The resolve delimiter is looked for after the repo id ([datasets/|spaces/]org/name), so a repo named resolve resolves 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.
  • The shim applies only where the site is a pointer's (pointer.is_some()), never on <hash32>.<host> sites or loopback, and never under /_decdn/.
  • Every streamed response now carries ETag: "<blob hash hex>" (HEAD and empty entries already did).
  • Docs: adr/appendix-gateway.md § HF_ENDPOINT (including that resolve paths shadow literal entries on the namespace host, and that /api/ for snapshot_download is not served), CHANGELOG, architecture.md.

Tests

  • hf/tests.rs: commit derivation; the pinned commit path; the path table (including repos named resolve, a models/ 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 under main and the commit with all headers, HEAD under main → 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 a decdn: link is byte-exact with Content-Length/X-Linked-Size on the resolve path and still rewritten on its literal site path.
  • crates/e2e/tests/gateway_pointer.rs gains a HEAD /models/demo/resolve/main/a.bin step (commit, linked size, linked etag) and an unknown-revision 404. Passes locally with gateway_public.

Gates run locally: clippy --workspace --all-targets --all-features -D warnings, cargo doc with 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 for snapshot_download), #2616 (raw-blob Content-Length/Range), #2618 (allowance across restarts), #2619 (node decdn_bytes_served_total ratio), decdn/devops#176 (wildcard DNS/TLS, role, PSL, proxy rate limits).

🤖 Generated with Claude Code

`/<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]>
Copilot AI balanced review requested due to automatic review settings October 24, 2026 20:16
Co-Authored-By: Claude Fable 5.1 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Download consistency, byte preservation, resolve-path parsing, and Hub error handling have unresolved correctness issues.

5 open issues
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

Comment on lines +1297 to +1299
if response.status().is_success() {
hf::decorate(response.headers_mut(), &site.hash);
}

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.

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.

Comment thread crates/cli/src/commands/gateway.rs Outdated
Comment on lines +1278 to +1282
return text(
StatusCode::NOT_FOUND,
"unknown revision: a namespace host serves `main` and the bundle's \
commit\n",
);

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.

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.

Comment thread crates/cli/src/commands/gateway.rs Outdated
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)

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.

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.

Comment on lines +1297 to +1299
if response.status().is_success() {
hf::decorate(response.headers_mut(), &site.hash);
}

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.

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.

Comment thread crates/cli/src/commands/gateway/hf.rs Outdated
return HfPath::NotResolve;
};
let segments: Vec<&str> = rest.split('/').collect();
let Some(at) = segments.iter().position(|s| *s == "resolve") else {

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.

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]>
@github-code-quality

github-code-quality Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 38353ea feat/gateway-hf-reso... 099d8c3 +/-
77% 77% 0%
View coverage of the 3 most impacted files.
File main 38353ea feat/gateway-hf-reso... 099d8c3 +/-
crates/cli/src/...ands/gateway.rs 76% 77% +1%
crates/protocol/src/framing.rs 92% 93% +1%
crates/cli/src/...s/gateway/hf.rs 0% 96% +96%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 24, 2026 21:02 UTC

thiras and others added 2 commits October 24, 2026 23:47
… 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]>
@thiras thiras modified the milestone: v0.3 Oct 28, 2026
@thiras
thiras marked this pull request as draft October 30, 2026 21:29
@thiras thiras closed this Nov 25, 2026
@thiras
thiras deleted the feat/gateway-hf-resolve branch November 25, 2026 21:03
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.

2 participants