{"record":{"id":"c18b927e32781c65","repo":"invoke-ai/InvokeAI","slug":"unexpected-error-while-deleting-queue-item-e","errorCode":null,"errorMessage":"Unexpected error while deleting queue item: {e}","messagePattern":"Unexpected error while deleting queue item: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/session_queue.py","lineNumber":612,"sourceCode":"        queue_item = ApiDependencies.invoker.services.session_queue.get_queue_item(item_id)\n        if queue_item.queue_id != queue_id:\n            raise HTTPException(status_code=404, detail=f\"Queue item with id {item_id} not found in queue {queue_id}\")\n\n        root_queue_item = _get_workflow_call_root_queue_item(queue_item)\n        if root_queue_item.queue_id != queue_id:\n            raise HTTPException(status_code=404, detail=f\"Queue item with id {item_id} not found in queue {queue_id}\")\n\n        # The queue service deletes the entire chain, so authorization must use the root owner.\n        if root_queue_item.user_id != current_user.user_id and not current_user.is_admin:\n            raise HTTPException(status_code=403, detail=\"You do not have permission to delete this queue item\")\n\n        ApiDependencies.invoker.services.session_queue.delete_queue_item(item_id)\n    except SessionQueueItemNotFoundError:\n        raise HTTPException(status_code=404, detail=f\"Queue item with id {item_id} not found in queue {queue_id}\")\n    except HTTPException:\n        raise\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Unexpected error while deleting queue item: {e}\")\n\n\n@session_queue_router.put(\n    \"/{queue_id}/i/{item_id}/cancel\",\n    operation_id=\"cancel_queue_item\",\n    responses={\n        200: {\"model\": SessionQueueItem},\n    },\n)\ndef cancel_queue_item(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id to perform this operation on\"),\n    item_id: int = Path(description=\"The queue item to cancel\"),\n) -> SessionQueueItem:\n    \"\"\"Cancels a queue item. Users can only cancel their own items unless they are an admin.\"\"\"\n    try:\n        # Get the queue item to check ownership\n        queue_item = ApiDependencies.invoker.services.session_queue.get_queue_item(item_id)","sourceCodeStart":594,"sourceCodeEnd":630,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/session_queue.py#L594-L630","documentation":"HTTPException(500) catch-all in DELETE /session_queue/{queue_id}/i/{item_id} for any exception other than item-not-found, explicit HTTPExceptions, or other handled types. Failures in the delete_queue_item service call (DB errors, event-bus broadcast failures while notifying queue listeners) surface as this generic 500.","triggerScenarios":"Calling DELETE when the underlying delete_queue_item throws: database write failure, the events service cannot publish queue-item-deleted, or an unexpected error inside chain deletion of a workflow-call chain.","commonSituations":"SQLite database locked by another process (e.g. a backup or another InvokeAI process); DB connection pool exhausted under load; event bus (WebSocket) service in a bad state after a partial restart.","solutions":["Inspect the interpolated {e} in the detail and the server logs for the root cause","Check DB connectivity/locks and retry the delete once storage is healthy","Restart the API server if the event bus or service graph is in a bad state","If deletion keeps failing for one chain, try cancelling then deleting, or remove via DB maintenance tooling"],"exampleFix":"// before: single DELETE fails transiently\nawait api.delete(`/api/v1/session_queue/${queueId}/i/${itemId}`)\n// after: retry transient 500s\nawait retry(async () => api.delete(...), { retries: 2, retryOn: [500, 503] })","handlingStrategy":"retry","validationCode":"// quick health check before delete\nconst health = await fetch('/api/v1/session_queue/status')\nif (!health.ok) throw new Error('Queue backend unhealthy; postpone delete')","typeGuard":null,"tryCatchPattern":"try {\n  await api.delete(`/api/v1/session_queue/${queueId}/i/${itemId}`)\n} catch (e) {\n  if (e.response?.status === 500) {\n    log.error('Delete failed:', e.response.data?.detail)\n    await retry(() => api.delete(...), { retries: 2, backoff: 'exponential' })\n  } else throw e\n}","preventionTips":["Monitor DB locks (especially SQLite) and connection pool saturation","Check server logs for event-bus broadcast failures after deletes","Restart the API server if service graph/event bus state degrades"],"tags":["fastapi","http-500","queue","database"],"backgroundTag":"unexpected-internal-server-error","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}