{"record":{"id":"38f85f6123988534","repo":"invoke-ai/InvokeAI","slug":"unexpected-error-while-canceling-all-except-curren","errorCode":null,"errorMessage":"Unexpected error while canceling all except current: {e}","messagePattern":"Unexpected error while canceling all except current: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/session_queue.py","lineNumber":311,"sourceCode":"\n@session_queue_router.put(\n    \"/{queue_id}/cancel_all_except_current\",\n    operation_id=\"cancel_all_except_current\",\n    responses={200: {\"model\": CancelAllExceptCurrentResult}},\n)\ndef cancel_all_except_current(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id to perform this operation on\"),\n) -> CancelAllExceptCurrentResult:\n    \"\"\"Immediately cancels all queue items except in-processing items. Non-admin users can only cancel their own items.\"\"\"\n    try:\n        # Admin users can cancel all items, non-admin users can only cancel their own\n        user_id = None if current_user.is_admin else current_user.user_id\n        return ApiDependencies.invoker.services.session_queue.cancel_all_except_current(\n            queue_id=queue_id, user_id=user_id\n        )\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Unexpected error while canceling all except current: {e}\")\n\n\n@session_queue_router.put(\n    \"/{queue_id}/delete_all_except_current\",\n    operation_id=\"delete_all_except_current\",\n    responses={200: {\"model\": DeleteAllExceptCurrentResult}},\n)\ndef delete_all_except_current(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id to perform this operation on\"),\n) -> DeleteAllExceptCurrentResult:\n    \"\"\"Immediately deletes all queue items except in-processing items. Non-admin users can only delete their own items.\"\"\"\n    try:\n        # Admin users can delete all items, non-admin users can only delete their own\n        user_id = None if current_user.is_admin else current_user.user_id\n        return ApiDependencies.invoker.services.session_queue.delete_all_except_current(\n            queue_id=queue_id, user_id=user_id\n        )","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/session_queue.py#L293-L329","documentation":"Thrown by cancel_all_except_current: any exception from SessionQueue.cancel_all_except_current(queue_id, user_id) becomes a 500 with the exception message in the detail. Non-admin users are scoped to their own items via user_id; failures here are unclassified and reported as generic server errors.","triggerScenarios":"PUT /{queue_id}/cancel_all_except_current with an invalid queue_id, DB write failure during bulk cancel, or an internal service error while computing cancellable items.","commonSituations":"Bulk-cancel while the queue is under heavy write load (SQLite lock contention); stale queue_id after switching instances; admin flag not set so scoping logic operates on unexpected user data.","solutions":["Check detail string for the underlying exception","Verify queue_id is valid on the current instance","Retry during lower load if SQLite locking is implicated","If persistent, check server logs and DB integrity (integrity_check on invokeai.db)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const q = await fetch(`/api/v1/queue/${queueId}`);\nif (!q.ok) throw new Error(`Queue ${queueId} not found`);","typeGuard":"function isCancelResult(v) { return v !== null && typeof v === 'object' && 'canceled' in v; }","tryCatchPattern":"try {\n  const res = await fetch(`/api/v1/queue/${queueId}/cancel_all_except_current`, {method:'PUT'});\n  if (res.status === 500) throw new Error((await res.json()).detail);\n  return await res.json();\n} catch (e) { console.error('bulk cancel failed:', e.message); }","preventionTips":["Validate queue_id before bulk operations","Avoid bulk cancel during heavy queue writes; pause first if needed","Read the detail string - the underlying exception is embedded","Run DB integrity checks if cancel failures recur"],"tags":["fastapi","http-500","queue","cancellation","api"],"backgroundTag":"api-internal-server-error","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}