Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: fingerprint the same manifest scopes the downgrade migration scan reads (#16556)

Daniel Han94f23e0cf55e
diff --git a/studio/backend/hub/utils/download_manifest.py b/studio/backend/hub/utils/download_manifest.py
index 983651c830b..aa34d2d1a5a 100644
--- a/studio/backend/hub/utils/download_manifest.py
+++ b/studio/backend/hub/utils/download_manifest.py
@@ -660,13 +660,14 @@ def _read_migration_payload(path: Path) -> Optional[dict]:
return data if isinstance(data, dict) else None
+def _folded(name: str) -> str:
+ # Folded on Windows, as pathlib's glob is.
+ return name.casefold() if os.name == "nt" else name
+
+
def _listed(directory: Path) -> list[tuple[str, str]]:
- # Eager, and folded on Windows, as pathlib's glob is.
with os.scandir(directory) as entries:
- return [
- (entry.name, entry.name.casefold() if os.name == "nt" else entry.name)
- for entry in entries
- ]
+ return [(entry.name, _folded(entry.name)) for entry in entries]
def _migration_manifest_paths(parent: Path, failed: list) -> Iterator[Path]:
@@ -703,11 +704,14 @@ def _migration_fingerprint(parent: Path, scopes: Optional[Iterable[str]] = None)
active, raw = _hub_cache_spellings(None)
dirs = {".": os.stat(parent).st_mtime_ns}
if scopes is None:
- scopes = [
- entry.name
- for entry in os.scandir(parent)
- if entry.name.startswith("cache-") and entry.is_dir(follow_symlinks = False)
- ]
+ # Same name match as the scan, so a scope it reads is always fingerprinted.
+ with os.scandir(parent) as entries:
+ scopes = [
+ entry.name
+ for entry in entries
+ if _folded(entry.name).startswith("cache-")
+ and entry.is_dir(follow_symlinks = False)
+ ]
for name in scopes:
st = os.lstat(parent / name)
if not stat.S_ISDIR(st.st_mode):
diff --git a/studio/backend/tests/test_manifest_migration_marker.py b/studio/backend/tests/test_manifest_migration_marker.py
index db13c63c947..dd3fca16c29 100644
--- a/studio/backend/tests/test_manifest_migration_marker.py
+++ b/studio/backend/tests/test_manifest_migration_marker.py
@@ -331,3 +331,28 @@ def test_marker_check_error_falls_back_to_the_full_scan(home, monkeypatch):
monkeypatch.setattr(download_manifest, "_migration_already_clean", boom)
assert download_manifest.migrate_ordinary_v2_manifests_for_downgrade() >= 3
assert not _marker().exists()
+
+
+def test_scope_matched_only_when_folded_is_fingerprinted(home, monkeypatch):
+ # The scan reads a ``Cache-*`` scope on Windows, so the fingerprint must cover it too.
+ monkeypatch.setattr(download_manifest, "_folded", str.casefold)
+ _populate(home)
+ hand = home.root / "hand-hub"
+ hand.mkdir()
+ _write("Org/Hand", 2, hub_cache = hand)
+ written = download_manifest.manifest_path("model", "Org/Hand", None, hub_cache = hand)
+ payload = written.read_bytes()
+ shutil.rmtree(written.parent)
+ folded_scope = state_dir.manifests_dir() / "Cache-Hand"
+ folded_scope.mkdir()
+ download_manifest.migrate_ordinary_v2_manifests_for_downgrade()
+ _settle(state_dir.manifests_dir())
+ download_manifest.migrate_ordinary_v2_manifests_for_downgrade()
+ assert "Cache-Hand" in json.loads(_marker().read_text(encoding = "utf-8"))["dirs"]
+
+ calls = _count_reads(monkeypatch)
+ staged = folded_scope / "late.json.tmp"
+ staged.write_bytes(payload)
+ os.replace(staged, folded_scope / "late.json")
+ download_manifest.migrate_ordinary_v2_manifests_for_downgrade()
+ assert folded_scope / "late.json" in calls