invoke-ai/InvokeAI · error · HTTPException

Error getting client state

Error message

Error getting client state

What it means

HTTP 500 raised by get_client_state_by_key when the client_state_persistence service throws while fetching the value for (current_user.user_id, key). The original exception is logged server-side and replaced with a generic 500 detail.

Source

Thrown at invokeai/app/api/routers/client_state.py:26

client_state_router = APIRouter(prefix="/v1/client_state", tags=["client_state"])


@client_state_router.get(
    "/{queue_id}/get_by_key",
    operation_id="get_client_state_by_key",
    response_model=str | None,
)
def get_client_state_by_key(
    current_user: CurrentUserOrDefault,
    queue_id: str = Path(description="The queue id (ignored, kept for backwards compatibility)"),
    key: str = Query(..., description="Key to get"),
) -> str | None:
    """Gets the client state for the current user (or system user if not authenticated)"""
    try:
        return ApiDependencies.invoker.services.client_state_persistence.get_by_key(current_user.user_id, key)
    except Exception as e:
        logging.error(f"Error getting client state: {e}")
        raise HTTPException(status_code=500, detail="Error getting client state")


@client_state_router.post(
    "/{queue_id}/set_by_key",
    operation_id="set_client_state",
    response_model=str,
)
def set_client_state(
    current_user: CurrentUserOrDefault,
    queue_id: str = Path(description="The queue id (ignored, kept for backwards compatibility)"),
    key: str = Query(..., description="Key to set"),
    value: str = Body(..., description="Stringified value to set"),
) -> str:
    """Sets the client state for the current user (or system user if not authenticated)"""
    try:
        return ApiDependencies.invoker.services.client_state_persistence.set_by_key(current_user.user_id, key, value)
    except Exception as e:
        logging.error(f"Error setting client state: {e}")

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Check server logs for 'Error getting client state' with the underlying exception
  2. Verify the client state persistence backend (database) is reachable and migrated
  3. Re-run InvokeAI database migrations (e.g. alembic upgrade head) to ensure the client state table exists
  4. Retry the request after backend recovery

Example fix

// before
const state = await getClientStateByKey(queueId, key); // throws on 500
// after
let state = null;
try {
  state = await getClientStateByKey(queueId, key);
} catch {
  state = null; // fall back to default client state
}
Defensive patterns

Strategy: fallback

Validate before calling

// no reliable client-side pre-check; ensure backend reachable
const healthy = await fetch('/health').then(r => r.ok).catch(() => false);

Type guard

const isClientStateFetchError = (e) =>
  e?.response?.status === 500 && e?.response?.data?.detail === 'Error getting client state';

Try / catch

try {
  state = await api.get(`/client_state/${queueId}/get_by_key`, { params: { key } });
} catch (e) {
  if (isClientStateFetchError(e)) state = DEFAULT_CLIENT_STATE; // fallback value
  else throw e;
}

Prevention

When it happens

Trigger: GET /client_state/{queue_id}/get_by_key where the persistence backend (DB table for client state) is unavailable, corrupted, or the service is misconfigured in ApiDependencies.

Common situations: Database migration missing the client-state table; DB connection pool exhausted; Redis/SQLite backend down; user row missing in a multi-user setup after restore from backup.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/8c6c47c0cca6ba5a. Report an issue: GitHub.