Skip to content

[feat] Round robin job scheduling in multiuser mode#9086

Open
lstein wants to merge 5 commits intoinvoke-ai:mainfrom
lstein:copilot/enhancement-round-robin-job-scheduling
Open

[feat] Round robin job scheduling in multiuser mode#9086
lstein wants to merge 5 commits intoinvoke-ai:mainfrom
lstein:copilot/enhancement-round-robin-job-scheduling

Conversation

@lstein
Copy link
Copy Markdown
Collaborator

@lstein lstein commented Apr 25, 2026

In multiuser mode, a single user could monopolize the queue by enqueueing large batches, forcing other users to wait indefinitely. This adds a round_robin queue mode that interleaves jobs across users so each gets a turn before any user gets a second slot.

Changes

  • New config field session_queue_mode ("FIFO" | "round_robin", default "round_robin"): controls dequeue ordering. Configurable via invokeai.yaml, env var (INVOKEAI_SESSION_QUEUE_MODE), or CLI.
  • Single-user mode always uses FIFOsession_queue_mode is ignored when multiuser=False.
  • Round-robin dequeue() SQL: uses two CTEs — user_last_served tracks MAX(started_at) per user; user_next_item selects each user's best pending item (priority DESC, item_id ASC). Rows are ordered by COALESCE(last_served_at, '1970-01-01') ASC so the least-recently-served user always goes next.
  • Tests: 10 new tests covering FIFO and round-robin behavior, including the exact interleaving example from the issue:
Queued Processed
A1, A2, B1, C1, C2, A3 A1, B1, C1, A2, C2, A3

QA Instructions

  1. Run with multiuser: true in invokeai.yaml (default session_queue_mode: round_robin).
  2. Enqueue several batches as two different users — confirm jobs alternate per user rather than draining one user's queue fully before moving to the next.
  3. Set session_queue_mode: FIFO and confirm strict insertion-order is restored.
  4. Run with multiuser: false — confirm FIFO is used regardless of session_queue_mode.

Run the new unit tests:

pytest tests/app/services/session_queue/test_session_queue_dequeue.py -v

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • ❗Changes to a redux slice have a corresponding migration
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

Copilot AI and others added 5 commits March 10, 2026 03:50
- Add SESSION_QUEUE_MODE type and session_queue_mode config field
- Modify dequeue() to support round-robin ordering when multiuser mode
  is active, serving each user in turn based on last-served timestamp
- Add tests for FIFO and round-robin dequeue behavior

Co-authored-by: lstein <111189+lstein@users.noreply.github.com>
Three regressions from the multiuser isolation work in 33ec16d were
preventing non-admin users from seeing the broader queue:

1. The "X/Y" pending badge collapsed to a single number because the
   backend stopped returning per-user counts and the frontend dropped the
   X/Y formatting. Restored user_pending/user_in_progress on
   SessionQueueStatus and the X/Y formatter; get_queue_status now takes
   an explicit is_admin flag for current-item visibility.

2. The queue list only showed the caller's own jobs because
   get_queue_item_ids filtered by user. Per-item field redaction already
   happens in list_all_queue_items / get_queue_items_by_item_ids, so the
   id list itself can be returned unfiltered.

3. After enqueue or status change in another user's batch, A's queue
   list, badge totals, and item statuses stayed stale until reload because
   QueueItemStatusChangedEvent and BatchEnqueuedEvent went only to
   user:{owner} + admin rooms. Now the full event still goes to those
   rooms, and a sanitized companion (user_id="redacted", identifiers and
   error fields stripped) is broadcast to the queue room with the owner
   and admin sids in skip_sid so they don't receive a clobbering
   duplicate. The frontend handler short-circuits the redacted variant to
   tag invalidation only, skipping per-session side effects.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Run via `pnpm run generate-docs-data`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added api python PRs that change python files services PRs that change app services frontend PRs that change frontend files python-tests PRs that change python tests docs PRs that change docs labels Apr 25, 2026
@lstein lstein added the v6.13.x label Apr 25, 2026
@lstein lstein moved this to 6.13.x Theme: MODELS in Invoke - Community Roadmap Apr 25, 2026
@lstein lstein removed the v6.13.x label Apr 25, 2026
@lstein lstein moved this from 6.13.x Theme: MODELS to 6.14.x Theme: LIBRARY UPDATES in Invoke - Community Roadmap Apr 25, 2026
@lstein lstein added the 6.14.x label Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.14.x api docs PRs that change docs frontend PRs that change frontend files python PRs that change python files python-tests PRs that change python tests services PRs that change app services

Projects

Status: 6.14.x Theme: LIBRARY UPDATES

Development

Successfully merging this pull request may close these issues.

3 participants