USER_ISOLATION_IMPLEMENTATION.md
This document describes the implementation of user isolation features in the InvokeAI session queue and processing system to address issues identified in the enhancement request.
Problem: When two users are logged in simultaneously and one initiates a generation, the generation preview shows up in both users' browsers and the generated image gets saved to both users' image boards.
Solution: Implemented socket-level event filtering based on user authentication:
invokeai/app/api/sockets.py):_handle_connect() methodverify_token() functionuser_id and is_admin in socket session for later use_handle_queue_event() to filter events by user:
QueueItemEventBase events, only emit to:
user_id matches)is_admin is True)invokeai/app/services/events/events_common.py):user_id field to QueueItemEventBase classuser_id from queue items:
InvocationStartedEvent.build()InvocationProgressEvent.build()InvocationCompleteEvent.build()InvocationErrorEvent.build()QueueItemStatusChangedEvent.build()Problem: Users can see batch field values from generation processes launched by other users.
Solution: Implemented field value sanitization at the API level:
invokeai/app/api/routers/session_queue.py):sanitize_queue_item_for_user() helper function
field_values for non-admin users viewing other users' itemslist_all_queue_items() - Added CurrentUser dependencyget_queue_items_by_item_ids() - Added CurrentUser dependencyget_queue_item() - Added CurrentUser dependencyProblem: When the job queue tab is open in multiple browsers and a generation is begun in one browser window, the queue does not update in the other window.
Status: This issue is likely resolved by the socket authentication and event filtering changes. The existing socket subscription mechanism (subscribe_queue event) already supports multiple connections per user. Testing is required to confirm this works correctly with the new authentication flow.
Problem: Queue table lacks user identification, making it difficult to know who launched which job.
Solution: Added user information to queue items and UI:
invokeai/app/services/session_queue/session_queue_sqlite.py):users tableget_queue_item() - Now selects display_name and email from users tabledequeue() - Includes user infoget_next() - Includes user infoget_current() - Includes user infolist_all_queue_items() - Includes user infoinvokeai/app/services/session_queue/session_queue_common.py):SessionQueueItem:
user_display_name: Optional[str] - Display name from users tableuser_email: Optional[str] - Email from users tableuser_id field already existed from Migration 25constants.ts): Added user: '8rem' column widthQueueListHeader.tsx): Added "User" column headerQueueItemComponent.tsx):
en.json): Added translations:
"user": "User""fieldValuesHidden": "Hidden for privacy"verify_token() function from invokeai.app.services.auth.token_serviceis_admin fieldNo database migration is required. The changes leverage:
user_id column in session_queue table (added in Migration 25)users table (added in Migration 25)Socket Authentication:
Event Filtering:
Field Value Sanitization:
UI Display:
Field Values Display:
Multi-Browser Testing:
TypeScript Types:
cd invokeai/frontend/web && python ../../../scripts/generate_openapi_schema.py | pnpm typegenBackward Compatibility:
Socket.IO Session Storage: