Repository navigation
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
…timated from Co-authored-by: Cursor <cursoragent@cursor.com>
…a stale cache Co-authored-by: Cursor <cursoragent@cursor.com>
…cannot be estimated Co-authored-by: Cursor <cursoragent@cursor.com>
…re calling it ready Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
harveyff
force-pushed
the
fix/hf-progress-moved-branch
branch
from
November 17, 2026 10:31
1729ac2 to
4b05a75
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An image ships an older version of an hf:// model, with
refs/mainpointing at it. The Hub'smainhas since moved and the files kept their names. When llm-init downloads the new version, progress opens at 100% with every file row marked done, then climbs past the total ("36 GB of 18 GB") while still downloading. Reproduced on v1.7.21 and v1.7.26.Root cause
estimateDownloadBudgetseededbytes_completedand the file rows fromcachedHFSnapshotFiles. That function walked the snapshot named by the localrefs/<revision>, which is the old commit, and matched files to the new tree by path. Every old file therefore counted as done,SeedDownloadBudgetclamped the seed to the total, and tqdm then added the full transfer of the new blobs on top, becauseOnBytes/OnFileByteshave no ceiling.Fix
hfwrap: the tree listing now records each file'sBlobID:lfs.oid(sha256) for LFS files, the gitoidotherwise. These are the names the HF cache files content under inblobs/.SHA256is unchanged, so drift checks are not affected.hfwrap:ResolveCommitcalls/api/models/<repo>/revision/<rev>, and skips the request when the revision already is a commit.WriteRefCommitwritesrefs/<rev>atomically and refuses refs that would leaverefs/. The ref keeps an existing file's mode, or gets 0644 when new, so a shared cache read under another uid still sees it (os.CreateTempalone would leave 0600).EstimateReporeportsCommitwhen it listed at one.lifecycle, keeping the estimate and the download on one revision:runHFdownloads at that commit. Afterwards it writesrefs/<revision>, which hf skips when it is given a commit and whichreuseHFDownloadreads on the next boot.MODEL_SOURCEis untouched, and the next pass resolves the branch anew. If the revision cannot be resolved, the pass downloads at the revision as given, which is the old behaviour.lifecycle: drop the old-ref snapshot walk. A listed file counts as cached only when one of these is a regular file of the listed size:snapshots/<target commit>/<path>orblobs/<BlobID>. This is at most twostatcalls per file, and nothing is hashed.X-Linked-ETag: the Olares mirror sends an S3-styleETag(96a2…-10), and hf names the blob after it, so no Hub id finds it. The blob check covers content shared with an earlier revision that hf has not linked in yet.<id>.incompletepartials are not seeded, because hf resumes them and the first tqdm tick already carries their bytes.lifecycle/hfwrap, an unreachable remote is no longer silent.hf downloadanswers from the snapshotrefs/<revision>names when its own lookup fails, and exits 0. On Olares, a real app (Qwen3.8-27B,mainmoved to4af51b3) booted at the old4ca7207this way while the mirror was timing out, and the log made it look like a confirmed download.X-Repo-Commitis the request hf itself makes) at the same time. The HEAD also sizes the file, so when the API answers first the attempt waits up to 3 s more for it. The mirror has been seen refusing the revision API with 401 while serving the HEAD.Options.MetadataBudget). Against an unreachable remote the worst case drops from about 126 s to about 66 s, and past the budget the download starts without a pinned total.remote unreachable: hf revision not resolved; a cached snapshot may be used instead. When hf then returns the commit the cache already held, it addshf revision not confirmed before the download; hf returned the cached commit, which may be out of datewithcached_commit. That wording does not claim the remote was unreachable, since the same commit also comes back when nothing changed upstream..llm-initrecord reuse stays offline by design and is unchanged.progress: with the byte budget pinned,bytes_completedis capped atbytes_total. The first overrun per pass logsdownload progress ran past the pinned total; capping it. This is a safety net, not the fix.lifecycle: when the size cannot be fully estimated (e.g. the mirror times out the projector's HEAD), every file is still listed from the start, with the unsized ones shown without a size. Before, the page stayed on "Estimating size", then showed the projector alone at 100% for a minute before the main GGUF appeared. The total stays unpinned, and the log names the source that could not be sized.lifecycle: an engine still serving the previous model is restarted when a pass movesmodel_path, and the model is called ready only once it is back. On an upgrade the engine started on the persisted sentinel while the new revision downloaded, and since llama.cpp-hfpicks its revision at start, it kept serving the old model under a ready status. The restart goes through the existingengine_restarthandoff. When the request fails or no supervise loop acts on it, the model is marked failed withthe engine still serves the previous model; restart it to load the new oneinstead of ready, and the restart stays pending, so the next pass (/api/retryor a re-registration) asks for it again even though the run dir already names the new model.StateUnverifiedis left toWaitAlive. llama.cpp is asked which file it loaded (model_pathin/props, via the new optionaladapter.ServedModelReporter) instead of trusting the run dir: a mismatch triggers the restart, and after everyWaitAliveit is checked again before ready, even when the pass restarted nothing, since/propsanswers 503 while a model loads. Unanswered queries are retried for about 10 s and then let through with a warning (a build withoutmodel_path); a mismatch found there is restarted within the same pass, at most once. This holds across an llm-init restart (the run dir already names the new model), does not restart an engine already moved to the new model by hand, and fails an engine that came back on the previous model. HF cache paths are compared frommodels--<org>--<repo>on. Other engines, and a projector-only change, keep the before/after run dir comparison. The engine keeps starting with-hf <model_name>.progress/lifecycle: with no pinned total, files already on disk count toward the overall bytes as well as their rows.SeedCachedBytesstarts bothbytes_completedandbytes_totalat the cached bytes without pinning, so files that transfer still grow the total. Before, a cached projector of 100 plus 500 downloaded of the main file read 500 overall against rows adding up to 600.proxy(not about progress; this PR's diff turns on the compat job, which fails without it): the OpenWebUI alias/api/chat/completionsnow reaches vLLM, llama.cpp and SGLang as/v1/chat/completions. It was forwarded as is, none of them serves that path, and llama.cpp answered 404, failingtest_openwebui_alias_streams_sse. The compat suite had been skipping on main, its compose stack never coming up. Body rewriting, the enum check and the metrics label still run on the client's path; only the upstream path changes.Out of scope:
MODEL_SOURCE, snapshot pinning, drift /VERIFY_LEVEL, and URL sources.Behaviour by case
--revision)--revision A→--revision BVerification
go vet ./...andgo test ./...pass ingolang:1.26on Linux (28 packages).New and updated tests:
.incompletepartials and non-ID names are ignored;hasHFBlob/hasHFFilecases, including another commit's snapshot, a branch name, and a path escaping the snapshot;ResolveCommit(branch, pinned commit with no request, bad sha, missing API) andWriteRefCommit(nested refs, escape refused, 0644 when new, existing mode kept);ensurewith main moving after the estimate: hf runs at the estimated commit,refs/mainnames it, and the next pass reuses the record;ResolveCommitfalling back to the file HEAD (401 on the revision API, 302 carryingX-Repo-Commit), and refusing a HEAD without the header or a glob;ensurewith the remote unreachable and hf returning the cached commit logs both warnings; when hf returns a newer commit it logs neither;BlobIDparsing;WaitAlive, and the retry asks for the restart again and reaches ready once it happens;/propsparsing and path comparison;/props503 at first, then the old path) is restarted once and reaches ready; one that comes back on the old model fails;/propsnever answering reaches ready with no restart;/v1/chat/completionsand the/api/chat/completionsalias reach the engine as/v1/chat/completions;Real run against the Hub with the built image and huggingface_hub 0.36.2 (
unsloth/Qwen3-0.6B-GGUF,Qwen3-0.6B-Q4_K_S.gguf, same size and different bytes between0a91863and50968a4):<sha256>.incomplete, which confirms the lookup;On Olares (one@olares.fashion, through the system HF mirror):
harveyff/llm-init:v1.7.26-progress-fix2and the v1.7.26 binary, against the samehf0.36.2.0a91863downloaded with--revision, withrefs/mainpointed at it and the.llm-initrecord removed.0a91863,main=50968a4, no--revision--revision 0a91863→--revision 50968a4Pinned-commit download (
v1.7.26-progress-fix3), ISO case through the mirror:hf download starting ... revision="" commit=50968a4…;refs/mainmoved from0a91863to50968a4, a write hf does not make when given a commit;Upgrade with engine restart (
v1.7.26-progress-fix8), Qwen3.8-27B GGUF plus mmproj, old4ca7207installed,main=4af51b3: the total was pinned at exactly 18,587,014,752 bytes with both files listed; after the download the engine was restarted, llama.cpp loadedsnapshots/4af51b3(main and mmproj), and the model went Ready about 25 s later.Earlier runs, while the mirror's API was returning 504 and huggingface.co TLS handshakes were timing out, logged
commit=""and downloaded at the branch as before.Cross-revision reuse behind a mirror (a review question): not observed on Olares. A file unchanged between the two commits got a different mirror ETag under each, so hf re-downloaded it into a new blob (
5f08…→a0dc…) instead of reusing the old one silently, and progress tracked that transfer. A mirror with revision-stable ETags and noX-Linked-ETagwould still skip such a file without emitting progress. Covering that would need a HEAD per unmatched file. This PR leaves it out.The force re-download could not be observed in this harness. With no engine container, the pass waits in
loading, and the retry was not picked up within 10 minutes. The unit test above covers the force seed.