invoke-ai/InvokeAI · error · HTTPException
Unexpected error while canceling queue item: {e}
Error message
Unexpected error while canceling queue item: {e} What it means
This HTTP 500 is the catch-all for cancel_queue_item: any exception that is neither SessionQueueItemNotFoundError nor an HTTPException is wrapped as 'Unexpected error while canceling queue item'. It indicates an infrastructure or service-level failure (database error, service unavailable, serialization bug) rather than a user-facing input problem.
Source
Thrown at invokeai/app/api/routers/session_queue.py:644
) -> SessionQueueItem:
"""Cancels a queue item. Users can only cancel their own items unless they are an admin."""
try:
# Get the queue item to check ownership
queue_item = ApiDependencies.invoker.services.session_queue.get_queue_item(item_id)
if queue_item.queue_id != queue_id:
raise HTTPException(status_code=404, detail=f"Queue item with id {item_id} not found in queue {queue_id}")
# Check authorization: user must own the item or be an admin
if queue_item.user_id != current_user.user_id and not current_user.is_admin:
raise HTTPException(status_code=403, detail="You do not have permission to cancel this queue item")
return ApiDependencies.invoker.services.session_queue.cancel_queue_item(item_id)
except SessionQueueItemNotFoundError:
raise HTTPException(status_code=404, detail=f"Queue item with id {item_id} not found in queue {queue_id}")
except HTTPException:
raise
except Exception as e:
raise HTTPException(status_code=500, detail=f"Unexpected error while canceling queue item: {e}")
@session_queue_router.get(
"/{queue_id}/counts_by_destination",
operation_id="counts_by_destination",
responses={200: {"model": SessionQueueCountsByDestination}},
)
def counts_by_destination(
current_user: CurrentUserOrDefault,
queue_id: str = Path(description="The queue id to query"),
destination: str = Query(description="The destination to query"),
) -> SessionQueueCountsByDestination:
"""Gets the counts of queue items by destination. Non-admin users only see their own items."""
try:
user_id = None if current_user.is_admin else current_user.user_id
return ApiDependencies.invoker.services.session_queue.get_counts_by_destination(
queue_id=queue_id, destination=destination, user_id=user_id
)View on GitHub (pinned to 0b6a024f2f)
Solutions
- Inspect the InvokeAI server logs for the original exception (it is embedded in the response detail)
- Verify database connectivity and that the schema matches the installed InvokeAI version (run migrations)
- Retry the cancellation — transient DB locks usually clear; the item state may or may not have changed, so re-check via GET first
- Report a bug with the detail string if the error reproduces consistently on a valid item
Example fix
// before
await cancelQueueItem(queueId, itemId); // unhandled 500
// after
try {
await cancelQueueItem(queueId, itemId);
} catch (e) {
if (e.response?.status === 500) {
console.error('server detail:', e.response.data?.detail);
// check server logs / DB health, then retry once
}
throw e;
} Defensive patterns
Strategy: retry
Validate before calling
// No client-side validation prevents server-side faults; check service health first
const health = await api.get('/health');
if (health.data?.status !== 'healthy') throw new Error('InvokeAI service unhealthy; cancel will likely 500'); Try / catch
try {
await api.delete(`/session_queue/${queueId}/i/${itemId}`);
} catch (e) {
if (e.response?.status === 500) {
console.error('Server detail:', e.response.data?.detail);
await new Promise(r => setTimeout(r, 2000));
return retryCancel(queueId, itemId, 1);
}
throw e;
} Prevention
- Monitor database health (locks, disk space) on the InvokeAI host
- Keep InvokeAI and its DB schema version in sync (run migrations on upgrade)
- Read the detail string — it contains the original server exception
- Retry transient failures with backoff; escalate reproducible ones as bugs
When it happens
Trigger: The underlying SessionQueueService.cancel_queue_item throws, e.g. a database connection failure, SQL error, disk I/O problem, or an unexpected bug in the service implementation.
Common situations: SQLite/Postgres database locked or unreachable; InvokeAI's event bus or processor down; running a mismatched database schema version after an upgrade; concurrent write contention on the queue table.
Related errors
- Unexpected error while fetching counts by destination: {e}
- Unexpected error while deleting by destination: {e}
- Unexpected error while canceling by batch id: {e}
- Unexpected error while canceling by destination: {e}
- Unexpected error while clearing queue: {e}
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/ea25f1aa80adad73.
Report an issue: GitHub.