jamiepine/voicebox · error · HTTPException
Failed to clear cache: {str(e)}
Error message
Failed to clear cache: {str(e)} What it means
Raised (HTTP 500) by POST /cache/clear when clear_voice_prompt_cache() throws. That function clears an in-memory dict and unlinks *.prompt and combined_*.wav files under the configured cache dir, already swallowing per-file unlink errors as warnings — so a propagated exception almost always comes from _get_cache_dir()/config.get_cache_dir() (e.g. misconfigured path), a torch import/init failure, or an OS error creating/reading the directory itself, not from individual file deletes.
Source
Thrown at backend/routes/tasks.py:42
with progress_manager._lock:
progress_manager._progress.clear()
progress_manager._last_notify_time.clear()
progress_manager._last_notify_progress.clear()
return {"message": "All task state cleared"}
@router.post("/cache/clear")
async def clear_cache():
"""Clear all voice prompt caches (memory and disk)."""
try:
deleted_count = clear_voice_prompt_cache()
return {
"message": "Voice prompt cache cleared successfully",
"files_deleted": deleted_count,
}
except Exception as e:
raise HTTPException(status_code=500, detail=f"Failed to clear cache: {str(e)}")
@router.get("/tasks/active", response_model=models.ActiveTasksResponse)
async def get_active_tasks():
"""Return all currently active downloads and generations."""
task_manager = get_task_manager()
progress_manager = get_progress_manager()
active_downloads = []
task_manager_downloads = task_manager.get_active_downloads()
progress_active = progress_manager.get_all_active()
download_map = {task.model_name: task for task in task_manager_downloads}
progress_map = {p["model_name"]: p for p in progress_active}
all_model_names = set(download_map.keys()) | set(progress_map.keys())
for model_name in all_model_names:
task = download_map.get(model_name)View on GitHub (pinned to 51f49dea19)
Solutions
- Confirm the configured cache dir exists and is writable/deletable by the server process.
- Check the server log — the wrapped exception names the exact path/permission problem.
- Because per-file deletes are already best-effort, a 500 here usually points to config/permissions, not data — fix the env, not the cache contents.
- If torch failed to import, validate the Python environment (requirements.txt / image) before retrying.
Example fix
# before
except Exception as e:
raise HTTPException(status_code=500, detail=f"Failed to clear cache: {str(e)}")
# after (avoid leaking path/error internals; log full detail server-side)
except OSError as e:
logger.warning("cache clear hit OS error: %s", e)
return {"message": "Cache cleared with warnings", "files_deleted": 0}
except Exception:
logger.exception("clear_voice_prompt_cache failed")
raise HTTPException(status_code=500, detail="Failed to clear cache") Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-flight: confirm the cache dir is writable before clearing.
async function canClearCache(api) {
const health = await api.getHealth().catch(() => null);
return Boolean(health && health.cache_dir_writable !== false);
} Type guard
function isRetryableCacheError(e) {
return e?.status === 500 && /cache/i.test(String(e.detail ?? ''));
} Try / catch
try { await api.clearCache(); notify('Cache cleared'); }
catch (e) {
if (e.status === 500) notify('Could not clear cache — check server permissions/config');
else throw e;
} Prevention
- Mount the cache directory as writable/deletable by the server process.
- Validate CACHE_DIR / storage config at startup, not only when clearing.
- Treat this 500 as an ops/config issue — per-file deletes are already best-effort inside the function.
When it happens
Trigger: The cache directory path is unset/misconfigured in config, the process lacks permission to stat the directory, the filesystem is read-only, or the torch dependency failed to initialize so the module-level _memory_cache or torch.save machinery errors.
Common situations: Container runs with a read-only mount for the cache dir, wrong CACHE_DIR env var pointing at a non-writable path, or running as a user without delete permission on the cached files' parent.
Related errors
- str(e)
- str(e)
- Failed to delete model cache directory: {str(e)}
- Audio for capture {capture_id} is missing
- Microphone access is not available. Please ensure: 1. The ap
AI-assisted analysis of jamiepine/voicebox@51f49dea19 (2026-08-12).
Data as JSON: /api/errors/fe1e1950b033ebb1.
Report an issue: GitHub.