Skip to content

Commit 4ca7f50

Browse files
committed
fix(hub): download re-adopt/cancel correctness, external-link matching, GGUF dropdown click-through
- re-adopt: explicit backend state now wins in adoptingCancel, so a running download no longer sticks on "Cancelling" with a disabled button after a refresh; the epoch guard applies even when cancel was issued before adoption (drops the now-unused applyCancelResult param) - cancel/crash: snapshot cancel_requested before drop_process so a cancel landing in the finalize gap can't mislabel an OOM/SIGKILL crash as "cancelled" or persist a spurious resume marker - external links: route protocol-relative //host README links through the confirmation modal (was only matching ://, mailto:), match case-insensitively, and harden the dialog's host display - GGUF card: tags and status marks in the download-bar dropdown no longer swallow clicks and selections - refactor: promote gguf_variant_blob_hashes / gguf_variant_requirements to public so download orchestration stops reaching into private helpers (updates call sites and tests)
1 parent b0152f7 commit 4ca7f50

12 files changed

Lines changed: 93 additions & 63 deletions

File tree

‎studio/backend/hub/services/download_lifecycle.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,14 @@ def finalize_worker_exit(
232232
worker's own exit code be the single source of truth."""
233233
stderr_data = drain_stderr_excerpt(proc.stderr)
234234
rc = proc.wait()
235+
cancel_requested = registry.cancel_requested(key)
235236
if not registry.drop_process(key, proc):
236237
return
237238
stderr_text = download_registry.scrub_secrets(
238239
(stderr_data or b"").decode("utf-8", "replace").strip(),
239240
hf_token = hf_token,
240241
)
241-
state = classify_exit(rc, cancel_requested = registry.cancel_requested(key))
242+
state = classify_exit(rc, cancel_requested = cancel_requested)
242243
if state == "complete":
243244
registry.set_job(key, "complete")
244245
if stderr_text:

‎studio/backend/hub/services/models/deletion.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,10 @@ def _delete_cached_model_blocking(
384384
try:
385385
# A sibling quantization may be downloading concurrently (a per-variant
386386
# delete does not block it). When one is, restrict this delete to the
387-
# variant's own files so the shared mmproj companion stays intact for the
388-
# live sibling.
387+
# variant's own files and leave the shared mmproj companion for it. This
388+
# is a point-in-time check: the finalized companion blob is held by the
389+
# reference-count walk below, and a sibling that starts mid-delete simply
390+
# re-fetches the companion (no data loss).
389391
sibling_active = bool(
390392
variant and downloads.registry.has_active_peer_variant(repo_id, variant)
391393
)

‎studio/backend/hub/services/models/downloads.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ async def download_model_response(
107107
if variant is not None:
108108
try:
109109
variant_blob_hashes = await asyncio.to_thread(
110-
gguf_variants._gguf_variant_blob_hashes,
110+
gguf_variants.gguf_variant_blob_hashes,
111111
repo_id,
112112
variant,
113113
hf_token,
114114
include_companions = False,
115115
)
116116
variant_progress_blob_hashes = await asyncio.to_thread(
117-
gguf_variants._gguf_variant_blob_hashes,
117+
gguf_variants.gguf_variant_blob_hashes,
118118
repo_id,
119119
variant,
120120
hf_token,
@@ -270,7 +270,7 @@ def _variant_transport_status(
270270
repo_id,
271271
active_only = True,
272272
)
273-
variant_hashes = gguf_variants._gguf_variant_blob_hashes(
273+
variant_hashes = gguf_variants.gguf_variant_blob_hashes(
274274
repo_id,
275275
variant,
276276
hf_token,
@@ -365,7 +365,7 @@ def _metadata_resolver(
365365
) -> tuple[int, frozenset[str]]:
366366
if progress_variant is None:
367367
return expected_total, frozenset()
368-
requirement = gguf_variants._gguf_variant_requirements(
368+
requirement = gguf_variants.gguf_variant_requirements(
369369
resolved_repo_id,
370370
progress_variant,
371371
token,
@@ -386,7 +386,7 @@ def _metadata_resolver(
386386
)
387387
return (
388388
expected_total,
389-
gguf_variants._gguf_variant_blob_hashes(
389+
gguf_variants.gguf_variant_blob_hashes(
390390
resolved_repo_id,
391391
progress_variant,
392392
token,

‎studio/backend/hub/services/models/gguf_variants.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def _build_gguf_variant_requirements(
187187
return build_gguf_variant_plans(siblings)
188188

189189

190-
def _gguf_variant_requirements(
190+
def gguf_variant_requirements(
191191
repo_id: str,
192192
variant: str,
193193
hf_token: Optional[str] = None,
@@ -265,7 +265,7 @@ def _manifest_variant_blob_hashes(
265265
return frozenset(hashes)
266266

267267

268-
def _gguf_variant_blob_hashes(
268+
def gguf_variant_blob_hashes(
269269
repo_id: str,
270270
variant: str,
271271
hf_token: Optional[str] = None,
@@ -293,7 +293,7 @@ def _gguf_variant_blob_hashes(
293293
requirement_key = _variant_hash_cache_key(repo_id, variant, hf_token)
294294
requirement = _variant_requirement_cache_get(requirement_key)
295295
if requirement is None and allow_remote:
296-
requirement = _gguf_variant_requirements(repo_id, variant, hf_token)
296+
requirement = gguf_variant_requirements(repo_id, variant, hf_token)
297297
if requirement is not None:
298298
hashes = (
299299
requirement.required_hashes
@@ -322,7 +322,7 @@ def delete_variant_incomplete_blobs_result(
322322
# a shared mmproj companion this variant also references is never unlinked
323323
# out from under the live sibling; the repo's last variant delete reclaims it.
324324
target_hashes = (
325-
_gguf_variant_blob_hashes(
325+
gguf_variant_blob_hashes(
326326
repo_id, variant, hf_token, include_companions = companions
327327
)
328328
| extra_hashes
@@ -611,7 +611,7 @@ def _is_fully_downloaded(variant) -> bool:
611611
requirement.main_hashes if requirement is not None else None
612612
)
613613
if variant_hashes is None and incomplete_hashes:
614-
variant_hashes = _gguf_variant_blob_hashes(
614+
variant_hashes = gguf_variant_blob_hashes(
615615
repo_id,
616616
variant.quant,
617617
hf_token,

‎studio/backend/hub/tests/test_model_services.py‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ def test_gguf_variant_blob_hashes_accept_dict_lfs_fallback(monkeypatch):
330330
),
331331
)
332332

333-
result = gguf_variants._gguf_variant_blob_hashes("Org/DictLfs", "Q4_K_M", None)
334-
main_only = gguf_variants._gguf_variant_blob_hashes(
333+
result = gguf_variants.gguf_variant_blob_hashes("Org/DictLfs", "Q4_K_M", None)
334+
main_only = gguf_variants.gguf_variant_blob_hashes(
335335
"Org/DictLfs",
336336
"Q4_K_M",
337337
None,
@@ -358,7 +358,7 @@ def test_gguf_variant_blob_hashes_skip_missing_rfilename(monkeypatch):
358358
),
359359
)
360360

361-
result = gguf_variants._gguf_variant_blob_hashes("Org/Malformed", "Q4_K_M", None)
361+
result = gguf_variants.gguf_variant_blob_hashes("Org/Malformed", "Q4_K_M", None)
362362

363363
assert result == frozenset({"main"})
364364

@@ -684,12 +684,12 @@ def _raise_permission_error(*_args, **_kwargs):
684684
monkeypatch.setattr(downloads.asyncio, "to_thread", _run_inline)
685685
monkeypatch.setattr(
686686
downloads.gguf_variants,
687-
"_gguf_variant_requirements",
687+
"gguf_variant_requirements",
688688
lambda *_args, **_kwargs: None,
689689
)
690690
monkeypatch.setattr(
691691
downloads.gguf_variants,
692-
"_gguf_variant_blob_hashes",
692+
"gguf_variant_blob_hashes",
693693
lambda *_args, **_kwargs: frozenset(),
694694
)
695695
monkeypatch.setattr(
@@ -800,7 +800,7 @@ async def _run_inline(fn, *args, **kwargs):
800800
monkeypatch.setattr(downloads.asyncio, "to_thread", _run_inline)
801801
monkeypatch.setattr(
802802
downloads.gguf_variants,
803-
"_gguf_variant_requirements",
803+
"gguf_variant_requirements",
804804
lambda *_args, **_kwargs: requirement,
805805
)
806806
monkeypatch.setattr(
@@ -889,7 +889,7 @@ async def _run_inline(fn, *args, **kwargs):
889889
monkeypatch.setattr(downloads.asyncio, "to_thread", _run_inline)
890890
monkeypatch.setattr(
891891
downloads.gguf_variants,
892-
"_gguf_variant_requirements",
892+
"gguf_variant_requirements",
893893
lambda *_args, **_kwargs: requirement,
894894
)
895895
monkeypatch.setattr(
@@ -965,7 +965,7 @@ async def _run_inline(fn, *args, **kwargs):
965965
monkeypatch.setattr(downloads.asyncio, "to_thread", _run_inline)
966966
monkeypatch.setattr(
967967
downloads.gguf_variants,
968-
"_gguf_variant_requirements",
968+
"gguf_variant_requirements",
969969
lambda *_args, **_kwargs: requirement,
970970
)
971971
monkeypatch.setattr(
@@ -1066,7 +1066,7 @@ async def _run_inline(fn, *args, **kwargs):
10661066
monkeypatch.setattr(downloads.asyncio, "to_thread", _run_inline)
10671067
monkeypatch.setattr(
10681068
downloads.gguf_variants,
1069-
"_gguf_variant_requirements",
1069+
"gguf_variant_requirements",
10701070
lambda *_args, **_kwargs: requirement,
10711071
)
10721072
monkeypatch.setattr(
@@ -1139,7 +1139,7 @@ async def _run_inline(fn, *args, **kwargs):
11391139
monkeypatch.setattr(downloads.asyncio, "to_thread", _run_inline)
11401140
monkeypatch.setattr(
11411141
downloads.gguf_variants,
1142-
"_gguf_variant_requirements",
1142+
"gguf_variant_requirements",
11431143
lambda *_args, **_kwargs: requirement,
11441144
)
11451145
monkeypatch.setattr(
@@ -1195,12 +1195,12 @@ async def _run_inline(fn, *args, **kwargs):
11951195
monkeypatch.setattr(downloads.asyncio, "to_thread", _run_inline)
11961196
monkeypatch.setattr(
11971197
downloads.gguf_variants,
1198-
"_gguf_variant_requirements",
1198+
"gguf_variant_requirements",
11991199
lambda *_args, **_kwargs: None,
12001200
)
12011201
monkeypatch.setattr(
12021202
downloads.gguf_variants,
1203-
"_gguf_variant_blob_hashes",
1203+
"gguf_variant_blob_hashes",
12041204
lambda *_args, **_kwargs: frozenset(),
12051205
)
12061206
monkeypatch.setattr(
@@ -1254,12 +1254,12 @@ async def _run_inline(fn, *args, **kwargs):
12541254
monkeypatch.setattr(downloads.asyncio, "to_thread", _run_inline)
12551255
monkeypatch.setattr(
12561256
downloads.gguf_variants,
1257-
"_gguf_variant_requirements",
1257+
"gguf_variant_requirements",
12581258
lambda *_args, **_kwargs: None,
12591259
)
12601260
monkeypatch.setattr(
12611261
downloads.gguf_variants,
1262-
"_gguf_variant_blob_hashes",
1262+
"gguf_variant_blob_hashes",
12631263
lambda *_args, **_kwargs: frozenset(),
12641264
)
12651265
monkeypatch.setattr(
@@ -1319,12 +1319,12 @@ async def _run_inline(fn, *args, **kwargs):
13191319
monkeypatch.setattr(downloads.asyncio, "to_thread", _run_inline)
13201320
monkeypatch.setattr(
13211321
downloads.gguf_variants,
1322-
"_gguf_variant_requirements",
1322+
"gguf_variant_requirements",
13231323
lambda *_args, **_kwargs: None,
13241324
)
13251325
monkeypatch.setattr(
13261326
downloads.gguf_variants,
1327-
"_gguf_variant_blob_hashes",
1327+
"gguf_variant_blob_hashes",
13281328
lambda *_args, **_kwargs: frozenset(),
13291329
)
13301330
monkeypatch.setattr(
@@ -2117,7 +2117,7 @@ async def _run_inline(fn, *args, **kwargs):
21172117
)
21182118
monkeypatch.setattr(
21192119
downloads.gguf_variants,
2120-
"_gguf_variant_blob_hashes",
2120+
"gguf_variant_blob_hashes",
21212121
lambda _repo, _variant, _token = None, include_companions = True, **_kwargs: (
21222122
frozenset({"mainhash", "mmprojhash"})
21232123
if include_companions
@@ -2210,7 +2210,7 @@ async def _run_inline(fn, *args, **kwargs):
22102210
)
22112211
monkeypatch.setattr(
22122212
downloads.gguf_variants,
2213-
"_gguf_variant_blob_hashes",
2213+
"gguf_variant_blob_hashes",
22142214
lambda _repo, _variant, _token = None, include_companions = True, **_kwargs: (
22152215
frozenset({"mainhash", "mmprojhash"})
22162216
if include_companions
@@ -2539,7 +2539,7 @@ def test_two_concurrent_same_repo_variants_both_complete(monkeypatch, tmp_path):
25392539
# Per-variant blob hashes (distinct main shard, shared mmproj companion).
25402540
monkeypatch.setattr(
25412541
downloads.gguf_variants,
2542-
"_gguf_variant_blob_hashes",
2542+
"gguf_variant_blob_hashes",
25432543
lambda _repo, variant, _token = None, include_companions = True, **_k: (
25442544
frozenset({f"{variant.lower()}-main", "shared-mmproj"})
25452545
if include_companions

‎studio/backend/hub/utils/download_registry.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,10 +1207,12 @@ def end_delete(self, repo_id: str, variant: Optional[str] = None) -> None:
12071207

12081208
def has_active_peer_variant(self, repo_id: str, variant: Optional[str]) -> bool:
12091209
"""Whether a DIFFERENT quantization of *repo_id* is downloading while
1210-
*variant* is being deleted. When one is, the delete must leave the shared
1211-
companion (mmproj) untouched for the live sibling and reclaim only this
1212-
variant's own files. Deterministic, so protection never depends on the
1213-
sibling having resolved its blob hashes."""
1210+
*variant* is being deleted. When one is, the delete reclaims only this
1211+
variant's own files and leaves the shared companion (mmproj) for the live
1212+
sibling. A point-in-time check (a sibling may claim just after it returns):
1213+
the finalized companion blob is held by deletion's reference-count walk,
1214+
and a sibling that starts mid-delete re-fetches the companion. Deterministic,
1215+
so protection never depends on the sibling having resolved its blob hashes."""
12141216
repo_id = normalize_repo_key(repo_id)
12151217
target = (variant or "").strip().lower() or None
12161218
with self._lock:

‎studio/backend/hub/utils/inventory_scan.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,17 @@ def resolve_snapshot_dir_for_scan(
183183
repo_id: str,
184184
repo_cache_dir: Optional[Path] = None,
185185
) -> Optional[Path]:
186-
"""Latest snapshot dir for a cache row, or across all HF cache roots.
186+
"""Latest snapshot dir for a cache row, or the first populated HF cache root.
187187
188188
Scanner-side counterpart to snapshot_download()'s return value
189189
(which the worker captured at download time but the scanner has
190-
no access to). Picks by mtime — same rule resolve_hf_cache_realpath
191-
uses and the same one huggingface_hub's from_pretrained resolves
192-
to. Preferred over reading refs/main because the user may have
193-
downloaded a specific commit that isn't the main ref; mtime is the
194-
more direct signal for "what just landed on disk".
190+
no access to). With a *repo_cache_dir*, returns its newest snapshot.
191+
Otherwise scans cache roots in priority order (active, then legacy,
192+
then default) and returns the newest snapshot within the first root
193+
that holds one — the active root is where snapshot_download writes,
194+
so it is authoritative. Within a root, picks by mtime (what
195+
from_pretrained resolves to), preferred over refs/main because the
196+
user may have downloaded a specific commit that isn't the main ref.
195197
"""
196198
if repo_cache_dir is not None:
197199
latest = latest_snapshot_dir(repo_cache_dir)

‎studio/backend/hub/workers/hf_download.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,11 @@ def _recover_manifest_after_download(
433433
metadata is still unavailable here, leftover ``.incomplete`` blobs prove
434434
snapshot_download returned a cached partial without downloading, so we fail
435435
(exit 1) instead of deriving a self-certifying manifest from the finalized
436-
subset. The partial is left intact for a later resume."""
436+
subset, leaving the partial intact for a later resume. That signal catches a
437+
partially written file but not one that never started (it leaves no
438+
``.incomplete``), so a kill between files is still accepted optimistically
439+
from the on-disk subset; a later metadata-bearing attempt writes the true
440+
manifest and verification catches any shortfall."""
437441
from hub.utils import download_manifest
438442
from hub.utils.hf_cache_state import has_active_incomplete_blobs
439443

‎studio/frontend/src/features/hub/catalog/external-link-confirm-dialog.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { useExternalLinkConfirm } from "../stores/external-link-confirm";
1919

2020
function hostOf(url: string): string {
2121
try {
22-
return new URL(url).host;
22+
return new URL(url, "https://_").host;
2323
} catch {
2424
return url;
2525
}

0 commit comments

Comments
 (0)