{"record":{"id":"6c4fddc7007b329d","repo":"unslothai/unsloth","slug":"local-cache-path-is-too-long-max-4096-chars","errorCode":null,"errorMessage":"local cache path is too long (max 4096 chars)","messagePattern":"local cache path is too long \\(max 4096 chars\\)","errorType":"validation","errorClass":"ValueError","httpStatus":422,"severity":"error","filePath":"studio/backend/models/training.py","lineNumber":268,"sourceCode":"        if not valid_hf_dataset_config_name(v):\n            raise ValueError(\"subset contains invalid characters\")\n        return v\n\n    @field_validator(\n        \"model_local_path\",\n        \"dataset_local_path\",\n        \"model_snapshot_path\",\n        \"dataset_snapshot_path\",\n    )\n    @classmethod\n    def _check_cache_local_path(cls, v: Optional[str]) -> Optional[str]:\n        if v is None:\n            return v\n        v = v.strip()\n        if not v:\n            return None\n        if len(v) > 4096:\n            raise ValueError(\"local cache path is too long (max 4096 chars)\")\n        if \"\\x00\" in v:\n            raise ValueError(\"local cache path contains invalid characters\")\n        if \"..\" in Path(v).parts or \"..\" in PureWindowsPath(v).parts:\n            raise ValueError(\"local cache path must not contain '..' segments\")\n        return v\n\n    @field_validator(\"train_split\", \"eval_split\")\n    @classmethod\n    def _check_split_name(cls, v: Optional[str]) -> Optional[str]:\n        if v is None:\n            return v\n        v = v.strip()\n        if not v:\n            return None\n        if len(v) > MAX_HF_DATASET_OPTION_LENGTH:\n            raise ValueError(f\"split name is too long (max {MAX_HF_DATASET_OPTION_LENGTH} chars)\")\n        if not valid_hf_dataset_split_instruction(v):\n            raise ValueError(\"split name contains invalid characters\")","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/models/training.py#L250-L286","documentation":"Raised by the _check_cache_local_path field validator, which applies to four fields (model_local_path, dataset_local_path, model_snapshot_path, dataset_snapshot_path). These server-side cache paths are capped at 4096 characters after trimming — beyond the common PATH_MAX bound, so the OS would reject them anyway; validating here gives a clean 422 instead of a deep filesystem error. Empty-after-trim normalizes to None.","triggerScenarios":"POST a training start request with any of the four path fields exceeding 4096 chars, e.g. a path that has been repeatedly re-joined onto itself or contains a huge base64 blob.","commonSituations":"Loop bugs that append a directory each iteration; embedding non-path payloads into a path field; extremely deep workspace trees; client mapping the wrong object into the path field.","solutions":["Fix the path construction bug producing the over-long value; the real paths should be short server cache locations.","If these fields are meant to be left to the server, omit them entirely.","Add a client-side length assertion on path fields before submit to catch runaway concatenation early."],"exampleFix":"# before (loop appends each time)\npath = f\"{path}/{run_id}\"  # grows unbounded\n# after\npath = base_cache_dir / run_id","handlingStrategy":"validation","validationCode":"PATH_FIELDS = (\"model_local_path\", \"dataset_local_path\", \"model_snapshot_path\", \"dataset_snapshot_path\")\n\ndef paths_short_enough(body: dict) -> bool:\n    return all(len((body.get(f) or \"\").strip()) <= 4096 for f in PATH_FIELDS)","typeGuard":"const PATH_FIELDS = ['model_local_path','dataset_local_path','model_snapshot_path','dataset_snapshot_path'] as const;\nfunction pathsOk(body: Record<string, string | undefined>): boolean {\n  return PATH_FIELDS.every(f => (body[f]?.trim().length ?? 0) <= 4096);\n}","tryCatchPattern":null,"preventionTips":["Omit cache-path fields when the server can derive them","Watch for runaway path concatenation in loops","Assert path length in request builders"],"tags":["pydantic","validation","training","filesystem","paths"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}