Studio: queue local GGUF OpenAI-compatible requests before llama-server - #7047
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces an admission control mechanism for local llama-server generation requests, managing active upstream requests and queuing excess ones using a cancellable FIFO queue. It integrates this control across various streaming and non-streaming inference routes and updates the llama-cpp backend to track effective parallel slots. The reviewer identified a critical issue where a cancelled waiter future could cause waiting loops to spin infinitely and consume 100% CPU; they suggested adding and checking an is_cancelled property on reservations to prevent this. Additionally, the reviewer pointed out a potential double-exit of the tracker context manager if a stream generator fails before yielding, suggesting that stream_started be set to True immediately upon iterator creation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
b51fdba to
214e05d
Compare
214e05d to
3085340
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
I wanted to confirm this fixes a real dead stream and not just a slow first byte, so before merging I reproduced it. One long request held a single-slot llama-server (
Studio flushes the 200 and SSE headers before the body, so with admission off that silence sits on an already-open stream, which is what a client can time out on. Holding the request in the queue and keeping it alive is the right fix, since once the response has started you can't hold it back. CI is green across the fork matrix, and the Gemini "critical" notes describe code your commit already has. Follow-up I pushed: the admission registry keys on the llama-server Merging. |
Summary
This adds a Studio-side admission queue for local GGUF OpenAI-compatible requests before they reach
llama-server.The queue is scoped to local GGUF
/v1/chat/completionsand/v1/responsespaths, and uses the effective llama.cpp parallel slot count so Studio does not forward more concurrent upstream requests than the running backend can service.Problem
When Studio starts llama.cpp with a small
--parallelvalue, clients can still send multiple OpenAI-compatible requests at once. Before this change, excess requests were forwarded tollama-server, where they waited behind the active request. For streaming clients this can look like a stalled or terminated stream because no SSE bytes are emitted while the request is stuck upstream.Changes
llama_admissionqueue with bounded capacity, timeout, cancellation cleanup, and async release handling.LlamaCppBackend.effective_parallel_slotsafter a healthy load, and reset it on unload/cleanup./v1/chat/completionsand/v1/responsesrequests before forwarding to llama.cpp.UNSLOTH_OPENAI_COMPAT_ADMISSION_CONTROLUNSLOTH_OPENAI_COMPAT_ADMISSION_QUEUE_TIMEOUTUNSLOTH_OPENAI_COMPAT_ADMISSION_KEEPALIVE_INTERVALUNSLOTH_OPENAI_COMPAT_ADMISSION_MAX_QUEUEThis intentionally does not add UI settings and does not gate
/v1/completionsin this PR.Validation
Automated checks:
Source-clone LAN API checks:
Direct API checks:
Real client checks from a LAN Ubuntu VM against
http://192.168.10.113:8899/v1:For the Codex CLI check, the GGUF was loaded with a 16k context because Codex's default prompt envelope is larger than an 8k context window.
Notes
This builds on the streaming hardening merged in #6950. It handles a different layer: request admission before llama.cpp receives the request, so streaming clients get an immediate SSE response and keepalives while waiting instead of a silent upstream wait.