jamiepine/voicebox · error · HTTPException

Failed to delete model: {str(e)}

Error message

Failed to delete model: {str(e)}

What it means

Catch-all 500 from DELETE /models/{model_name}. After the inner OSError handler, any other Exception (non-OSError) from unload_model_by_config or the surrounding logic is caught and re-raised as HTTPException(500, detail=f'Failed to delete model: {str(e)}'). HTTPException is explicitly re-raised (except HTTPException: raise) so the 404 and inner 500 above pass through unchanged.

Source

Thrown at backend/routes/models.py:478

        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. Read detail=str(e) — the forwarded message identifies the non-OSError cause.
  2. Restart the backend to reset engine singletons, then retry the delete.
  3. If the underlying cause is a registry/config defect (missing hf_repo_id), fix the config before retrying.
  4. As a last resort, stop the backend and remove the cache directory manually, then restart.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await fetch(`/models/${name}`, {method:'DELETE'});
} catch (e) {
  // non-OSError 500 — server-side fault; read detail but don't blindly retry
  if (e.response?.status === 500 && /Failed to delete model:/.test(e.response.detail ?? '')) {
    // surface to user; recommend backend restart and retry
    throw new Error('Server error during delete — try restarting the backend');
  }
  throw e;
}

Prevention

When it happens

Trigger: unload_model_by_config raises a non-OSError exception (backend attribute error, engine dispatch failure); unexpected error building the repo_cache_dir path; HuggingFace constants import fails inside the handler; registry config object missing hf_repo_id attribute.

Common situations: Backend singleton in a broken state when unload is attempted; partial registry where a config lacks hf_repo_id; bug in an engine-specific unload path; corrupted cache layout triggering a non-OSError filesystem error from a helper.

Related errors


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