{"record":{"id":"ea25f1aa80adad73","repo":"invoke-ai/InvokeAI","slug":"unexpected-error-while-canceling-queue-item-e","errorCode":null,"errorMessage":"Unexpected error while canceling queue item: {e}","messagePattern":"Unexpected error while canceling queue item: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/session_queue.py","lineNumber":644,"sourceCode":") -> 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)\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        # Check authorization: user must own the item or be an admin\n        if 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 cancel this queue item\")\n\n        return ApiDependencies.invoker.services.session_queue.cancel_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 canceling queue item: {e}\")\n\n\n@session_queue_router.get(\n    \"/{queue_id}/counts_by_destination\",\n    operation_id=\"counts_by_destination\",\n    responses={200: {\"model\": SessionQueueCountsByDestination}},\n)\ndef counts_by_destination(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id to query\"),\n    destination: str = Query(description=\"The destination to query\"),\n) -> SessionQueueCountsByDestination:\n    \"\"\"Gets the counts of queue items by destination. Non-admin users only see their own items.\"\"\"\n    try:\n        user_id = None if current_user.is_admin else current_user.user_id\n        return ApiDependencies.invoker.services.session_queue.get_counts_by_destination(\n            queue_id=queue_id, destination=destination, user_id=user_id\n        )","sourceCodeStart":626,"sourceCodeEnd":662,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/session_queue.py#L626-L662","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait cancelQueueItem(queueId, itemId); // unhandled 500\n// after\ntry {\n  await cancelQueueItem(queueId, itemId);\n} catch (e) {\n  if (e.response?.status === 500) {\n    console.error('server detail:', e.response.data?.detail);\n    // check server logs / DB health, then retry once\n  }\n  throw e;\n}","handlingStrategy":"retry","validationCode":"// No client-side validation prevents server-side faults; check service health first\nconst health = await api.get('/health');\nif (health.data?.status !== 'healthy') throw new Error('InvokeAI service unhealthy; cancel will likely 500');","typeGuard":null,"tryCatchPattern":"try {\n  await api.delete(`/session_queue/${queueId}/i/${itemId}`);\n} catch (e) {\n  if (e.response?.status === 500) {\n    console.error('Server detail:', e.response.data?.detail);\n    await new Promise(r => setTimeout(r, 2000));\n    return retryCancel(queueId, itemId, 1);\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["http-500","queue","database","unexpected-error"],"backgroundTag":"internal-server-error","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}