Repository navigation
Release GGUF context while tool approval is pending - #10673
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0c02657654
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
|
Confirmed this hits the path in studio/backend/core/inference/llama_admission.py where try_park hands back the slot but keeps the whole token commitment, so a pending approval can still block a queued chat. One thing before I review: release_idle_chat_slot only checks base_url, while the slot number comes from the previous round's stream, so could you confirm llama-server cannot have reassigned that slot to another chat by the time the erase is sent? |
|
Confirmed the stall path in studio/backend/core/inference/llama_admission.py where a parked approval keeps its whole token commitment, and the erase acknowledgement gate looks like the right guard. Since reclaiming the slot means the approved chat re-prefills its whole prompt, could you confirm what that costs on the long-context case before I review? |
Parking a chat on a tool-approval prompt returned its serving slot to the pool but kept its KV tokens committed, so the budget still counted context llama-server was holding for a run that had stopped decoding. On a `--kv-unified` server that budget is the only thing preventing an overcommitted shared cache, so an unanswered approval could keep a queued chat out indefinitely. A parked holder now records what erasing its cached context would hand back, and erases only once the queue reports that the freed room would actually admit a claimant. Erasing is not free -- llama-server drops the cells instead of spilling them to its prompt cache -- so a single user with one long chat no longer pays a full prompt reprocess after every approval. Resuming from a park now has to win the tokens back as well as a slot. The claim is held back from new arrivals so a trickle of small chats cannot starve it, and lapses after a deadline so a holder that never returns cannot reserve room forever. A lapsed ticket keeps its place in the slot order but stops reserving room, and is still never admitted over budget: llama.cpp answers an exhausted cache by clearing every slot it is decoding. A ticket blocked on room does not pin a slot a later approval could pay for, which is what would otherwise deadlock a one-slot server. The slot a round decoded on is read from the final chat-stream result's `__verbose.id_slot`, requested with `response_fields` narrowed to that field. Erasure declines unless the server is still the one that decoded the round and `--slot-save-path` is in play, and an unacknowledged erasure keeps the reservation.
# Conflicts: # studio/backend/core/inference/llama_admission.py # studio/backend/tests/test_llama_cpp_tool_loop.py
|
Pushed a rework of the fix, plus a merge of latest What changed The original version erased the slot's cached context on every approval prompt. That is not free — llama-server drops the cells rather than spilling them to its prompt cache — so a single user with one long chat paid a full prompt reprocess after every "Allow", whether or not anyone was waiting for the room. Reclamation is now demand-driven. A parked holder records what erasing would hand back, and erases only once the queue reports that the freed room would actually admit a queued claimant. The tokens are handed back only after llama-server acknowledges the erasure; an unacknowledged erase keeps the reservation. Resuming from a park now has to win the tokens back as well as a slot. The claim is held back from new arrivals so a trickle of small chats cannot starve an approved resumption, and it lapses after a deadline so a holder that never returns cannot reserve room forever. A lapsed ticket keeps its place in the slot order but stops reserving room, and is still never admitted over budget — llama.cpp answers an exhausted cache by failing and clearing every slot it is decoding, so overcommitting to end one chat's wait would end every other chat outright. A ticket blocked on room does not pin a slot a later approval could pay for, which would otherwise deadlock a one-slot server. The slot a round decoded on is read from the final chat-stream result's The three earlier review threads are answered inline and resolved. Validation @codex review |
|
@danielhanchen — answers to both questions. Can llama-server have reassigned the slot by the time the erase is sent? Yes, and not only in a narrow window, so the guard is not "this cannot happen" but "the worst case is bounded". What that costs is bounded to a prefix reprocess for whoever inherited the slot, never a wrong answer and never an over-commitment:
Narrowing it further would mean asking llama-server what a slot currently holds before erasing ( What does the re-prefill cost on long context? One full prompt reprocess for the approved chat, at prompt-processing speed — The reason that is acceptable here is that it is no longer paid on every approval. This push changed reclamation from unconditional to demand-driven: the parked chat erases only once the queue reports that the freed room would actually admit a blocked claimant. A single user with one long chat and no contention now pays nothing at all, where the first version of this PR charged a full reprefill after every "Allow". Under contention the trade is one chat's reprefill against another chat waiting indefinitely, which is the case the bug is about. If that cost turns out to matter under real multi-user load, the natural follow-up is |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f47cf5348
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
…into Re-costing yields a round's commitment only where llama-server clears an idle slot's KV, because elsewhere the cells stay resident and yielding would promise the same capacity twice. Studio launches exactly that way on Windows under full GPU offload, so there a growth re-cost declines and the larger prompt goes out against a budget the pool refused it. A slot whose context was explicitly erased holds no cells, so that reasoning does not apply to it: yielding hands back room that really is free. The round after a reclaim now says so, and may wait for room instead of decoding over the refusal.
|
Pushed the fix for the P1 above. The overcommit half of that finding is pre-existing — @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 50d320d2f4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
… from Answering the approval cancels the reclamation watcher, but the erase it started runs in a worker thread that the cancel does not stop. The request has already gone out, so losing its result left the next round pricing itself against cells llama-server no longer holds -- and declining to yield, on the servers where that matters most. The worker records the erase itself, so a cancel cannot lose it. Handing the tokens back stays on the loop, where the cancel skips it: releasing beside a resume that has already priced itself would leave this chat decoding on a commitment of nothing.
|
Pushed the fix for the cancellation race. The erase now records its own result inside the worker, so answering the approval cannot drop it; handing the tokens back deliberately stays on the loop where the cancel skips it, since releasing there would race a resume that has already priced itself. Reasoning and the covering test are in the thread. @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ecf1b754ad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ecf1b754ad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
Cancelling the reclamation watcher does not stop the erase it started: the worker thread runs on and the request lands whether or not anyone is still listening. The resumed round could therefore price itself against cells llama-server was in the middle of dropping, and on backends without idle-slot clearing decline to yield and decode over its own reservation. The watcher is now asked to stop rather than cancelled, and the ask is only honoured before the erase is sent. Past that point the cells are going regardless of what this chat does, so the resume waits for the result and is told, bounded by the erase request's own timeout. Handing the tokens back lands ahead of the resume too, which is where it belonged.
|
Pushed the ordering fix. The watcher is now asked to stop rather than cancelled, and the ask is honoured only before the erase is sent — past that the request is already with llama-server, so the resume waits for the result instead of pricing itself against cells that are mid-drop. That also lands The P2 about several watchers erasing from the same aggregate is true and deferred, with the reasoning in its thread: the aggregate test is what makes joint reclamation possible at all, the over-reclaim window is one poll interval wide, and electing which holders contribute is queue-side coordination better measured against real multi-approval traffic than argued here. @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 40f2dcb512
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
…e resume Asking the watcher to stop did not interrupt its poll, so every approval paid up to a poll interval before resuming -- including the ordinary one, where nothing was ever erased and there was nothing to wait for. Across an approval-heavy tool loop that accumulates. The poll now waits on the stop request rather than sleeping past it. A watcher still polling gives up at once; one that is already sending is still waited out.
|
Pushed the fix for the poll-interval wait. That one was a regression from the previous commit rather than an edge case — asking the watcher to stop did not interrupt its sleep, so every approval paid for it, including the ordinary one that erased nothing. The poll now waits on the stop request instead of sleeping past it. @codex review |
|
Codex Review: Didn't find any major issues. 🎉 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". |
Cuts the added comments and docstrings to what the code cannot state for itself: llama.cpp clearing every decoding slot on an exhausted cache, the --slot-save-path requirement and the deferred erase behind it, `__verbose` appearing only on a stream's final result, and why a resuming holder's claim on room is not the same number as the slot it holds back. Field comments the names already carried, one-line docstrings on private helpers, and prose restating the next statement are gone. Consolidates the tests to the invariants that carry the change: reclamation offered only against blocked demand, a resume winning back both slot and room without being overtaken, a claim it cannot pay for never pinning a slot a later approval can use, and an erasure the engine has not confirmed leaving the reservation in place. The deadlock and the erase-acknowledgement matrix are parametrized rather than written out per case. The ASGI-level reclamation test is removed with them, so the route wiring it covered -- the erased-cache re-cost, waiting out an in-flight erase, and recording one from its worker -- is no longer exercised by the suite.
|
Pushed a comments-and-tests trim, no behaviour change. Comments and docstrings are cut to what the code cannot state for itself: llama.cpp clearing every decoding slot on an exhausted cache, the Tests are consolidated onto the invariants that carry the change — reclamation offered only against blocked demand, a resume winning back both slot and room without being overtaken, a claim it cannot pay for never pinning a slot a later approval can use, and an unconfirmed erasure leaving the reservation in place — with the deadlock (lapsed and not) and the erase-acknowledgement matrix parametrized rather than written out per case. Worth flagging rather than burying: the ASGI-level reclamation test went with them, so the route wiring it covered — the erased-cache re-cost, waiting out an in-flight erase, and recording one from its worker — is no longer exercised by the suite. Those paths are unchanged and were mutation-checked when they landed, but they are untested as of this commit. Five mutations were re-run against what remains and each fails exactly the test that claims it: removing the demand gate, a resume that never re-takes its tokens, an unaffordable claim that still pins a slot, an erasure accepted without acknowledgement, and the erase guard removed. One of those only started failing after a fix to the test itself — it had been asserting inside an @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab4b7f8266
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
A stray edit replaced the early return in `_CombinedCancelEvent.wait` with an expression from an unrelated function, so an event already set before the wait raised NameError instead of reporting cancellation. A Stop or unload landing during a GGUF load read back as a load failure. Restores the line this file has carried since the health wait learned to honour a cancelled load.
|
Pushed c113fbe, which fixes a real regression the review just caught — and one I introduced by accident rather than by design.
I audited the whole branch for the same class rather than the single instance: every removed production line across the three changed files belongs to this change, and all three modules compile clean. @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c113fbeeee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
|
Closed the P1 on The mechanism the review describes is real — a later affordable resume does wait behind an earlier unaffordable one — but the consequence does not follow. Running the exact scenario shows Flagged in the thread and repeating here: the test that pinned that ordering was dropped in the consolidation two commits ago to meet the test-ratio limit, so the property is currently unguarded. @codex review |
|
Codex Review: Didn't find any major issues. Delightful! 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: be4eb67fc1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
|
Merged latest Closed the P1 about erasing a reassigned slot without a code change, with the reasoning in its thread. The reassignment is real and already documented on @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: be4eb67fc1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
The slot a round decoded on is read for the approval park, which only the streaming path performs; the non-streaming drain never parks and never reclaims. Requesting it there asked llama-server for metadata nothing would read. Also corrects the test that justified the gate. Verbose alone would attach the whole prompt, but it never travels alone -- `response_fields` narrows the object to `id_slot` before it is sent, so the cost of asking is small. The reason to gate is that the answer is unused, not that it is expensive.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 775ee2d6d1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
|
Merged latest The gating half of the slot-metadata finding was real and is fixed: The reparking finding reproduces exactly as written, and is left alone: the identical scenario with the approval-waiting chat merely holding its lease — no parking, no reclamation, which is Staging CI on the previous head flagged the formatter fixed-point test against @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". |
Lyxot
left a comment
There was a problem hiding this comment.
Safe to merge.
The fix is in the right place: the approval wait was keeping the whole token reservation, and parking now hands back the KV on demand rather than unconditionally, so nobody pays a prefix reprocess unless a blocked claimant is actually waiting on that room. Failure modes all fall back to the old behaviour — an unacknowledged erase, missing slot metadata, a renumbered server after a reload, or a build without --slot-save-path each retain the reservation rather than overcommit the unified cache.
Scope is backend-only, six files, 504 added lines with tests at 29.17%. The branch is current with main (a6cf5962b7), and CI failures on it are the three Core jobs, which fail in unsloth_zoo @ main's own pytest step, and one studio job that failed only on its artifact upload after every test step passed.
Two caveats for whoever merges, neither blocking:
Slot persistence is disabled on Windows when the slot path is not ASCII, and reclamation is gated on it, so on those installs this degrades to the current behaviour rather than fixing it. The desktop report in the issue is a Windows one and was not reproduced natively, so it is worth confirming there separately.
A growing tool loop that has yielded its commitment is not counted as a claimant, so it cannot trigger reclamation of a parked cache and waits out its recost deadline instead. That is the same on main — measured both ways, with and without parking, identical result — and it cannot arise under --cache-ram 0 at all, since a round that cannot yield never reparks. Worth a follow-up alongside electing which parked holders contribute, rather than widening this change.
|
@danielhanchen Following up now that this is merged, with measurements for your re-prefill cost question. Measured on Qwen3-4B-Instruct-2507 UD-Q4_K_XL with an RTX 5070 Ti under WSL/Linux, using four slots, 35k requested context, unified KV, and For a 30k-token prefix, median request-to-first-token time was 29 ms with the cache retained versus 6.176 s after erase, an added 6.15 s. The three erased runs were 6.152–6.356 s. Engine counters confirm that the retained case processed only the 16 new tokens, while the erased case processed all 30,016 tokens. The erase acknowledgement itself took a median 3.61 ms. Added first-token latency was 0.99 s at 8k and 2.44 s at 16k. This is a controlled engine-level comparison isolating the re-prefill penalty, excluding approval, tool execution, and admission wait. The merged demand-driven implementation avoids explicit erasure when nobody is blocked; its nine focused reclamation tests passed on the final PR head, These numbers document the tradeoff for future performance work: when reclamation occurs, this configuration pays approximately six seconds of extra resume latency at 30k. They do not establish end-to-end latency under concurrent load or performance on the reported 27B model or native Windows; those need separate measurements. |
…ool-approval park reclaim from unslothai#10673 and this branch's preemption on one ticket ledger
Release GGUF context while tool approval is pending
A long chat waiting for tool approval can keep another chat queued even when the monitor reports four free slots. Parking returns the decode slot but previously kept the whole context reservation.
Record the actual llama-server slot from completion metadata and ask the engine to erase that completed round's cached context before returning its token reservation. When approval is resolved, reacquire both a serving slot and the retained token allowance before continuing. Failed erasures or unavailable slot metadata preserve the existing reservation. Repeated approvals without a new decode reuse the reclamation result.
This can require prompt reprocessing when the approved chat resumes, in exchange for letting other chats use the context while a human decision is pending.
Addresses the context-reservation half of #10671, which stays open: the issue also asks that the UI explain a context-budget wait when capacity cannot be reclaimed, and the original desktop report's Windows build, quantization, MTP setting and 30k-to-35k threshold remain unreproduced.
Validation
Identical live HTTP probe on baseline
1ad44677d4and the fix, real Qwen3-4B-Instruct-2507 UD-Q4_K_XL on RTX 5070 Ti under WSL/Linux, 35,000 context, four effective slots,--kv-unified --cache-ram 0:The same probe fails its intended assertion on the baseline and passes on the fix. Baseline stalled cases report 0 active, 1 queued, 4 free. Both fixed long-chat cases report no queued requests before approval is resolved.
150 focused tests passed, covering admission accounting, resume capacity, cancellation/release races, erasure acknowledgment and failure, tool streaming, recosting, and stress scenarios. Repository formatter, diff checks, and scoped worktree audits passed.
Not yet validated on native Windows v0.1.808-beta, the reported Qwen3.8 27B quantization, MTP, or the exact reported 30k-to-35k threshold. No cross-platform CI run is claimed.