{"record":{"id":"122f9adc8764ded9","repo":"invoke-ai/InvokeAI","slug":"error-deleting-client-state-key","errorCode":null,"errorMessage":"Error deleting client state key","messagePattern":"Error deleting client state key","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/client_state.py","lineNumber":83,"sourceCode":"        raise HTTPException(status_code=500, detail=\"Error getting client state keys\")\n\n\n@client_state_router.post(\n    \"/{queue_id}/delete_by_key\",\n    operation_id=\"delete_client_state_by_key\",\n    responses={204: {\"description\": \"Client state key deleted\"}},\n)\ndef delete_client_state_by_key(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id (ignored, kept for backwards compatibility)\"),\n    key: str = Query(..., description=\"Key to delete\"),\n) -> None:\n    \"\"\"Deletes a specific client state key for the current user\"\"\"\n    try:\n        ApiDependencies.invoker.services.client_state_persistence.delete_by_key(current_user.user_id, key)\n    except Exception as e:\n        logging.error(f\"Error deleting client state key: {e}\")\n        raise HTTPException(status_code=500, detail=\"Error deleting client state key\")\n\n\n@client_state_router.post(\n    \"/{queue_id}/delete\",\n    operation_id=\"delete_client_state\",\n    responses={204: {\"description\": \"Client state deleted\"}},\n)\ndef delete_client_state(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id (ignored, kept for backwards compatibility)\"),\n) -> None:\n    \"\"\"Deletes the client state for the current user (or system user if not authenticated)\"\"\"\n    try:\n        ApiDependencies.invoker.services.client_state_persistence.delete(current_user.user_id)\n    except Exception as e:\n        logging.error(f\"Error deleting client state: {e}\")\n        raise HTTPException(status_code=500, detail=\"Error deleting client state\")\n","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/client_state.py#L65-L101","documentation":"HTTP 500 raised by delete_client_state_by_key when the persistence service throws while deleting (current_user.user_id, key). The failure is logged server-side and surfaced as a generic 500 detail; the key may or may not have been removed.","triggerScenarios":"POST /client_state/{queue_id}/delete_by_key where the backend delete fails: DB locked, connection drop, foreign-key/transaction error, or table missing.","commonSituations":"SQLite lock contention during concurrent generation; deleting a key concurrently from two tabs; database in read-only mode; unapplied migrations on a fresh install.","solutions":["Check server logs for 'Error deleting client state key' to find the root cause","Retry the delete; the operation is idempotent if the key no longer exists","Verify the database is writable and migrations are up to date (alembic upgrade head)","Treat the key as stale client-side and overwrite it with a fresh value via set_by_key if delete keeps failing"],"exampleFix":"// before\nawait deleteClientStateByKey(queueId, key); // 500, key state unknown\n// after\ntry {\n  await deleteClientStateByKey(queueId, key);\n} catch {\n  await setClientState(queueId, key, defaultValue); // recover by resetting the key\n}","handlingStrategy":"try-catch","validationCode":"// deleting a nonexistent key is acceptable; only guard connectivity\nconst healthy = await fetch('/health').then(r => r.ok).catch(() => false);","typeGuard":"const isClientStateDeleteError = (e) =>\n  e?.response?.status === 500 && e?.response?.data?.detail === 'Error deleting client state key';","tryCatchPattern":"try {\n  await api.post(`/client_state/${queueId}/delete_by_key`, { key });\n} catch (e) {\n  if (isClientStateDeleteError(e)) {\n    // key state unknown: overwrite with default to force consistency\n    await api.post(`/client_state/${queueId}/set_by_key`, { key, value: DEFAULT_VALUE });\n  } else throw e;\n}","preventionTips":["Avoid concurrent deletes of the same key from multiple tabs","Retry deletes; the operation is effectively idempotent","Verify DB is writable and migrations current after upgrades","If delete keeps failing, reset the key via set_by_key with a default value"],"tags":["http-500","client-state","persistence","deletion"],"backgroundTag":"server-internal-error","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}