{"record":{"id":"2fe5fef16fa2945e","repo":"unslothai/unsloth","slug":"folder-nesting-exceeds-the-max-folder-depth-lev","errorCode":null,"errorMessage":"Folder nesting exceeds the {_MAX_FOLDER_DEPTH}-level scan limit","messagePattern":"Folder nesting exceeds the (.+?)-level scan limit","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/rag/folder_sync.py","lineNumber":962,"sourceCode":"                        not _is_within(root, resolved)\n                        or contains_sensitive_path_component(os.path.relpath(resolved, root))\n                        or is_denied_system_path(resolved)\n                    ):\n                        continue\n                    resolved_key = _path_key(resolved)\n                    if resolved_key in ancestor_paths:\n                        continue\n                    directory_stat = entry.stat(follow_symlinks = False)\n                    directory_identity = (directory_stat.st_dev, directory_stat.st_ino)\n                    identity_usable = directory_identity[1] not in (None, 0)\n                    if (\n                        identity_usable\n                        and directory_identity in ancestor_identities\n                        and (resolved_key in mount_points or os.path.ismount(full))\n                    ):\n                        continue\n                    if depth >= _MAX_FOLDER_DEPTH:\n                        raise RuntimeError(\n                            f\"Folder nesting exceeds the {_MAX_FOLDER_DEPTH}-level scan limit\"\n                        )\n                    child_identities = ancestor_identities\n                    if identity_usable:\n                        child_identities = ancestor_identities | {directory_identity}\n                    pending.append(\n                        (\n                            full,\n                            ancestor_paths | {resolved_key},\n                            child_identities,\n                            depth + 1,\n                        )\n                    )\n                    continue\n                if not entry.is_file(follow_symlinks = False):\n                    continue\n                if os.path.splitext(entry.name)[1].lower() not in config.UPLOAD_EXTS:\n                    continue","sourceCodeStart":944,"sourceCodeEnd":980,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/rag/folder_sync.py#L944-L980","documentation":"During the recursive directory walk in _scan, when a subdirectory is about to be queued at depth == _MAX_FOLDER_DEPTH (64), the scan aborts. The depth cap bounds work and stack growth in the pending-list BFS; loop protection via ancestor path/identity sets only shortcuts known cycles (mount-point aliases, resolved repeats), it does not authorize unbounded depth.","triggerScenarios":"A genuinely nested tree deeper than 64 levels under the linked root (e.g. node_modules-style nesting, recursive build output, deliberately generated deep chains); symlink-loop protection does not fire because symlinks are skipped, so this is real directory depth.","commonSituations":"Build artifacts (target/debug/...), pathological npm/cargo trees, a script bug that recursively copies a folder into itself (creating real, not symlinked, depth).","solutions":["Flatten or clean the deep subtree (delete runaway recursive copies such as folder/folder/folder/...).","Link a shallower subdirectory that excludes the deep chain instead of the whole tree.","If deeper trees are legitimate, raise _MAX_FOLDER_DEPTH in folder_sync.py consciously — the cap protects memory and job duration."],"exampleFix":"# before\ncreate_folder(..., path=\"/data/proj\")  # contains a 100-level self-copy chain\n\n# after\ncreate_folder(..., path=\"/data/proj/src\")  # shallow subtree, deep chain excluded","handlingStrategy":"validation","validationCode":"_MAX_FOLDER_DEPTH = 64\n\ndef tree_depth_ok(root: str, cap: int = _MAX_FOLDER_DEPTH) -> bool:\n    deepest = 0\n    stack = [(root, 0)]\n    while stack:\n        d, depth = stack.pop()\n        deepest = max(deepest, depth)\n        if depth >= cap:\n            return False\n        if os.path.isdir(d):\n            stack += [(os.path.join(d, e), depth + 1) for e in os.listdir(d)]\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    create_folder_with_sync(...)\nexcept RuntimeError as e:\n    if \"scan limit\" in str(e):\n        show_user(\"Folder tree is nested deeper than 64 levels; flatten or link a shallower folder.\")\n    else:\n        raise","preventionTips":["Check tree depth before linking very large trees.","Clean up accidental recursive self-copies (folder/folder/folder/...).","Link the specific subtree you need, not a monolithic root."],"tags":["rag","folder-sync","scan","limits","recursion"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}