invoke-ai/InvokeAI · error · HTTPException
Unexpected error while pruning queue: {e}
Error message
Unexpected error while pruning queue: {e} What it means
Catch-all 500 for the prune route: any exception from session_queue.prune() (deletes completed/errored items, scoped to the calling user unless admin) is wrapped as HTTP 500 with the original message appended. Unlike clear, there is no HTTPException pass-through here — even HTTPExceptions from inner code would be re-wrapped.
Source
Thrown at invokeai/app/api/routers/session_queue.py:464
@session_queue_router.put(
"/{queue_id}/prune",
operation_id="prune",
responses={
200: {"model": PruneResult},
},
)
def prune(
current_user: CurrentUserOrDefault,
queue_id: str = Path(description="The queue id to perform this operation on"),
) -> PruneResult:
"""Prunes all completed or errored queue items. Non-admin users can only prune their own items."""
try:
# Admin users can prune all items, non-admin users can only prune their own
user_id = None if current_user.is_admin else current_user.user_id
return ApiDependencies.invoker.services.session_queue.prune(queue_id, user_id=user_id)
except Exception as e:
raise HTTPException(status_code=500, detail=f"Unexpected error while pruning queue: {e}")
@session_queue_router.get(
"/{queue_id}/current",
operation_id="get_current_queue_item",
responses={
200: {"model": Optional[SessionQueueItem]},
},
)
def get_current_queue_item(
current_user: CurrentUserOrDefault,
queue_id: str = Path(description="The queue id to perform this operation on"),
) -> Optional[SessionQueueItem]:
"""Gets the currently execution queue item"""
try:
item = ApiDependencies.invoker.services.session_queue.get_current(queue_id)
if item is not None:
item = sanitize_queue_item_for_user(item, current_user.user_id, current_user.is_admin)View on GitHub (pinned to 0b6a024f2f)
Solutions
- Check the {e} detail and server traceback for the root cause.
- Prune more frequently/smaller so bulk deletes don't time out or lock the DB.
- Verify DB connectivity, writability, and migration state.
- Retry after resolving DB contention; restart the service if the queue service failed to initialize.
Example fix
// before: single giant prune of a huge history
requests.put(f"{base}/api/v1/queue/{queue_id}/prune")
// after: schedule regular prunes instead of one massive bulk delete
schedule.every().hour.do(lambda: requests.put(f"{base}/api/v1/queue/{queue_id}/prune")) Defensive patterns
Strategy: try-catch
Validate before calling
const s = await fetch(`${base}/api/v1/queue/${queueId}/status`).then(r => r.json());
if (s.completed + s.canceled + s.failed === 0) return; // nothing to prune Type guard
function isPruneResult(v): v is { deleted: number } {
return typeof v === 'object' && v !== null && 'deleted' in v;
} Try / catch
try {
const r = await fetch(`${base}/api/v1/queue/${queueId}/prune`, { method: 'PUT' });
if (!r.ok) throw new Error(`prune failed: ${(await r.json()).detail}`);
} catch (e) {
logger.error('prune error', e);
await sleep(5000); // back off before attempting again
} Prevention
- Prune on a schedule instead of one massive bulk delete
- Watch for bulk-delete timeouts on large histories
- Verify DB writability and disk space
- Re-run migrations after InvokeAI upgrades
When it happens
Trigger: PUT /api/v1/queue/{queue_id}/prune when the prune service call raises: DB error, lock contention, unknown queue_id, or internal bug during bulk deletion of finished items.
Common situations: Pruning very large histories timing out or hitting DB limits; SQLite lock from concurrent access; server under disk pressure; schema drift after upgrade.
Related errors
- Unexpected error while canceling by batch id: {e}
- Unexpected error while canceling by destination: {e}
- Unexpected error while clearing queue: {e}
- Unexpected error while getting queue status: {e}
- Unexpected error while getting batch status: {e}
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/99b23ae7e621a449.
Report an issue: GitHub.