invoke-ai/InvokeAI · error · HTTPException

Unexpected error while deleting by destination: {e}

Error message

Unexpected error while deleting by destination: {e}

What it means

This HTTP 500 wraps any exception from delete_by_destination, which removes all queued items for a destination (all of them for admins, only the caller's own for non-admins). Any non-HTTPException failure in the service layer — typically database errors — is reported as 'Unexpected error while deleting by destination'. The delete may be partially applied, so queue state should be re-fetched.

Source

Thrown at invokeai/app/api/routers/session_queue.py:685

@session_queue_router.delete(
    "/{queue_id}/d/{destination}",
    operation_id="delete_by_destination",
    responses={200: {"model": DeleteByDestinationResult}},
)
def delete_by_destination(
    current_user: CurrentUserOrDefault,
    queue_id: str = Path(description="The queue id to query"),
    destination: str = Path(description="The destination to query"),
) -> DeleteByDestinationResult:
    """Deletes all items with the given destination. Non-admin users can only delete their own items."""
    try:
        # Admin users can delete all items, non-admin users can only delete their own
        user_id = None if current_user.is_admin else current_user.user_id
        return ApiDependencies.invoker.services.session_queue.delete_by_destination(
            queue_id=queue_id, destination=destination, user_id=user_id
        )
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Unexpected error while deleting by destination: {e}")

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Inspect server logs for the underlying exception in the response detail
  2. Verify database health and re-run the delete after transient lock contention clears
  3. Re-fetch the queue listing to confirm which items actually remain before retrying
  4. Avoid bulk-deleting while generations are actively consuming the same queue

Example fix

// before
await deleteByDestination(queueId, destination); // unhandled 500, partial state possible
// after
try {
  await deleteByDestination(queueId, destination);
} catch (e) {
  if (e.response?.status === 500) {
    const remaining = await listQueueItems(queueId);
    console.warn('delete failed, remaining items:', remaining.length);
  }
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

const items = await api.get(`/session_queue/${queueId}/i`);
const count = items.data.items.filter(i => i.destination === destination).length;
if (count === 0) return { deleted: 0 }; // nothing to delete — skip risky bulk call

Try / catch

try {
  await api.delete(`/session_queue/${queueId}/d/${destination}`);
} catch (e) {
  if (e.response?.status === 500) {
    const remaining = await api.get(`/session_queue/${queueId}/i`);
    console.error('Bulk delete failed; items remaining:', remaining.data.items.length);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling DELETE /session_queue/{queue_id}/d/{destination} when the bulk delete throws: DB failure, lock contention with concurrent enqueue/cancel, or an invalid state in the queue service.

Common situations: SQLite database locked by another process (e.g. during long-running generations); deleting a destination while items are actively being processed; post-upgrade schema mismatch.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/aabef8d29ca1dce6. Report an issue: GitHub.