{"record":{"id":"f2ef542b12e5e43a","repo":"invoke-ai/InvokeAI","slug":"queue-item-with-id-item-id-not-found-in-queue-q","errorCode":null,"errorMessage":"Queue item with id {item_id} not found in queue {queue_id}","messagePattern":"Queue item with id (.+?) not found in queue (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"invokeai/app/api/routers/session_queue.py","lineNumber":394,"sourceCode":"@session_queue_router.put(\n    \"/{queue_id}/retry_items_by_id\",\n    operation_id=\"retry_items_by_id\",\n    responses={200: {\"model\": RetryItemsResult}},\n)\ndef retry_items_by_id(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id to perform this operation on\"),\n    item_ids: list[int] = Body(description=\"The queue item ids to retry\"),\n) -> RetryItemsResult:\n    \"\"\"Retries the given queue items. Users can only retry their own items unless they are an admin.\"\"\"\n    try:\n        # Check queue membership for all items and ownership for non-admins.\n        valid_item_ids: list[int] = []\n        for item_id in item_ids:\n            try:\n                queue_item = ApiDependencies.invoker.services.session_queue.get_queue_item(item_id)\n                if queue_item.queue_id != queue_id:\n                    raise HTTPException(\n                        status_code=404, detail=f\"Queue item with id {item_id} not found in queue {queue_id}\"\n                    )\n                root_queue_item = _get_workflow_call_root_queue_item(queue_item)\n                if root_queue_item.queue_id != queue_id:\n                    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","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/session_queue.py#L376-L412","documentation":"A 404 raised by retry_items_by_id when a requested queue item exists but belongs to a different queue than the path's queue_id — either the item itself or its workflow-call root item is in another queue. The API treats cross-queue access as 'not found' in this queue rather than leaking membership.","triggerScenarios":"PUT /api/v1/queue/{queue_id}/retry_items_by_id with an item_ids entry whose queue_item.queue_id (or its root queue item's queue_id) does not match the path queue_id.","commonSituations":"Client caches item ids from a previous queue after clearing/creating a new queue; retrying an id against the wrong queue id; workflow-call chains whose root item lives in a different queue.","solutions":["Fetch the item first (GET queue item) and confirm its queue_id matches the path queue_id before retrying.","List current queue items to obtain fresh, valid ids for the target queue.","Fix the client to track (queue_id, item_id) pairs together instead of bare ids.","If ids come from persisted bookmarks, validate them against the queue on startup and prune stale ones."],"exampleFix":"// before\nrequests.put(f\"{base}/api/v1/queue/{queue_id}/retry_items_by_id\", json={\"item_ids\": [42]})\n// after\nitem = requests.get(f\"{base}/api/v1/queue/items/42\").json()\nif item[\"queue_id\"] == queue_id:\n    requests.put(f\"{base}/api/v1/queue/{queue_id}/retry_items_by_id\", json={\"item_ids\": [42]})","handlingStrategy":"validation","validationCode":"const item = await fetch(`${base}/api/v1/queue/items/${itemId}`).then(r => r.json());\nif (item.queue_id !== queueId) throw new Error(`item ${itemId} is in queue ${item.queue_id}, not ${queueId}`);","typeGuard":"function belongsToQueue(item, queueId) {\n  return item != null && item.queue_id === queueId;\n}","tryCatchPattern":"try {\n  const r = await fetch(`${base}/api/v1/queue/${queueId}/retry_items_by_id`, { method: 'PUT', body: JSON.stringify({ item_ids: ids }) });\n  if (r.status === 404) {\n    const detail = (await r.json()).detail;\n    console.warn('stale item id:', detail);\n    ids = ids.filter(i => !detail.includes(`id ${i} `));\n  }\n} catch (e) { /* handle */ }","preventionTips":["Track (queue_id, item_id) pairs, never bare ids","Refresh item ids after clearing/creating queues","Verify item queue membership before retry","Prune stale persisted ids against the live queue"],"tags":["http-404","queue","validation","rest"],"backgroundTag":"resource-not-found","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}