{"record":{"id":"bc1c6004c5354a0f","repo":"invoke-ai/InvokeAI","slug":"unexpected-error-while-getting-current-queue-item","errorCode":null,"errorMessage":"Unexpected error while getting current queue item: {e}","messagePattern":"Unexpected error while getting current queue item: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/session_queue.py","lineNumber":485,"sourceCode":"@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)\n        return item\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Unexpected error while getting current queue item: {e}\")\n\n\n@session_queue_router.get(\n    \"/{queue_id}/next\",\n    operation_id=\"get_next_queue_item\",\n    responses={\n        200: {\"model\": Optional[SessionQueueItem]},\n    },\n)\ndef get_next_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 next queue item, without executing it\"\"\"\n    try:\n        item = ApiDependencies.invoker.services.session_queue.get_next(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":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/session_queue.py#L467-L503","documentation":"Catch-all 500 for get_current_queue_item: exceptions from session_queue.get_current() (or the subsequent sanitize_queue_item_for_user call) are wrapped as HTTP 500. The route returns the currently executing queue item or null if the queue is idle.","triggerScenarios":"GET /api/v1/queue/{queue_id}/current when the service call raises (DB failure, unknown queue) or sanitization throws on malformed item data.","commonSituations":"DB locked/down; queue_id typo; corrupted queue item row causing sanitize failures; service not initialized after partial startup.","solutions":["Read the {e} detail and server traceback for the root cause.","Verify queue_id via GET status and confirm DB health.","Treat null result as 'queue idle' in clients rather than retrying aggressively.","Upgrade/restart InvokeAI if the traceback indicates corrupted item data or a service bug."],"exampleFix":"// before: assuming data on every poll\nitem = requests.get(f\"{base}/api/v1/queue/{queue_id}/current\").json()\nprocess(item)\n// after: handle idle queue\nresp = requests.get(f\"{base}/api/v1/queue/{queue_id}/current\")\nitem = resp.json() if resp.ok else None\nif item is not None:\n    process(item)","handlingStrategy":"try-catch","validationCode":"const status = await fetch(`${base}/api/v1/queue/${queueId}/status`);\nif (!status.ok) throw new Error(`queue ${queueId} unknown`);","typeGuard":"function isQueueItemOrNull(v) {\n  return v === null || (typeof v === 'object' && v !== null && 'item_id' in v && 'queue_id' in v);\n}","tryCatchPattern":"try {\n  const r = await fetch(`${base}/api/v1/queue/${queueId}/current`);\n  if (!r.ok) throw new Error((await r.json()).detail);\n  const item = await r.json(); // null means queue is idle\n  if (item) updateProgress(item);\n} catch (e) {\n  await sleep(backoff); // don't hammer a failing service\n}","preventionTips":["Treat null as idle, not as an error condition","Poll with backoff to avoid DB contention","Validate queue_id before polling","Keep server and schema versions aligned"],"tags":["http-500","fastapi","queue","polling"],"backgroundTag":"unhandled-exception-wrapped-as-500","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}