fix "browser" test - #2118
Conversation
My understanding was that it has already a fallback to a huggingface.js/packages/hub/src/utils/WebBlob.ts Lines 34 to 41 in 1b32a04 (I will prevent a NaN here btw to be 100% sure) |
Ideally though, to avoid downloading the whole blob in memory, CORS issue should be fixed / mitigated in a better way (finding the root cause is already very nice) |
back on this The only solution I see is to always use GET and cancel reading the body if the server send the accept-ranges header. The downside is the cancel that can be late and we'll start receiving data. const size = Number(response.headers.get("content-length") || 0);
const contentType = response.headers.get("content-type") || "";
const supportRange = response.headers.get("accept-ranges") === "bytes";
if (supportRange && size >= (opts?.cacheBelow ?? 1_000_000)) {
await response.body?.cancel();
return new WebBlob(url, 0, size, contentType, true, customFetch, opts?.accessToken);
}
return response.blob(); |
8ba474d to
af35c19
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit af35c19. Configure here.
In browsers, when CloudFront gzips a response on the fly (typical for small text/JSON files behind /api/resolve-cache/...), the cached response loses both Content-Length and Accept-Ranges. Subsequent HEAD requests served from the same cache entry inherit the missing headers, so the lib could not tell either the file size or whether ranges were supported, and silently fell back to buffering the whole blob in RAM. Range responses are never content-encoded, so Content-Range (which carries the total file size) and the strong ETag always survive regardless of the cached encoding state. Switching the discovery probe from HEAD to GET Range: bytes=0-0 gives us size + range support in a single round trip and removes the test flake without any server change. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

Note
Medium Risk
Touches
WebBlob.createheader parsing and test fetch behavior; failures would affect streamed/ranged downloads, but changes are small and add validation to reduce silent misbehavior.Overview
Fixes browser-side
WebBlobcreation whenContent-Lengthis missing or not usable by validating thecontent-lengthheader and throwing a clearer error (includingx-headers) instead of silently producing an invalid size.Updates
WebBlobtests to avoid relying on CORS-exposedHEADheaders by deriving size from aGETbody and injecting a customfetchthat suppliescontent-length/accept-rangesfor theHEADrequest. Adds a rootlint-stagedconfig to runoxfmton staged*.{cjs,ts}files.Reviewed by Cursor Bugbot for commit 015531a. Bugbot is set up for automated code reviews on this repo. Configure here.