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: do not fail a cached dataset load on a bookkeeping write (#8057)
BardiaKoopah7617fc398205
diff --git a/studio/backend/hub/utils/dataset_cache.py b/studio/backend/hub/utils/dataset_cache.pyindex 03bb7755944..c1ad69372e8 100644--- a/studio/backend/hub/utils/dataset_cache.py+++ b/studio/backend/hub/utils/dataset_cache.py@@ -11,7 +11,10 @@ import tempfilefrom pathlib import Path, PurePosixPathfrom typing import Any, Optional+from loggers import get_logger+from hub.utils.dataset_processed_cache import (+ UnsafeDatasetCachePathError,mark_app_processed_dataset_cache_complete,normalized_commit_hash,prepare_app_processed_dataset_cache,@@ -24,6 +27,7 @@ from hub.utils.hf_cache_state import ()from utils.paths.path_utils import drop_appledouble_metadata, is_appledouble_metadata+logger = get_logger(__name__)TRAINING_DATA_EXTS = (".parquet", ".json", ".jsonl", ".csv")@@ -559,7 +563,17 @@ def load_cached_hf_dataset()dataset = load_dataset(**kwargs)if app_cache is not None:- mark_app_processed_dataset_cache_complete(app_cache)+ # Advisory flag: a purged entry, read-only home or full disk must not discard a loaded dataset.+ try:+ mark_app_processed_dataset_cache_complete(app_cache)+ except UnsafeDatasetCachePathError:+ raise+ except (OSError, RuntimeError, ValueError):+ logger.warning(+ "Could not record processed dataset cache completion for %s",+ repo_id,+ exc_info = True,+ )return datasetdiff --git a/studio/backend/hub/utils/dataset_processed_cache.py b/studio/backend/hub/utils/dataset_processed_cache.pyindex c18cbe40bcc..d0a6ec3a0be 100644--- a/studio/backend/hub/utils/dataset_processed_cache.py+++ b/studio/backend/hub/utils/dataset_processed_cache.py@@ -20,6 +20,10 @@ _CACHE_DIRNAME = "snapshot-loads"_METADATA_FILENAME = "metadata.json"+class UnsafeDatasetCachePathError(OSError):+ """Cache entry is a symlink or escapes the cache root; unlike other OSErrors, never best effort."""++@dataclass(frozen = True)class AppProcessedDatasetCache:repo_id: str@@ -183,10 +187,14 @@ def mark_app_processed_dataset_cache_complete(entry: AppProcessedDatasetCache) -root = _resolved_app_processed_dataset_cache_root(create = False)if root is None:raise OSError("Dataset cache root is unavailable")- entry_path = entry.path.resolve(strict = True)- entry_path.relative_to(root)+ # Before resolve: a dangling swapped-in symlink would otherwise surface as FileNotFoundError.if entry.path.is_symlink() or entry.cache_dir.is_symlink():- raise OSError(f"Dataset cache path is a symlink: {entry.path}")+ raise UnsafeDatasetCachePathError(f"Dataset cache path is a symlink: {entry.path}")+ entry_path = entry.path.resolve(strict = True)+ if not entry_path.is_relative_to(root):+ raise UnsafeDatasetCachePathError(+ f"Dataset cache entry escapes the cache root: {entry.path}"+ )_atomic_write_metadata(entry_path / _METADATA_FILENAME,_metadata_payload(diff --git a/studio/backend/tests/test_dataset_cache_paths.py b/studio/backend/tests/test_dataset_cache_paths.pyindex 0b5eda0f9fa..c5f5c69fa69 100644--- a/studio/backend/tests/test_dataset_cache_paths.py+++ b/studio/backend/tests/test_dataset_cache_paths.py@@ -4,6 +4,7 @@import errnoimport jsonimport os+import shutilimport sysimport timeimport types@@ -871,6 +872,54 @@ def test_app_processed_cache_is_deterministic_and_discoverable(monkeypatch, tmp_assert list(dataset_processed_cache.iter_app_processed_dataset_caches()) == [second]+def _loaded_entry(tmp_path):+ _, snapshot = _dataset_repo(tmp_path, "Org/Data", "commit-a")+ (snapshot / "train.parquet").write_bytes(b"rows")+ return snapshot++[email protected]("purge", ["entry", "root"])+def test_cached_load_survives_a_failed_completion_write(monkeypatch, tmp_path, purge):+ snapshot = _loaded_entry(tmp_path)+ calls = _fake_datasets(monkeypatch)+ real_load = sys.modules["datasets"].load_dataset++ def _load_then_purge(**kwargs):+ shutil.rmtree(+ Path(kwargs["cache_dir"]).parent+ if purge == "entry"+ else dataset_processed_cache.app_processed_dataset_cache_root()+ )+ return real_load(**kwargs)++ monkeypatch.setattr(sys.modules["datasets"], "load_dataset", _load_then_purge)++ result = dataset_cache.load_cached_hf_dataset(+ "Org/Data", str(snapshot), subset = None, split = "train"+ )++ assert result == {"loaded": True}+ assert len(calls) == 1+++def test_cached_load_still_fails_on_a_dangling_symlinked_entry(monkeypatch, tmp_path):+ snapshot = _loaded_entry(tmp_path)+ _fake_datasets(monkeypatch)+ real_load = sys.modules["datasets"].load_dataset+ external = tmp_path / "external"++ def _load_then_swap(**kwargs):+ entry = Path(kwargs["cache_dir"]).parent+ shutil.rmtree(entry)+ entry.symlink_to(external, target_is_directory = True)+ return real_load(**kwargs)++ monkeypatch.setattr(sys.modules["datasets"], "load_dataset", _load_then_swap)++ with pytest.raises(dataset_processed_cache.UnsafeDatasetCachePathError):+ dataset_cache.load_cached_hf_dataset("Org/Data", str(snapshot), subset = None, split = "train")++def test_app_processed_cache_rejects_symlinked_parent(monkeypatch, tmp_path):repo_id = "Org/Data"_, snapshot = _dataset_repo(tmp_path, repo_id, "commit-a")