jamiepine/voicebox · warning · HTTPException

Model {model_name} not found in cache

Error message

Model {model_name} not found in cache

What it means

404 from DELETE /models/{model_name}. The config was resolved successfully (so the id is valid) but the on-disk cache directory Path(HF_HUB_CACHE)/('models--' + hf_repo_id.replace('/','--')) does not exist. This means the model was never downloaded, the cache was already cleared, or the repo_id-to-directory translation doesn't match what's on disk.

Source

Thrown at backend/routes/models.py:466

async def delete_model(model_name: str):
    """Delete a downloaded model from the HuggingFace cache."""
    from huggingface_hub import constants as hf_constants
    from ..backends import get_model_config, unload_model_by_config

    config = get_model_config(model_name)
    if not config:
        raise HTTPException(status_code=400, detail=f"Unknown model: {model_name}")

    hf_repo_id = config.hf_repo_id

    try:
        unload_model_by_config(config)

        cache_dir = hf_constants.HF_HUB_CACHE
        repo_cache_dir = Path(cache_dir) / ("models--" + hf_repo_id.replace("/", "--"))

        if not repo_cache_dir.exists():
            raise HTTPException(status_code=404, detail=f"Model {model_name} not found in cache")

        try:
            shutil.rmtree(repo_cache_dir)
        except OSError as e:
            raise HTTPException(status_code=500, detail=f"Failed to delete model cache directory: {str(e)}")

        return {"message": f"Model {model_name} deleted successfully"}

    except HTTPException:
        raise
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Failed to delete model: {str(e)}")

View on GitHub (pinned to 51f49dea19)

Solutions

  1. GET /models/status and check the 'downloaded' flag for that model — if false, there's nothing to delete.
  2. If you expected files there, GET /models/cache-dir and inspect the models--* directories on disk.
  3. If the repo_id was renamed, either rename the on-disk directory to match the new id or re-download.
  4. Treat 404 here as 'already clean' if your goal is just to ensure removal.

Example fix

# before — deleting a model that was never downloaded
curl -X DELETE http://localhost:8000/models/qwen3-4b   # -> 404
# after — confirm presence first
GET /models/status  # downloaded:false -> nothing to delete; no API call needed
Defensive patterns

Strategy: validation

Validate before calling

async function deleteIfDownloaded(name: string) {
  const status = await (await fetch('/models/status')).json();
  const m = status.models.find(x => x.model_name === name);
  if (!m) throw new Error(`Unknown model: ${name}`);
  if (!m.downloaded) return { nothingToDo: true };
  return await fetch(`/models/${encodeURIComponent(name)}`, {method:'DELETE'});
}

Try / catch

try {
  await fetch(`/models/${name}`, {method:'DELETE'});
} catch (e) {
  if (e.response?.status === 404 && /not found in cache/.test(e.response.detail)) return; // already clean
  throw e;
}

Prevention

When it happens

Trigger: DELETE /models/qwen3-1.7b when the 1.7B model was never downloaded; deleting again after a successful delete; cache moved/migrated away; hf_repo_id changed so the computed directory name no longer matches the existing folder.

Common situations: User clicks delete on a model the status UI shows as 'not downloaded'; double-delete; HF cache cleared out of band (rm -rf) or migrated to another volume; registry's hf_repo_id edited after downloads happened under the old id.

Related errors


AI-assisted analysis of jamiepine/voicebox@51f49dea19 (2026-08-12). Data as JSON: /api/errors/d36c32280c9b4984. Report an issue: GitHub.