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: exempt shared top-level trees from the integrity check for our own wheels too (#8179)

Daniel Hanc2c16b7293bf
diff --git a/studio/backend/tests/test_transformers_version.py b/studio/backend/tests/test_transformers_version.py
index d1cdf6be0f5..63610909dbe 100644
--- a/studio/backend/tests/test_transformers_version.py
+++ b/studio/backend/tests/test_transformers_version.py
@@ -1894,6 +1894,28 @@ class TestVenvDirFileIntegrity:
)
assert _venv_dir_is_valid_and_undamaged(str(venv_dir), ("transformers==5.3.0",))
+ def test_shared_non_runtime_rows_are_ignored_for_our_own_wheels_too(self, tmp_path: Path):
+ """Unreliable ownership is a property of the path, not of the claimant.
+ unsloth_zoo <= 2026.8.5 shipped a top-level tests/ into the same squatted
+ namespace, so exempting only third parties left it reported forever."""
+ venv_dir = self._make_venv(
+ tmp_path / "venv",
+ pkg = "unsloth_zoo",
+ record_extra = ["tests/conftest.py,sha256=deadbeef,11429"],
+ )
+ assert _venv_dir_is_valid_and_undamaged(str(venv_dir), ("unsloth_zoo==5.3.0",))
+
+ def test_our_own_runtime_tree_is_still_checked(self, tmp_path: Path):
+ """Only the shared roots are exempt. A tests/ tree inside our package is
+ ours alone, so damage there still forces the wipe-and-reinstall."""
+ venv_dir = self._make_venv(
+ tmp_path / "venv",
+ pkg = "unsloth_zoo",
+ files = {"unsloth_zoo/__init__.py": "x" * 40, "unsloth_zoo/tests/h.py": "y" * 10},
+ )
+ (venv_dir / "unsloth_zoo" / "tests" / "h.py").unlink()
+ assert not _venv_dir_is_valid_and_undamaged(str(venv_dir), ("unsloth_zoo==5.3.0",))
+
def test_an_installer_rewritten_file_keeps_its_existence_check(self, tmp_path: Path):
"""setup.ps1 runs npm install in the installed tree, so the lockfile's
recorded size drifts. npm never deletes it, so only the size is dropped."""
diff --git a/studio/backend/utils/transformers_version.py b/studio/backend/utils/transformers_version.py
index e44e4cc9489..e0fd6d2b5f5 100644
--- a/studio/backend/utils/transformers_version.py
+++ b/studio/backend/utils/transformers_version.py
@@ -2000,7 +2000,6 @@ _SHARED_NON_RUNTIME_ROOTS = frozenset(
)
)
_INSTALLER_REWRITTEN_NAMES = frozenset(("package-lock.json",))
-_OUR_DISTRIBUTIONS = frozenset(("unsloth", "unsloth-zoo", "unsloth-studio"))
def _sidecar_damaged_files(venv_dir: str, limit: int = 3) -> list[str]:
@@ -2096,14 +2095,10 @@ def _sidecar_scan_impl(venv_dir: str, limit: int = 3) -> tuple[list[str], bool]:
or (parts and parts[0] in ("bin", "Scripts"))
):
continue
- # Third-party top-level dirs several wheels write into, so one uninstall
- # deletes another's files. Never applied to what we ship: a missing
- # __init__.py does not make a directory unimportable (PEP 420).
- if (
- len(parts) > 1
- and parts[0] in _SHARED_NON_RUNTIME_ROOTS
- and name.replace("_", "-").lower() not in _OUR_DISTRIBUTIONS
- ):
+ # Top-level dirs several wheels write into, so one uninstall deletes
+ # another's files. Unreliable ownership is a property of the path, so
+ # this covers what we ship too; see _shared_non_runtime in _studio_deps.
+ if len(parts) > 1 and parts[0] in _SHARED_NON_RUNTIME_ROOTS:
continue
# The size field is optional and real wheels do leave it blank. Keep the row with an
# unknown size: existence is still checkable, and dropping it hides a deletion.
diff --git a/unsloth_cli/_studio_deps.py b/unsloth_cli/_studio_deps.py
index cf36c8c6576..9385a6951f0 100644
--- a/unsloth_cli/_studio_deps.py
+++ b/unsloth_cli/_studio_deps.py
@@ -220,7 +220,8 @@ def _scan_paths() -> Dict[str, list]:
# Top-level dirs several wheels write into, so one uninstall deletes another's
# files and the survivor's RECORD describes a file nothing recreates. einx and
# torchao both ship test/conftest.py, and install_python_stack.py
-# force-reinstalls torchao every update.
+# force-reinstalls torchao every update; unsloth_zoo <= 2026.8.5 shipped
+# tests/ and scripts/ into the same squatted namespace.
_SHARED_NON_RUNTIME_ROOTS = frozenset(
(
"test",
@@ -243,28 +244,23 @@ _SHARED_NON_RUNTIME_ROOTS = frozenset(
_INSTALLER_REWRITTEN_NAMES = frozenset(("package-lock.json",))
-def _shared_non_runtime(rel: str, name: str) -> bool:
- """A third-party row under a top-level dir several wheels write into.
+def _shared_non_runtime(rel: str) -> bool:
+ """A row under a top-level dir several wheels write into.
Ownership of these is unreliable: whichever wheel installed last wins, and
- any of them uninstalling takes the others' files with it. Never applied to
- what we ship, because a missing __init__.py does NOT make a directory
- unimportable (PEP 420) and this repo imports scripts.* itself, so our own
- top-level trees stay checked. Applied while reading RECORD, not when
- reporting, so the row also stays out of the ownership tally and the `limit`
- budget.
+ any of them uninstalling takes the others' files with it. That is a property
+ of the path, not of the distribution claiming it, so it holds for what we
+ ship too: unsloth_zoo <= 2026.8.5 packaged a top-level tests/ and scripts/,
+ nothing imports either at runtime, and a clobbered copy wedged every update
+ with `unsloth_zoo: tests/conftest.py is 8107 bytes, expected 11429`. Our
+ runtime trees are unaffected, since none of them is named for a shared root.
+ Applied while reading RECORD, not when reporting, so the row also stays out
+ of the ownership tally and the `limit` budget.
"""
- if _canonical(name) in _OUR_DISTRIBUTIONS:
- return False
parts = tuple(p for p in rel.replace("\\", "/").split("/") if p and p != ".")
return len(parts) > 1 and parts[0] in _SHARED_NON_RUNTIME_ROOTS
-# What Unsloth ships. Its top-level trees are ours to guarantee, so they are
-# never exempted however they are named.
-_OUR_DISTRIBUTIONS = frozenset(("unsloth", "unsloth-zoo", "unsloth-studio"))
-
-
def _installer_rewritten(rel: str) -> bool:
"""A file our own setup rewrites in place, so its recorded size drifts.
@@ -335,7 +331,7 @@ def damaged_installed_files(limit: int = 8) -> List[str]:
# size recorded inside itself; .pyc is regenerated from source.
if ".dist-info/" in rel or ".egg-info/" in rel or rel.endswith(".pyc"):
continue
- if _shared_non_runtime(rel, name):
+ if _shared_non_runtime(rel):
continue
# The size field is optional and real wheels do leave it blank. Keep
# the row anyway with an unknown size: existence is still checkable,
diff --git a/unsloth_cli/tests/test_studio_update_verify.py b/unsloth_cli/tests/test_studio_update_verify.py
index 97709912e3a..68f88c0d749 100644
--- a/unsloth_cli/tests/test_studio_update_verify.py
+++ b/unsloth_cli/tests/test_studio_update_verify.py
@@ -689,13 +689,40 @@ def test_ignored_rows_do_not_consume_the_finding_budget(site):
assert len(found) == 1 and "tau/__init__.py is missing" in found[0]
-def test_our_own_top_level_trees_are_still_checked(site):
- # A missing __init__.py does not make a directory unimportable (PEP 420),
- # and this repo imports scripts.* itself, so the shared-namespace exemption
- # must never apply to what Unsloth ships.
+def test_our_own_shared_top_level_trees_are_exempt_too(site):
+ # Reported as `unsloth_zoo: tests/conftest.py is 8107 bytes, expected 11429`
+ # on an install that was already current, so the update failed on every
+ # retry. 11429 is the size in the 2026.8.5 wheel, which shipped a top-level
+ # tests/ that any other wheel using that name overwrites. Squatting the
+ # namespace does not make it ours, and nothing imports it at runtime.
+ conftest = "tests/conftest.py"
+ _make_dist(
+ site,
+ "unsloth_zoo",
+ {"unsloth_zoo/__init__.py": b"z\n", conftest: b"c" * 8107},
+ record_sizes = {conftest: 11429},
+ )
+ assert _deps().damaged_installed_files() == []
+
+
+def test_our_own_shared_top_level_trees_may_also_vanish(site):
+ # Same path, deleted rather than overwritten: the einx shape, but claimed by
+ # a distribution of ours. No reinstall repairs it either.
_make_dist(site, "unsloth_zoo", {"unsloth_zoo/__init__.py": b"z\n"})
(site / "unsloth_zoo-1.0.dist-info" / "RECORD").write_text(
"unsloth_zoo/__init__.py,sha256=x,2\nscripts/helper.py,sha256=x,99\n"
)
+ assert _deps().damaged_installed_files() == []
+
+
+def test_our_own_runtime_trees_are_still_checked(site):
+ # The exemption is scoped to the shared roots. Everything Unsloth actually
+ # imports lives outside them and must still fail an update when damaged.
+ _make_dist(
+ site,
+ "unsloth_zoo",
+ {"unsloth_zoo/__init__.py": b"z\n", "unsloth_zoo/tests/helper.py": b"h\n"},
+ )
+ (site / "unsloth_zoo" / "tests" / "helper.py").unlink()
found = _deps().damaged_installed_files()
- assert len(found) == 1 and "scripts/helper.py is missing" in found[0]
+ assert len(found) == 1 and "unsloth_zoo/tests/helper.py is missing" in found[0]