{"record":{"id":"99b23ae7e621a449","repo":"invoke-ai/InvokeAI","slug":"unexpected-error-while-pruning-queue-e","errorCode":null,"errorMessage":"Unexpected error while pruning queue: {e}","messagePattern":"Unexpected error while pruning queue: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/session_queue.py","lineNumber":464,"sourceCode":"\n@session_queue_router.put(\n    \"/{queue_id}/prune\",\n    operation_id=\"prune\",\n    responses={\n        200: {\"model\": PruneResult},\n    },\n)\ndef prune(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id to perform this operation on\"),\n) -> PruneResult:\n    \"\"\"Prunes all completed or errored queue items. Non-admin users can only prune their own items.\"\"\"\n    try:\n        # Admin users can prune all items, non-admin users can only prune their own\n        user_id = None if current_user.is_admin else current_user.user_id\n        return ApiDependencies.invoker.services.session_queue.prune(queue_id, user_id=user_id)\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Unexpected error while pruning queue: {e}\")\n\n\n@session_queue_router.get(\n    \"/{queue_id}/current\",\n    operation_id=\"get_current_queue_item\",\n    responses={\n        200: {\"model\": Optional[SessionQueueItem]},\n    },\n)\ndef get_current_queue_item(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id to perform this operation on\"),\n) -> Optional[SessionQueueItem]:\n    \"\"\"Gets the currently execution queue item\"\"\"\n    try:\n        item = ApiDependencies.invoker.services.session_queue.get_current(queue_id)\n        if item is not None:\n            item = sanitize_queue_item_for_user(item, current_user.user_id, current_user.is_admin)","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/session_queue.py#L446-L482","documentation":"Catch-all 500 for the prune route: any exception from session_queue.prune() (deletes completed/errored items, scoped to the calling user unless admin) is wrapped as HTTP 500 with the original message appended. Unlike clear, there is no HTTPException pass-through here — even HTTPExceptions from inner code would be re-wrapped.","triggerScenarios":"PUT /api/v1/queue/{queue_id}/prune when the prune service call raises: DB error, lock contention, unknown queue_id, or internal bug during bulk deletion of finished items.","commonSituations":"Pruning very large histories timing out or hitting DB limits; SQLite lock from concurrent access; server under disk pressure; schema drift after upgrade.","solutions":["Check the {e} detail and server traceback for the root cause.","Prune more frequently/smaller so bulk deletes don't time out or lock the DB.","Verify DB connectivity, writability, and migration state.","Retry after resolving DB contention; restart the service if the queue service failed to initialize."],"exampleFix":"// before: single giant prune of a huge history\nrequests.put(f\"{base}/api/v1/queue/{queue_id}/prune\")\n// after: schedule regular prunes instead of one massive bulk delete\nschedule.every().hour.do(lambda: requests.put(f\"{base}/api/v1/queue/{queue_id}/prune\"))","handlingStrategy":"try-catch","validationCode":"const s = await fetch(`${base}/api/v1/queue/${queueId}/status`).then(r => r.json());\nif (s.completed + s.canceled + s.failed === 0) return; // nothing to prune","typeGuard":"function isPruneResult(v): v is { deleted: number } {\n  return typeof v === 'object' && v !== null && 'deleted' in v;\n}","tryCatchPattern":"try {\n  const r = await fetch(`${base}/api/v1/queue/${queueId}/prune`, { method: 'PUT' });\n  if (!r.ok) throw new Error(`prune failed: ${(await r.json()).detail}`);\n} catch (e) {\n  logger.error('prune error', e);\n  await sleep(5000); // back off before attempting again\n}","preventionTips":["Prune on a schedule instead of one massive bulk delete","Watch for bulk-delete timeouts on large histories","Verify DB writability and disk space","Re-run migrations after InvokeAI upgrades"],"tags":["http-500","fastapi","queue","database"],"backgroundTag":"unhandled-exception-wrapped-as-500","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}