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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: two edge failures the dependency-pass change left behind (#10915)
Daniel Han1336bd3f9be6
diff --git a/studio/backend/tests/test_transformers_version_optional_tiktoken.py b/studio/backend/tests/test_transformers_version_optional_tiktoken.pyindex 8eb56680c29..5e1c30a6960 100644--- a/studio/backend/tests/test_transformers_version_optional_tiktoken.py+++ b/studio/backend/tests/test_transformers_version_optional_tiktoken.py@@ -584,3 +584,59 @@ def test_a_recordless_record_beside_a_complete_install_is_removed_without_a_top_tv._top_up_optional_packages(str(root), ("tiktoken",))assert not stale.exists()assert (good / "RECORD").is_file()+++def test_an_unlockable_filesystem_is_not_waited_out(tmp_path, monkeypatch) -> None:+ """A mount that cannot lock answers at once. Retrying it spent the whole 120 second+ bound asleep inside a model activation, to arrive at the same answer."""+ import errno+ import fcntl+ import time as _time++ root = tmp_path / "sidecar"+ root.mkdir()+ attempts = []++ def unsupported(fd, op):+ attempts.append(op)+ raise OSError(errno.ENOTSUP, "locking not supported")++ slept = []+ monkeypatch.setattr(fcntl, "flock", unsupported)+ monkeypatch.setattr(_time, "sleep", lambda s: slept.append(s))+ monkeypatch.setattr(tv.time, "sleep", lambda s: slept.append(s))+ with tv._optional_top_up_lock(str(root)) as held:+ assert held is False+ assert len(attempts) == 1, f"asked {len(attempts)} times for an answer that cannot change"+ assert not slept, "waited on a filesystem that cannot lock"+++def test_an_interpreter_without_fcntl_does_not_break_activation(tmp_path, monkeypatch) -> None:+ """No fcntl and no msvcrt means no lock, which reads as someone else's turn, not a crash."""+ import builtins++ root = tmp_path / "sidecar"+ root.mkdir()+ real_import = builtins.__import__++ def no_fcntl(name, *args, **kwargs):+ if name in ("fcntl", "msvcrt"):+ raise ImportError(f"no {name} here")+ return real_import(name, *args, **kwargs)++ monkeypatch.setattr(builtins, "__import__", no_fcntl)+ with tv._optional_top_up_lock(str(root)) as held:+ assert held is False+++def test_a_close_that_fails_does_not_escape(tmp_path) -> None:+ class _Handle:+ closed = False++ def close(self):+ _Handle.closed = True+ raise OSError("close refused")++ tv._close_quietly(_Handle())+ assert _Handle.closed+ tv._close_quietly(None)diff --git a/studio/backend/utils/transformers_version.py b/studio/backend/utils/transformers_version.pyindex 46e85014493..e08eb482368 100644--- a/studio/backend/utils/transformers_version.py+++ b/studio/backend/utils/transformers_version.py@@ -34,6 +34,7 @@ import importlib.utilimport jsonimport structlogfrom loggers import get_logger+import errnoimport contextlibimport osimport re@@ -2701,6 +2702,23 @@ _OPTIONAL_TOP_UP_LOCK = ".optional-top-up.lock"_OPTIONAL_TOP_UP_WAIT_SECONDS = 120.0+# The errnos that mean a peer holds the lock. Anything else is a filesystem that cannot+# lock, and waiting on it only delays the same answer.+_LOCK_CONTENDED_ERRNOS = frozenset(+ {errno.EACCES, errno.EAGAIN, errno.EWOULDBLOCK, errno.EINTR, errno.EDEADLK}+)+++def _close_quietly(handle) -> None:+ """Drop the handle. Never raises: a close that fails must not fail an activation."""+ if handle is None:+ return+ try:+ handle.close()+ except OSError:+ pass++@contextlib.contextmanagerdef _optional_top_up_lock(venv_dir: str):"""A cross-process lock on a sidecar's optional top-up, waited for up to a bound.@@ -2726,13 +2744,19 @@ def _optional_top_up_lock(venv_dir: str):import fcntlfcntl.flock(handle.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)break- except OSError:+ except OSError as exc:+ # Only contention is worth waiting out. A mount that does not implement+ # locking answers at once, and retrying it spent the whole bound sleeping+ # inside a model activation before giving the same answer.+ if exc.errno not in _LOCK_CONTENDED_ERRNOS:+ raiseif time.monotonic() >= deadline:raisetime.sleep(0.25)- except OSError:- if handle is not None:- handle.close()+ except (OSError, ImportError):+ # ImportError too: an interpreter with neither fcntl nor msvcrt cannot lock, and an+ # activation must not die for it.+ _close_quietly(handle)yield Falsereturntry:@@ -2746,9 +2770,9 @@ def _optional_top_up_lock(venv_dir: str):else:import fcntlfcntl.flock(handle.fileno(), fcntl.LOCK_UN)- except OSError:+ except (OSError, ImportError):pass- handle.close()+ _close_quietly(handle)def _ensure_venv_dir(venv_dir: str, packages: tuple[str, ...], label: str) -> bool:diff --git a/studio/install_manifest.py b/studio/install_manifest.pyindex fe1c9dfe3aa..d20a7a08509 100644--- a/studio/install_manifest.py+++ b/studio/install_manifest.py@@ -529,6 +529,29 @@ def remove_manifest(root: Optional[Path] = None) -> bool:return _remove_manifest_locked(root, path, parked)+# What "not there" looks like, which is what pathlib ignored before 3.14: the name is absent,+# a path component is not a directory, the descriptor is bad, or a symlink chain does not land.+_ABSENT_ERRNOS = frozenset({errno.ENOENT, errno.ENOTDIR, errno.EBADF, errno.ELOOP})+++def manifest_is_present(path: Path) -> bool:+ """Whether *path* is there, answering True when the filesystem refuses to say.++ stat, not Path.exists(): 3.13 raises EACCES out of exists() and 3.14 returns False from it+ (gh-101357), so exists() means "absent" on one and "unknown" on the other. Every caller here+ is deciding whether a marker still blocks the pass, and a marker that cannot be read is+ still a marker. Never raises: remove_manifest reported a refusal before this existed.+ """+ try:+ path.stat()+ except OSError as exc:+ return exc.errno not in _ABSENT_ERRNOS+ except ValueError:+ # A path this interpreter cannot encode holds no manifest.+ return False+ return True++def _remove_manifest_locked(root: Optional[Path], path: Path, parked: Path) -> bool:try:os.replace(path, parked)@@ -538,14 +561,14 @@ def _remove_manifest_locked(root: Optional[Path], path: Path, parked: Path) -> b# reads it as evidence and refuses behind one it cannot clear -- on Windows after# setup.ps1's mutations. Losing a dead run's evidence only costs a full pass.consume_previous_manifest(root)- return not parked.exists()+ return not manifest_is_present(parked)except OSError:# The rename was refused. Clear the reserved name and retry before falling back to# the unlink: setup.ps1 reads True as permission to replace pip, torch and triton, and# the pass refuses behind a parked copy it cannot clear. Dropping the live manifest# first would put that refusal after the mutations, on a venv that cannot verify.consume_previous_manifest(root)- if parked.exists():+ if manifest_is_present(parked):return Falsetry:os.replace(path, parked)diff --git a/studio/install_python_stack.py b/studio/install_python_stack.pyindex 559c9fbe410..b6ef88b5d81 100644--- a/studio/install_python_stack.py+++ b/studio/install_python_stack.py@@ -9017,7 +9017,7 @@ def install_python_stack() -> int:# update stops at the same point._parked = install_manifest.previous_manifest_path()install_manifest.consume_previous_manifest()- if _parked.exists():+ if install_manifest.manifest_is_present(_parked):_safe_print(f"error: could not remove the parked {install_manifest.PREVIOUS_MANIFEST_NAME} "f"in {install_manifest.venv_root()}; refusing to install behind evidence the "@@ -9027,7 +9027,7 @@ def install_python_stack() -> int:return 1if install_manifest.remove_manifest():install_manifest.consume_previous_manifest()- if _parked.exists():+ if install_manifest.manifest_is_present(_parked):_safe_print(f"error: could not remove the parked {install_manifest.PREVIOUS_MANIFEST_NAME} "f"in {install_manifest.venv_root()}; refusing to install behind evidence the "diff --git a/tests/studio/install/test_dependency_pass_skips.py b/tests/studio/install/test_dependency_pass_skips.pyindex 65b8b4280dd..ad6568ae880 100644--- a/tests/studio/install/test_dependency_pass_skips.py+++ b/tests/studio/install/test_dependency_pass_skips.py@@ -2043,7 +2043,7 @@ def test_the_parked_manifest_goes_right_after_the_live_one_is_removed(monkeypatcassert "install_manifest.consume_previous_manifest()" in source[at : at + 200]# The path is bound above the removal so the same check can run BEFORE it as well; the# invariant here is that the parked copy is read for and gone within this window.- assert "_parked.exists()" in source[at : at + 400]+ assert "manifest_is_present(_parked)" in source[at : at + 400]def test_an_input_missing_from_the_record_or_unreadable_now_is_changed(monkeypatch, tmp_path):diff --git a/tests/studio/install/test_install_manifest_pass_evidence.py b/tests/studio/install/test_install_manifest_pass_evidence.pyindex 3197b8a0396..827d5630e8d 100644--- a/tests/studio/install/test_install_manifest_pass_evidence.py+++ b/tests/studio/install/test_install_manifest_pass_evidence.py@@ -1044,3 +1044,69 @@ def test_a_symlink_on_the_pass_lock_name_is_not_followed(tmp_path: pathlib.Path)with im.pass_lock(tmp_path) as uncontended:assert uncontended is Trueassert target.read_text(encoding = "utf-8") == "untouched"+++def test_remove_manifest_reports_a_refusal_rather_than_raising(tmp_path: pathlib.Path) -> None:+ """An unsearchable venv directory made Path.exists() raise EACCES straight out of+ remove_manifest. It returned False before the parked copy existed, and it must still."""+ if os.name == "nt" or os.geteuid() == 0:+ pytest.skip("needs POSIX permissions and a non-root user")+ root = tmp_path / "venv"+ root.mkdir()+ im.write_manifest(root = root, req_root = tmp_path, package_name = "pytest")+ os.chmod(root, 0o000)+ try:+ assert im.remove_manifest(root) is False+ finally:+ os.chmod(root, 0o755)+++def test_the_presence_check_answers_blocked_when_it_cannot_look(tmp_path: pathlib.Path) -> None:+ """Unknown reads as still there: every caller is asking whether a marker blocks the pass."""+ if os.name == "nt" or os.geteuid() == 0:+ pytest.skip("needs POSIX permissions and a non-root user")+ hidden = tmp_path / "hidden"+ hidden.mkdir()+ target = hidden / "unsloth_install_manifest.previous.json"+ target.write_text("{}", encoding = "utf-8")+ os.chmod(hidden, 0o000)+ try:+ assert im.manifest_is_present(target) is True+ finally:+ os.chmod(hidden, 0o755)+ assert im.manifest_is_present(tmp_path / "absent.json") is False+++ "code, expected",+ [+ (errno.ENOENT, False),+ (errno.ENOTDIR, False),+ (errno.EBADF, False),+ (errno.ELOOP, False),+ (errno.EACCES, True),+ (errno.EPERM, True),+ (errno.ESTALE, True),+ (errno.EIO, True),+ (errno.ETIMEDOUT, True),+ (errno.ENAMETOOLONG, True),+ ],+)+def test_the_presence_check_reads_the_errno_itself(monkeypatch, code, expected) -> None:+ """Not Path.exists(): 3.13 raises EACCES out of it and 3.14 returns False (gh-101357), so+ it means "absent" on one interpreter and "unknown" on the other. Only the four pathlib+ treated as absent before 3.14 are absent here; anything else is a marker still in place."""++ def refuse(self, *args, **kwargs):+ raise OSError(code, os.strerror(code))++ monkeypatch.setattr(pathlib.Path, "stat", refuse)+ assert im.manifest_is_present(pathlib.Path("/whatever")) is expected+++def test_a_path_this_interpreter_cannot_encode_holds_no_manifest(monkeypatch) -> None:+ def refuse(self, *args, **kwargs):+ raise ValueError("embedded null character")++ monkeypatch.setattr(pathlib.Path, "stat", refuse)+ assert im.manifest_is_present(pathlib.Path("/whatever")) is False