Graceful capacity handling: request queue + visible waiting state#109
Merged
Conversation
…state
When the shared workshop key is near its limit, turns now degrade
gracefully instead of erroring:
- New requestGate caps concurrent outbound provider calls per browser (4)
and queues the rest FIFO, so one participant running several
conversations doesn't burst the key.
- generateResponse reports a WaitStatus (queued / rate-limited+retry) via
an onWait callback. The engine surfaces it as waitStatus, shown in the
chat loading indicator ('Many requests at once — your turn is queued…'
/ 'High demand — retrying in Ns…') in amber, so the user sees the app
is waiting for capacity rather than a frozen spinner or an error.
- Slot is held only during the in-flight request, released during retry
backoff. Status cleared on response, stop, reset, and error.
✅ Deploy Preview for ai2aichat ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.

Builds on the jittered backoff (#108) so that when the shared key is near its limit, turns wait gracefully instead of failing — the user's requested 'queue / loading' mechanism.
What's new:
requestGate.ts— per-browser FIFO concurrency cap (4 in-flight). One participant running 2–3 conversations no longer fans out a burst; excess turns queue.generateResponseemits aWaitStatusviaonWait:queued(waiting for a slot) orrate-limited(sleeping through a 429 retry). Slot is held only during the actual request, freed during backoff.waitStatus; the chat indicator shows it in amber — 'Many requests at once — your turn is queued…' / 'High demand — the API is rate-limiting. Retrying in Ns…' — instead of a silent 'Generating…' or an error.Tests 35/35 ✓, build ✓, lint ✓.