unslothai/unsloth · error · HTTPException

Failed to list local models: {str(e)}

Error message

Failed to list local models: {str(e)}

What it means

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.

Source

Thrown at studio/backend/hub/services/models/local_inventory.py:919

            hf_cache_dir,
            legacy_hf,
            hf_default,
            lm_dirs,
            ollama_dirs,
            known_hf_caches,
            custom_folders,
        )
        models = _dedupe_local_models(_filter_hidden_models(local_models))
        return LocalModelListResponse(
            models_dir = str(models_root),
            hf_cache_dir = str(hf_cache_dir),
            lmstudio_dirs = [str(d) for d in lm_dirs],
            ollama_dirs = [str(d) for d in ollama_dirs],
            models = models,
        )
    except Exception as e:
        logger.error(f"Error listing local models: {e}", exc_info = True)
        raise HTTPException(
            status_code = 500,
            detail = f"Failed to list local models: {str(e)}",
        )


async def list_local_models_response(models_dir: str = "./models") -> LocalModelListResponse:
    """Coalesce overlapping local inventory requests for the same models root."""

    def classify(response: LocalModelListResponse) -> LocalModelListResponse:
        # These rows feed the same pickers as /api/models/local. Classified inside the
        # shared worker so retrying waiters do not repeat GGUF metadata reads, and only
        # for a response that is actually about to be served.
        try:
            from routes.models import _local_model_task
            models = [
                model.model_copy(update = {"task": _local_model_task(model)})
                for model in response.models
            ]

View on GitHub (pinned to 203007d190)

Solutions

  1. Read the server log for the `Error listing local models:` line — the traceback names the failing scanner and file.
  2. Fix or remove the offending directory the traceback points at (permissions, corrupt file).
  3. Narrow the request: try the default models_dir only, then add sources back one at a time to isolate the failing source.
  4. If the traceback is inside studio code, report the bug with the traceback; this handler is a backstop, not expected flow.
Defensive patterns

Strategy: fallback

Try / catch

resp = client.get("/api/models/local")
if resp.status_code == 500:
    detail = resp.json()["detail"]
    # server log has the traceback under 'Error listing local models:'
    # degrade gracefully: show cached/last-known model list in the UI

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/d6f0c0b41230ada6. Report an issue: GitHub.