{"record":{"id":"d36c32280c9b4984","repo":"jamiepine/voicebox","slug":"model-model-name-not-found-in-cache","errorCode":null,"errorMessage":"Model {model_name} not found in cache","messagePattern":"Model (.+?) not found in cache","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"warning","filePath":"backend/routes/models.py","lineNumber":466,"sourceCode":"async def delete_model(model_name: str):\n    \"\"\"Delete a downloaded model from the HuggingFace cache.\"\"\"\n    from huggingface_hub import constants as hf_constants\n    from ..backends import get_model_config, unload_model_by_config\n\n    config = get_model_config(model_name)\n    if not config:\n        raise HTTPException(status_code=400, detail=f\"Unknown model: {model_name}\")\n\n    hf_repo_id = config.hf_repo_id\n\n    try:\n        unload_model_by_config(config)\n\n        cache_dir = hf_constants.HF_HUB_CACHE\n        repo_cache_dir = Path(cache_dir) / (\"models--\" + hf_repo_id.replace(\"/\", \"--\"))\n\n        if not repo_cache_dir.exists():\n            raise HTTPException(status_code=404, detail=f\"Model {model_name} not found in cache\")\n\n        try:\n            shutil.rmtree(repo_cache_dir)\n        except OSError as e:\n            raise HTTPException(status_code=500, detail=f\"Failed to delete model cache directory: {str(e)}\")\n\n        return {\"message\": f\"Model {model_name} deleted successfully\"}\n\n    except HTTPException:\n        raise\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Failed to delete model: {str(e)}\")\n","sourceCodeStart":448,"sourceCodeEnd":479,"githubUrl":"https://github.com/jamiepine/voicebox/blob/51f49dea198384b4eb6087b72c17057c6eb1c1cd/backend/routes/models.py#L448-L479","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["GET /models/status and check the 'downloaded' flag for that model — if false, there's nothing to delete.","If you expected files there, GET /models/cache-dir and inspect the models--* directories on disk.","If the repo_id was renamed, either rename the on-disk directory to match the new id or re-download.","Treat 404 here as 'already clean' if your goal is just to ensure removal."],"exampleFix":"# before — deleting a model that was never downloaded\ncurl -X DELETE http://localhost:8000/models/qwen3-4b   # -> 404\n# after — confirm presence first\nGET /models/status  # downloaded:false -> nothing to delete; no API call needed","handlingStrategy":"validation","validationCode":"async function deleteIfDownloaded(name: string) {\n  const status = await (await fetch('/models/status')).json();\n  const m = status.models.find(x => x.model_name === name);\n  if (!m) throw new Error(`Unknown model: ${name}`);\n  if (!m.downloaded) return { nothingToDo: true };\n  return await fetch(`/models/${encodeURIComponent(name)}`, {method:'DELETE'});\n}","typeGuard":null,"tryCatchPattern":"try {\n  await fetch(`/models/${name}`, {method:'DELETE'});\n} catch (e) {\n  if (e.response?.status === 404 && /not found in cache/.test(e.response.detail)) return; // already clean\n  throw e;\n}","preventionTips":["Hide or disable delete for models whose downloaded flag is false.","Treat the 404-in-cache response as success when ensuring removal.","After a successful delete, refresh /models/status to update the downloaded flag client-side."],"tags":["models","delete","cache","huggingface","http-404"],"backgroundTag":null,"analyzedSha":"51f49dea198384b4eb6087b72c17057c6eb1c1cd","analyzedAt":"2026-08-12T16:51:42.824Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}