Add async request queue to llm-server - #250
Merged
Merged
Conversation
stikves
marked this pull request as ready for review
September 14, 2026 14:41
stikves
force-pushed
the
sukru/serve-v2-public
branch
4 times, most recently
from
September 14, 2026 16:11
465b7bc to
0a24579
Compare
Replace the binary busy flag with a bounded async RequestQueue: concurrent requests wait FIFO and get a 429 only when the queue is full. - acquire() returns a QueuePermit that frees the slot exactly once, on scope exit or deinit, so a dropped streaming response can't leak it and wedge the server - Cancel queued waiters cleanly: remove the waiter and throw CancellationError - --max-queue-depth (default 16); reject negative values - hasRecurrentState skips prefix-reuse accounting for recurrent (SSM/hybrid) models - RequestQueue, QueuePermit and ServerError live in CoreAILMCommon, unit-tested via CoreAILMCommonTests
stikves
force-pushed
the
sukru/serve-v2-public
branch
from
September 14, 2026 16:13
0a24579 to
5696175
Compare
stikves
requested review from
Lewis300,
alejandro-isaza,
carinapeng,
chpriyal,
kevchengcodes and
tjia1818
September 14, 2026 16:14
alejandro-isaza
approved these changes
Sep 14, 2026
Replace the Mutex<Bool> once-guard with a lock-free Atomic<Bool>.compareExchange; the release path takes the RequestQueue Mutex, so relaxed ordering is sufficient. Add a concurrent-release unit test that races 50 release() calls against a single queued waiter.
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.
Summary
The llm-server currently gates concurrency with a binary busy flag: while one
request is generating, any concurrent request is rejected immediately with
429. This PR replaces that gate with an asyncRequestQueue, so concurrentrequests wait in a bounded queue and are rejected only when the queue is full.
Changes
RequestQueue(CoreAILMCommon): an async semaphore built onwithCheckedThrowingContinuationwith an acquired / rejected / queued statemachine. Replaces
tryAcquire()/release()and thegeneratingflag.acquire()returns aQueuePermitthat frees the slot exactly once — onexplicit
release()or, as a backstop, on deallocation, so a droppedstreaming response can never leak the slot and wedge the server.
while queued (e.g. on shutdown), the waiter is removed and its
acquire()throws
CancellationErrorinstead of leaking its continuation or being handedthe slot after the fact.
--max-queue-depth(default 16): how many requests may wait before theserver returns
429with aqueue_fullerror. Rejected as invalid ifnegative;
0means no queuing (second concurrent request gets an immediate429).hasRecurrentStateonInferenceEngine(defaultfalse; overridden bythe sequential and pipelined engines): recurrent (SSM / hybrid) models can't
reuse a token prefix, so the server skips the prefix-reuse fast path and counts
a miss. Engine correctness on rewind is already enforced by the engine itself;
this only keeps the server's reuse stats and logs accurate.
ServerError.queueFull(depth:)for the rejection path.Behavior
429429429(queue_full)/readynow reports busy based on queue activity rather than the removedgeneratingflag.Testing
RequestQueueunit coverage (inCoreAILMCommonTests): immediate acquire,concurrent waiting, FIFO wakeup, rejection at
maxDepth,maxDepth == 0,negative-depth clamp, idempotent permit release, and cancellation of a queued
waiter.
CoreAILMCommonTests(52) pass;llm-serverbuilds.muse_glimmer_30b_4bit_dynamic:429.queue_full. Thismatches 1 in-flight + 16 queued at the default depth.