feat(ai): queue concurrent generations instead of rejecting#9
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
Asking a question in a second annotation thread while the first was still answering failed with:
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.requestAiTask(after the connector wrapper), so every caller benefits: annotation thread panels,{{@...}}DocGen tags, Agent Flow, AI Chat. No per-call-site changes.onQueued(position)/onQueueStart()callbacks; thread panels show "⏳ Queued (#N)…" while waiting, then stream when their turn starts.M.aiQueueLength()for UI hints.Verified (Playwright)
🤖 Generated with Claude Code