{"record":{"id":"f6d109add27339a2","repo":"invoke-ai/InvokeAI","slug":"unexpected-error-while-retrying-queue-items-e","errorCode":null,"errorMessage":"Unexpected error while retrying queue items: {e}","messagePattern":"Unexpected error while retrying queue items: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/session_queue.py","lineNumber":417,"sourceCode":"                    raise HTTPException(\n                        status_code=404, detail=f\"Queue item with id {item_id} not found in queue {queue_id}\"\n                    )\n                if not current_user.is_admin and root_queue_item.user_id != current_user.user_id:\n                    raise HTTPException(\n                        status_code=403, detail=f\"You do not have permission to retry queue item {item_id}\"\n                    )\n                valid_item_ids.append(item_id)\n            except SessionQueueItemNotFoundError:\n                # Skip items that don't exist - they will be handled by retry_items_by_id\n                continue\n\n        return ApiDependencies.invoker.services.session_queue.retry_items_by_id(\n            queue_id=queue_id, item_ids=valid_item_ids\n        )\n    except HTTPException:\n        raise\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Unexpected error while retrying queue items: {e}\")\n\n\n@session_queue_router.put(\n    \"/{queue_id}/clear\",\n    operation_id=\"clear\",\n    responses={\n        200: {\"model\": ClearResult},\n    },\n)\ndef clear(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id to perform this operation on\"),\n) -> ClearResult:\n    \"\"\"Clears the queue. Admin users clear (and cancel) all items; non-admin users clear only their\n    own items — other users' queued and running items are untouched.\"\"\"\n    try:\n        # The service cancels every in-progress item in scope itself (there can be several\n        # with multiple workers), so there is no per-item authorization to do here: a","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/session_queue.py#L399-L435","documentation":"Catch-all 500 for retry_items_by_id: after the per-item validation loop, any exception from session_queue.retry_items_by_id() is wrapped as HTTP 500 with the original error text appended. HTTPExceptions raised during validation are re-raised unchanged (see the preceding except HTTPException: raise).","triggerScenarios":"PUT retry_items_by_id with valid_item_ids non-empty, when the service-layer retry call raises (DB error, constraint violation, service bug, empty valid list hitting service assumptions).","commonSituations":"DB locked/down; retrying an item whose session data was pruned; server upgrade with schema drift; internal service bugs when re-enqueueing graph sessions.","solutions":["Inspect the appended {e} message and server traceback for the root cause.","Check DB health and pending migrations.","Confirm the queue still exists and items were not pruned between validation and retry.","Retry after transient DB errors; upgrade InvokeAI if the traceback points at service internals."],"exampleFix":"// before: no error discrimination\nresp = requests.put(url, json={\"item_ids\": ids})\n// after: retry once on transient failure\nresp = requests.put(url, json={\"item_ids\": ids})\nif resp.status_code == 500 and 'locked' in resp.json().get('detail', ''):\n    time.sleep(1); resp = requests.put(url, json={\"item_ids\": ids})","handlingStrategy":"retry","validationCode":"const valid = [];\nfor (const id of ids) {\n  const item = await fetch(`${base}/api/v1/queue/items/${id}`).then(r => r.ok ? r.json() : null);\n  if (item && item.queue_id === queueId) valid.push(id);\n}\nif (valid.length === 0) return; // nothing to retry","typeGuard":"function isRetryableItemsResult(v): v is { retried_item_ids: number[] } {\n  return typeof v === 'object' && v !== null && 'retried_item_ids' in v;\n}","tryCatchPattern":"for (let attempt = 0; attempt < 3; attempt++) {\n  const r = await fetch(url, { method: 'PUT', body: JSON.stringify({ item_ids: valid }) });\n  if (r.ok) break;\n  const detail = (await r.json()).detail ?? '';\n  if (/locked|database/i.test(detail)) await sleep(1000 * (attempt + 1));\n  else throw new Error(`retry_items_by_id failed: ${detail}`);\n}","preventionTips":["Pre-validate items exist in the queue before retry","Use bounded retry with backoff for transient DB errors","Keep queue service and DB schema in sync across upgrades","Inspect the wrapped detail string for root cause"],"tags":["http-500","fastapi","queue","retry"],"backgroundTag":"unhandled-exception-wrapped-as-500","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}