{"record":{"id":"18e570563b5daf5c","repo":"unslothai/unsloth","slug":"the-cached-spec-name-source-failed-integrity-val","errorCode":null,"errorMessage":"The cached {spec.name} source failed integrity validation","messagePattern":"The cached (.+?) source failed integrity validation","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"studio/backend/utils/third_party_source.py","lineNumber":751,"sourceCode":"            if generated.read_bytes() != content:\n                return False\n        manifest = _runtime_manifest(runtime, spec)\n        if spec.runtime_tree_digest is not None:\n            return _manifest_digest(manifest) == spec.runtime_tree_digest\n        return checkout is not None and manifest == _expected_runtime_manifest(checkout, spec)\n    except (OSError, RuntimeError, ValueError):\n        return False\n\n\ndef _install_runtime(runtime: Path, checkout: Path, spec: PinnedSource) -> None:\n    workspace = Path(tempfile.mkdtemp(prefix = \".runtime-\", dir = runtime.parent))\n    staging = workspace / \"runtime\"\n    staging.mkdir()\n    try:\n        if spec.source_tree_digest is not None:\n            source_manifest = _sealed_source_manifest(checkout, spec)\n            if source_manifest is None:\n                raise RuntimeError(f\"The cached {spec.name} source failed integrity validation\")\n        else:\n            source_manifest = _checkout_manifest(checkout, spec)\n        for relative, expected_digest in source_manifest.items():\n            source_file = checkout / relative\n            destination_file = staging / relative\n            destination_file.parent.mkdir(parents = True, exist_ok = True)\n            shutil.copy2(source_file, destination_file)\n            if hashlib.sha256(destination_file.read_bytes()).hexdigest() != expected_digest:\n                raise RuntimeError(f\"{spec.name} source changed while preparing its runtime\")\n        for relative, content in _generated_file_contents(spec).items():\n            destination_file = staging / relative\n            destination_file.parent.mkdir(parents = True, exist_ok = True)\n            destination_file.write_bytes(content)\n        if not _valid_runtime(staging, spec, checkout):\n            raise RuntimeError(f\"The prepared {spec.name} runtime failed integrity validation\")\n        _replace_owned_directory(staging, runtime)\n    finally:\n        _remove_owned_path(workspace)","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/utils/third_party_source.py#L733-L769","documentation":"In _install_runtime, before copying files from the cached checkout into a fresh runtime staging dir, the checkout is re-validated with _sealed_source_manifest(checkout, spec); None means the on-disk cache no longer matches spec.source_tree_digest. The runtime build refuses to consume a cache that has drifted or been corrupted since installation.","triggerScenarios":"ensure_pinned_source reaches runtime preparation (runtime dir absent/invalid) and the previously installed checkout under cache_root()/third-party-sources/<name>/<revision>/source fails digest re-validation — files were modified, deleted, partially written, or replaced on disk.","commonSituations":"A build/tool/IDE wrote into the cached source tree; antivirus or sync tools (Dropbox/OneDrive) altered files; interrupted prior install left a half-populated cache; disk corruption; someone tampered with the cache deliberately.","solutions":["Clear the cache for that spec: remove cache_root()/third-party-sources/<spec.name> and let ensure_pinned_source re-download and re-verify from scratch","Audit what mutated the tree (mtimes, auditd) if it recurs — a process writing into the cache is the root cause","Exclude the cache directory from sync/AV scanning","After a clean re-download the digest check should pass; if it does not, the pin digest itself is wrong (see 1595)"],"exampleFix":"# before: recurring failure from mutated cache\nensure_pinned_source(spec)  # raises: cached source failed integrity validation\n\n# after: purge the spec's cache slice and rebuild\nimport shutil\nshutil.rmtree(cache_root() / \"third-party-sources\" / spec.name, ignore_errors=True)\nruntime = ensure_pinned_source(spec)","handlingStrategy":"fallback","validationCode":"from studio.backend.utils.third_party_source import _sealed_source_manifest, cache_root\ncheckout = cache_root() / \"third-party-sources\" / spec.name / spec.revision / \"source\"\nif spec.source_tree_digest is not None and _sealed_source_manifest(checkout, spec) is None:\n    shutil.rmtree(cache_root() / \"third-party-sources\" / spec.name)  # purge and let it re-fetch","typeGuard":null,"tryCatchPattern":"try:\n    runtime = ensure_pinned_source(spec)\nexcept RuntimeError as e:\n    if \"cached\" in str(e) and \"integrity\" in str(e):\n        shutil.rmtree(cache_root() / \"third-party-sources\" / spec.name, ignore_errors=True)\n        runtime = ensure_pinned_source(spec)  # fallback: rebuild cache from canonical source","preventionTips":["Make the cache directory read-only after installation so nothing can mutate it","Exclude the cache from sync tools and antivirus real-time scanning"],"tags":["cache","integrity","digest","pinned-source","filesystem"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}