{"record":{"id":"59191feaa0c7d945","repo":"invoke-ai/InvokeAI","slug":"you-do-not-have-permission-to-cancel-this-queue-it","errorCode":null,"errorMessage":"You do not have permission to cancel this queue item","messagePattern":"You do not have permission to cancel this queue item","errorType":"http","errorClass":"HTTPException","httpStatus":403,"severity":"error","filePath":"invokeai/app/api/routers/session_queue.py","lineNumber":636,"sourceCode":"    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)\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\"),","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/session_queue.py#L618-L654","documentation":"This HTTP 403 is raised when an authenticated user attempts to cancel a queue item they do not own and their token does not carry the is_admin flag. InvokeAI's multi-user mode scopes queue items to the user_id that enqueued them, and only admins may cancel other users' items. The check happens after the 404 queue-match check and before the service call.","triggerScenarios":"Calling the cancel endpoint as a non-admin user where queue_item.user_id differs from current_user.user_id — e.g. cancelling another user's queued generation.","commonSituations":"Shared/multi-user InvokeAI instances where a user grabs an item ID from logs or another user's UI; service accounts with non-admin tokens trying to manage items enqueued by other accounts; tokens issued before the user was promoted to admin still cached client-side.","solutions":["Cancel the item with the same user account that enqueued it","Have an admin user (is_admin=true token) perform the cancellation","Re-login or re-issue the token if the user was recently promoted to admin (stale TokenData)","Enable anonymous/admin single-user mode if per-user isolation is not needed for your deployment"],"exampleFix":"// before\n// cancelling with a regular user token an item owned by someone else\nawait api.delete(`/session_queue/${queueId}/i/${itemId}`);\n// after\n// run as admin token or the owning user\nconst item = await api.get(`/session_queue/${queueId}/i/${itemId}`);\nif (item.user_id === currentUser.id || currentUser.is_admin) {\n  await api.delete(`/session_queue/${queueId}/i/${itemId}`);\n}","handlingStrategy":"try-catch","validationCode":"const item = await api.get(`/session_queue/${queueId}/i/${itemId}`);\nif (item.data.user_id !== currentUser.id && !currentUser.is_admin) {\n  throw new Error('Current user cannot cancel this item; use the owning user or an admin token');\n}","typeGuard":"function canCancel(item, user) {\n  return user.is_admin === true || item.user_id === user.user_id;\n}","tryCatchPattern":"try {\n  await api.delete(`/session_queue/${queueId}/i/${itemId}`);\n} catch (e) {\n  if (e.response?.status === 403) {\n    console.warn('Not your queue item; request an admin to cancel it');\n    return;\n  }\n  throw e;\n}","preventionTips":["Only cancel items your own token enqueued","Use admin tokens for shared queue management","Re-authenticate after role changes so TokenData reflects admin status","Check item ownership in the UI before exposing cancel buttons"],"tags":["http-403","authorization","multi-user","invokeai"],"backgroundTag":"insufficient-permissions","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}