invoke-ai/InvokeAI · error · HTTPException

Error deleting client state key

Error message

Error deleting client state key

What it means

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.

Source

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

        raise HTTPException(status_code=500, detail="Error getting client state keys")


@client_state_router.post(
    "/{queue_id}/delete_by_key",
    operation_id="delete_client_state_by_key",
    responses={204: {"description": "Client state key deleted"}},
)
def delete_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 delete"),
) -> None:
    """Deletes a specific client state key for the current user"""
    try:
        ApiDependencies.invoker.services.client_state_persistence.delete_by_key(current_user.user_id, key)
    except Exception as e:
        logging.error(f"Error deleting client state key: {e}")
        raise HTTPException(status_code=500, detail="Error deleting client state key")


@client_state_router.post(
    "/{queue_id}/delete",
    operation_id="delete_client_state",
    responses={204: {"description": "Client state deleted"}},
)
def delete_client_state(
    current_user: CurrentUserOrDefault,
    queue_id: str = Path(description="The queue id (ignored, kept for backwards compatibility)"),
) -> None:
    """Deletes the client state for the current user (or system user if not authenticated)"""
    try:
        ApiDependencies.invoker.services.client_state_persistence.delete(current_user.user_id)
    except Exception as e:
        logging.error(f"Error deleting client state: {e}")
        raise HTTPException(status_code=500, detail="Error deleting client state")

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Check server logs for 'Error deleting client state key' to find the root cause
  2. Retry the delete; the operation is idempotent if the key no longer exists
  3. Verify the database is writable and migrations are up to date (alembic upgrade head)
  4. Treat the key as stale client-side and overwrite it with a fresh value via set_by_key if delete keeps failing

Example fix

// before
await deleteClientStateByKey(queueId, key); // 500, key state unknown
// after
try {
  await deleteClientStateByKey(queueId, key);
} catch {
  await setClientState(queueId, key, defaultValue); // recover by resetting the key
}
Defensive patterns

Strategy: try-catch

Validate before calling

// deleting a nonexistent key is acceptable; only guard connectivity
const healthy = await fetch('/health').then(r => r.ok).catch(() => false);

Type guard

const isClientStateDeleteError = (e) =>
  e?.response?.status === 500 && e?.response?.data?.detail === 'Error deleting client state key';

Try / catch

try {
  await api.post(`/client_state/${queueId}/delete_by_key`, { key });
} catch (e) {
  if (isClientStateDeleteError(e)) {
    // key state unknown: overwrite with default to force consistency
    await api.post(`/client_state/${queueId}/set_by_key`, { key, value: DEFAULT_VALUE });
  } else throw e;
}

Prevention

When it happens

Trigger: POST /client_state/{queue_id}/delete_by_key where the backend delete fails: DB locked, connection drop, foreign-key/transaction error, or table missing.

Common situations: SQLite lock contention during concurrent generation; deleting a key concurrently from two tabs; database in read-only mode; unapplied migrations on a fresh install.

Related errors


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