Skip to content

feat(ai): queue concurrent generations instead of rejecting#9

Merged
ijbo merged 1 commit into
mainfrom
feat/ai-generation-queue
Jun 23, 2026
Merged

feat(ai): queue concurrent generations instead of rejecting#9
ijbo merged 1 commit into
mainfrom
feat/ai-generation-queue

Conversation

@ijbo

@ijbo ijbo commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

The problem

Asking a question in a second annotation thread while the first was still answering failed with:

Error: Another AI generation is already in progress.

The AI backend is single-flight (one generation at a time), so the new parallel threads couldn't actually be used in parallel — the second request was rejected outright.

The fix

A serial generation queue around M.requestAiTask: concurrent calls now run in submission order (FIFO) instead of failing. The backend still runs one at a time, but callers wait their turn automatically.

  • Single authoritative hook — wraps requestAiTask (after the connector wrapper), so every caller benefits: annotation thread panels, {{@...}} DocGen tags, Agent Flow, AI Chat. No per-call-site changes.
  • Optional onQueued(position) / onQueueStart() callbacks; thread panels show "⏳ Queued (#N)…" while waiting, then stream when their turn starts.
  • Exposed M.aiQueueLength() for UI hints.

Verified (Playwright)

  • 3 concurrent calls against a single-flight stub that rejects when busy → all 3 fulfilled, FIFO order preserved (was: 2 rejections).
  • The shipped wrapper confirmed to never reject queued calls with "already in progress".
  • Smoke suite green (one unrelated view-mode flake passes in isolation); build clean.

🤖 Generated with Claude Code

Asking in a second annotation thread while one was generating failed with
"Another AI generation is already in progress." Add a serial FIFO queue around
requestAiTask so concurrent calls run in order; single hook covers thread
panels, DocGen, Agent Flow, AI Chat. Thread panels show a "Queued (#N)" state.

Verified via Playwright: 3 concurrent calls all complete in order vs 2 prior
rejections; shipped wrapper never rejects queued calls with "already in progress".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ijbo ijbo merged commit 4d1276f into main Jun 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant