Fix models not appearing: stop /api/models from re-downloading the catalog every call#776
Merged
Merged
Conversation
The catalog refresh failed on every request because the hf-hub fork mistook a 307 redirect's Content-Length for the target file size, tripping the post-download size check. ensure_catalog() then silently fell back to the stale cache without refreshing the staleness marker, so every /api/models call re-attempted the multi-second download forever (~9s per call). - Point hf-hub at the redirect Content-Length fix branch (Mesh-LLM/hf-hub#2). - Add a 5-minute refresh backoff so a failing refresh can't turn every request into a fresh network download when a stale catalog is already loaded. - Add a unit test for the backoff and an ignored networked test that verifies the live meshllm/catalog dataset now downloads end-to-end.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes /api/models re-downloading the HuggingFace catalog on every call by (a) pointing hf-hub at a fork branch that fixes a redirect Content-Length mis-detection, and (b) adding a 5-minute refresh backoff so any future refresh failure (with a stale catalog already loaded) doesn't trigger a network attempt per request.
Changes:
- Add
CATALOG_REFRESH_BACKOFF_UNTILstate + helpers; consult it inensure_catalog()when stale and a cached catalog exists; clear on successful refresh. - Repoint
hf-hubpatch to themicn/fix-redirect-content-length-sizefork branch. - Add unit test for backoff lifecycle and an ignored networked test for live catalog refresh.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/mesh-llm-host-runtime/src/models/remote_catalog.rs | Implements refresh backoff with helpers, integrates into ensure_catalog(), and adds tests. |
| Cargo.toml | Temporarily repoints hf-hub patch to the fix branch (follow-up to revert noted in description). |
| Cargo.lock | Updated to pick up the new hf-hub commit (and incidental dependency churn). |
The hf-hub redirect fix makes the remote catalog actually downloadable in CI again. parse_exact_model_ref consults the live catalog before the Hugging Face parser branches, so the parse_exact_model_ref_accepts_* tests now match a real catalog entry (e.g. unsloth/gemma-4-31B-it-GGUF) and return ExactModelRef::Catalog instead of the HuggingFace ref they assert. These tests were only passing because catalog downloads were broken. Install an empty catalog override (and mark serial, since the override is global) so the parser branches are tested in isolation.
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.
What this fixes
Models stopped showing up in the console because
/api/modelswas hanging ~9s on every call and silently serving a stale (or empty) catalog.Each
/api/modelsrequest walksensure_catalog(), which saw the staleness marker as expired and kicked off a synchronous HuggingFace download of themeshllm/catalogdataset. That download failed on the very first small file with a spurious size mismatch:The refresh aborted before touching the
.last_refreshmarker, soensure_catalog()fell back to the stale cache and returnedOk— but the marker stayed stale, so the next request re-attempted the same multi-second download. That loop repeated forever, ~9s per call.This was pre-existing on
main(verified by building and timing a cleanmaincheckout), not a regression from #773.Root cause + the two fixes
1. The actual bug (hf-hub fork). The cache download path HEADs the
resolveendpoint with a no-redirect client and gets a307whose ownContent-Length(341) is the redirect body, not the file. With noX-Linked-Size, the fork trusted that length, then rejected the correctly-downloaded818-byte file. Fixed in Mesh-LLM/hf-hub#2 —extract_file_size()no longer trusts a redirect'sContent-Length. This PR pointshf-hubat that fix branch.2. Defense-in-depth (this crate). Add a 5-minute refresh backoff so that any future refresh failure (HF outage, auth, etc.) can't turn every request into a fresh network download when a stale catalog is already loaded. After a failed refresh with a loaded catalog, retries are suppressed for 5 minutes; a successful refresh clears the backoff immediately.
Validation
cargo fmt --all -- --check,cargo clippy -p mesh-llm-host-runtime --all-targets -- -D warningsclean.refresh_backoff_suppresses_then_clearspasses.refresh_catalog_livenow downloads the livemeshllm/catalogdataset end-to-end (80 entries); it fails on entry macos menu app #1 without the hf-hub fix.Follow-up
Cargo.tomltemporarily tracks the fork'smicn/fix-redirect-content-length-sizebranch. Once Mesh-LLM/hf-hub#2 merges into the fork'smesh-llmbranch, repointhf-hubback tobranch = "mesh-llm"andcargo update -p hf-hub.