{"record":{"id":"5e1c5376ed91c44f","repo":"invoke-ai/InvokeAI","slug":"error-setting-client-state","errorCode":null,"errorMessage":"Error setting client state","messagePattern":"Error setting client state","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/client_state.py","lineNumber":45,"sourceCode":"\n\n@client_state_router.post(\n    \"/{queue_id}/set_by_key\",\n    operation_id=\"set_client_state\",\n    response_model=str,\n)\ndef set_client_state(\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 set\"),\n    value: str = Body(..., description=\"Stringified value to set\"),\n) -> str:\n    \"\"\"Sets the client state for the current user (or system user if not authenticated)\"\"\"\n    try:\n        return ApiDependencies.invoker.services.client_state_persistence.set_by_key(current_user.user_id, key, value)\n    except Exception as e:\n        logging.error(f\"Error setting client state: {e}\")\n        raise HTTPException(status_code=500, detail=\"Error setting client state\")\n\n\n@client_state_router.get(\n    \"/{queue_id}/get_keys_by_prefix\",\n    operation_id=\"get_client_state_keys_by_prefix\",\n    response_model=list[str],\n)\ndef get_client_state_keys_by_prefix(\n    current_user: CurrentUserOrDefault,\n    queue_id: str = Path(description=\"The queue id (ignored, kept for backwards compatibility)\"),\n    prefix: str = Query(..., description=\"Prefix to filter keys by\"),\n) -> list[str]:\n    \"\"\"Gets client state keys matching a prefix for the current user\"\"\"\n    try:\n        return ApiDependencies.invoker.services.client_state_persistence.get_keys_by_prefix(\n            current_user.user_id, prefix\n        )\n    except Exception as e:","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/client_state.py#L27-L63","documentation":"HTTP 500 raised by set_client_state when the client_state_persistence service's set_by_key throws while writing (current_user.user_id, key, value). The real error is logged server-side; the client only sees the generic 500 detail.","triggerScenarios":"POST /client_state/{queue_id}/set_by_key where the DB write fails: table missing, disk full, connection lost, or value serialization fails.","commonSituations":"SQLite database locked by a long-running generation job; oversized value exceeding a column/text limit; read-only filesystem after an upgrade; missing migration for the client-state table.","solutions":["Check server logs for 'Error setting client state' and the root exception","Verify the database backend is writable and migrations are current (alembic upgrade head)","Retry the write; shrink the stored value if it may exceed size limits","Verify the InvokeAI instance points at the intended database in the config"],"exampleFix":"// before\nawait setClientState(queueId, 'gallery', bigPayload); // 500\n// after\ntry {\n  await setClientState(queueId, 'gallery', bigPayload);\n} catch {\n  await setClientState(queueId, 'gallery', compactPayload); // smaller fallback value\n}","handlingStrategy":"retry","validationCode":"if (value == null) throw new Error('setClientState requires a value');\nif (JSON.stringify(value).length > MAX_STATE_SIZE) throw new Error('Client state value too large');","typeGuard":"const isClientStateWriteError = (e) =>\n  e?.response?.status === 500 && e?.response?.data?.detail === 'Error setting client state';","tryCatchPattern":"try {\n  await api.post(`/client_state/${queueId}/set_by_key`, { key, value });\n} catch (e) {\n  if (isClientStateWriteError(e)) await retryWithBackoff(() => api.post(`/client_state/${queueId}/set_by_key`, { key, value }));\n  else throw e;\n}","preventionTips":["Keep persisted state payloads small","Avoid writing client state concurrently from multiple tabs (debounce saves)","Verify DB writability and applied migrations after upgrades"],"tags":["http-500","client-state","persistence","write-failure"],"backgroundTag":"server-internal-error","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}