{"record":{"id":"f1b30b48134087d4","repo":"invoke-ai/InvokeAI","slug":"error-getting-client-state-keys","errorCode":null,"errorMessage":"Error getting client state keys","messagePattern":"Error getting client state keys","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"invokeai/app/api/routers/client_state.py","lineNumber":65,"sourceCode":"\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:\n        logging.error(f\"Error getting client state keys: {e}\")\n        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\")","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/api/routers/client_state.py#L47-L83","documentation":"HTTP 500 raised by get_client_state_keys_by_prefix when the persistence service throws while listing keys matching a prefix for the current user. Like the other client_state endpoints, the underlying error is only logged server-side.","triggerScenarios":"GET /client_state/{queue_id}/get_keys_by_prefix where the backend key-scan/query fails (connection error, missing table, corrupted index).","commonSituations":"Database unavailable during startup or crash recovery; backend switched between implementations (e.g. SQLite to Postgres) with incomplete migration; very large key sets timing out the scan.","solutions":["Check server logs for 'Error getting client state keys' with the root cause","Confirm the client-state storage backend is healthy and migrated","Retry with a narrower prefix to reduce scan size","Restore/verify DB consistency if the backend reports corruption"],"exampleFix":"null","handlingStrategy":"fallback","validationCode":"const healthy = await fetch('/health').then(r => r.ok).catch(() => false);\nif (!healthy) throw new Error('Backend unavailable; skipping key prefix scan');","typeGuard":"const isClientStateKeysError = (e) =>\n  e?.response?.status === 500 && e?.response?.data?.detail === 'Error getting client state keys';","tryCatchPattern":"try {\n  keys = await api.get(`/client_state/${queueId}/get_keys_by_prefix`, { params: { prefix } });\n} catch (e) {\n  if (isClientStateKeysError(e)) keys = []; // empty-list fallback\n  else throw e;\n}","preventionTips":["Use narrow prefixes to limit backend scan size","Keep the client-state backend migrated and reachable","Cache known keys client-side to degrade gracefully during outages"],"tags":["http-500","client-state","persistence","database"],"backgroundTag":"server-internal-error","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}