{"record":{"id":"d6f0c0b41230ada6","repo":"unslothai/unsloth","slug":"failed-to-list-local-models-str-e","errorCode":null,"errorMessage":"Failed to list local models: {str(e)}","messagePattern":"Failed to list local models: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"studio/backend/hub/services/models/local_inventory.py","lineNumber":919,"sourceCode":"            hf_cache_dir,\n            legacy_hf,\n            hf_default,\n            lm_dirs,\n            ollama_dirs,\n            known_hf_caches,\n            custom_folders,\n        )\n        models = _dedupe_local_models(_filter_hidden_models(local_models))\n        return LocalModelListResponse(\n            models_dir = str(models_root),\n            hf_cache_dir = str(hf_cache_dir),\n            lmstudio_dirs = [str(d) for d in lm_dirs],\n            ollama_dirs = [str(d) for d in ollama_dirs],\n            models = models,\n        )\n    except Exception as e:\n        logger.error(f\"Error listing local models: {e}\", exc_info = True)\n        raise HTTPException(\n            status_code = 500,\n            detail = f\"Failed to list local models: {str(e)}\",\n        )\n\n\nasync def list_local_models_response(models_dir: str = \"./models\") -> LocalModelListResponse:\n    \"\"\"Coalesce overlapping local inventory requests for the same models root.\"\"\"\n\n    def classify(response: LocalModelListResponse) -> LocalModelListResponse:\n        # These rows feed the same pickers as /api/models/local. Classified inside the\n        # shared worker so retrying waiters do not repeat GGUF metadata reads, and only\n        # for a response that is actually about to be served.\n        try:\n            from routes.models import _local_model_task\n            models = [\n                model.model_copy(update = {\"task\": _local_model_task(model)})\n                for model in response.models\n            ]","sourceCodeStart":901,"sourceCodeEnd":937,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/hub/services/models/local_inventory.py#L901-L937","documentation":"HTTP 500 catch-all from the local-models listing endpoint: any exception thrown while collecting models from the default sources (models root, HF cache, LM Studio dirs, Ollama dirs, known HF caches) that is not the 403 case escapes to this handler. The original exception is logged with a full traceback (logger.error ... exc_info=True) and surfaced in the detail string.","triggerScenarios":"A scanner crashing on corrupt GGUF metadata, an unreadable subdirectory inside the HF cache that bypasses the per-source _scan_source guard, a bug in dedupe/filtering, or disk errors while walking a source directory.","commonSituations":"Intermittent 500s when one model directory in the cache has odd permissions; a partially-written download leaving a malformed file a scanner chokes on; after upgrading studio when response model fields changed.","solutions":["Read the server log for the `Error listing local models:` line — the traceback names the failing scanner and file.","Fix or remove the offending directory the traceback points at (permissions, corrupt file).","Narrow the request: try the default models_dir only, then add sources back one at a time to isolate the failing source.","If the traceback is inside studio code, report the bug with the traceback; this handler is a backstop, not expected flow."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"resp = client.get(\"/api/models/local\")\nif resp.status_code == 500:\n    detail = resp.json()[\"detail\"]\n    # server log has the traceback under 'Error listing local models:'\n    # degrade gracefully: show cached/last-known model list in the UI","preventionTips":["Keep model cache directories readable by the backend user so scanners never crash mid-walk.","Alert on the 'Error listing local models' log line — the exc_info traceback identifies the root cause fast.","Cache the last successful model list client-side so one bad directory doesn't blank the picker."],"tags":["http-500","catch-all","local-models","logging"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}