Skip to content

Release GGUF context while tool approval is pending - #10673

Merged
Lyxot merged 14 commits into
unslothai:mainfrom
Imagineer99:fix/tool-approval-context-release
Sep 14, 2026
Merged

Lyxot merged 14 commits into
unslothai:mainfrom
Imagineer99:fix/tool-approval-context-release

Conversation

@Imagineer99

@Imagineer99 Imagineer99 commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

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 1ad44677d4 and 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:

Scenario Baseline Fix
Fresh A waits for approval, short B B completes before decision B completes before decision
Long A waits, then Deny B queued until A finishes B completes while A waits
Long A waits, then Allow B queued until A finishes B completes while A waits

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-14T14:10:50.618137Z e9a0009 Manual request
🔒 Security Review ✅ Completed 2026-09-09T21:48:37.840469Z 0c02657 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/routes/inference.py Resolved
Comment thread studio/backend/routes/inference.py Resolved
@danielhanchen

Copy link
Copy Markdown
Member

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?

@danielhanchen

Copy link
Copy Markdown
Member

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
@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Pushed a rework of the fix, plus a merge of latest main.

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 __verbose.id_slot, requested with response_fields narrowed to that field so the verbose object stays small. The erase declines unless the server is still the one that decoded the round and --slot-save-path is in play.

The three earlier review threads are answered inline and resolved.

Validation

pytest studio/backend/tests/test_tool_approval_context_release.py \
       studio/backend/tests/test_tool_approval_cache_reclaim_route.py \
       studio/backend/tests/test_llama_admission.py \
       studio/backend/tests/test_llama_admission_compat_matrix.py
# 134 passed, 5 skipped

pytest studio/backend/tests/test_llama_cpp_tool_loop.py
# 164 passed

@codex review

@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

@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". get_available_slot picks by longest-common-prefix similarity when --slot-prompt-similarity is set, and otherwise takes the least recently used idle slot. A chat parked on an approval prompt is idle by construction, so its slot is a prime LRU candidate, and parking hands the pool slot back immediately — the gap before the erase is however long the human takes to answer.

What that costs is bounded to a prefix reprocess for whoever inherited the slot, never a wrong answer and never an over-commitment:

  • SERVER_TASK_TYPE_SLOT_ERASE defers rather than fails when the slot is processing, so the erase lands when that chat next goes idle and it re-prefills on its following round.
  • The budget stays honest either way. If the slot was reassigned, the new request's prefill already dropped our cells, so crediting the parked holder's tokens back is exactly right; if it was not, the erase drops them. There is no state where we hand tokens back while our own KV is still resident.

Narrowing it further would mean asking llama-server what a slot currently holds before erasing (GET /slots, gated on --slots) or a conditional-erase API that does not exist. Both are a different change from this one, so I have left the behaviour as is and documented the hazard on release_idle_chat_slot rather than implying a guarantee the endpoint does not give.

What does the re-prefill cost on long context?

One full prompt reprocess for the approved chat, at prompt-processing speed — prompt_clear() drops the cells rather than spilling them to the prompt cache, so there is nothing to restore from.

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 POST /slots/{id}?action=save before the erase and action=restore on resume — --slot-save-path is already required for the erase, so the plumbing is there, and it would turn the reprefill into a disk read. I have kept it out of this PR to hold the scope down.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/routes/inference.py Resolved
…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.
@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Pushed the fix for the P1 above. The overcommit half of that finding is pre-existing — recost_waiting(..., allow_yield=False) has always declined and let the round continue at its old figure — but the erased-cache half is real and specific to this change, so I closed it rather than deferring: a slot whose context was explicitly erased holds no cells, which is exactly the condition _openai_llama_admission_can_yield is false for, so the round after a reclaim may now yield and wait for room instead of decoding over a refusal. Details and the covering tests are in the thread.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/routes/inference.py Resolved
… 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.
@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/routes/inference.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/routes/inference.py Resolved
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.
@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

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 release_parked_cache() ahead of the resume, which is where it belonged.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/routes/inference.py Resolved
…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.
@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 7f3fe5fbb3

ℹ️ 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".

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.
@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

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 --slot-save-path requirement and the deferred erase behind it, __verbose appearing only on a stream final result, and why a resuming holder claim on room is not the same number as the slot it holds back. Field comments the names already carried and prose restating the next statement are gone.

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 httpx.post stub, and release_idle_chat_slot catches Exception, so the failure was swallowed and read back as the refusal the test expected.

pytest studio/backend/tests/test_tool_approval_context_release.py studio/backend/tests/test_llama_admission*.py
# 182 passed, 5 skipped

pytest studio/backend/tests/test_llama_cpp_tool_loop.py
# 164 passed

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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.
@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Pushed c113fbe, which fixes a real regression the review just caught — and one I introduced by accident rather than by design.

_CombinedCancelEvent.wait is not part of this change at all. A stray edit overwrote its early return True with an expression from release_idle_chat_slot, so an already-set event raised NameError instead of reporting cancellation, turning a Stop or unload during a GGUF load into a load failure. The line is back to what the file has carried since the health wait learned to honour a cancelled load, and test_llama_cpp_wait_for_health.py now matches the merge base exactly.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Closed the P1 on _ticket_position_locked without a code change, with the reproduction in its thread.

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 reclaim_would_admit offering the retained approval on the first poll and both tickets resuming, because every token of committed is held either by a parked holder reclamation can take or by a decoding round that ends. The suggested remedy would let small resumes overtake a large one each time it is momentarily unaffordable, which is the starvation the reservation exists to prevent.

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

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".

@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/routes/inference.py Resolved
@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Merged latest main (03af220ac0) into the branch. Staging CI had flagged two studio workflow-lint failures and the shell installer tests, none of them in files this branch touches — the branch had simply fallen seven commits behind, including fixes to studio-update-smoke.yml and wheel-smoke.yml. They pass on the merged head. The Core (HF=...) jobs that also failed run unsloth_zoo @ main, a different repository, with failures in its alloc-conf and vllm-flashinfer suites.

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 release_idle_chat_slot; what does not follow is the budget consequence, since the second chat commitment and its resident total after the next round are the same with or without the erase — it re-prefills tokens it would otherwise have reused. The residual is that chat losing its prefix, and not getting the safe yield the parked chat gets.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/routes/inference.py Resolved
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.
@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@Lyxot

Lyxot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Merged latest main (a6cf5962b7) and closed the two open threads.

The gating half of the slot-metadata finding was real and is fixed: on_decode_slot now travels with payload.stream, so the non-streaming drain — which never parks and never starts a watcher — no longer asks for a slot it cannot use. The cost half was wrong and the docstring that said it is corrected; response_fields narrows the same payload __verbose rides on, so the addition was one integer on the final delta.

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 main — stalls to the same deadline with the same committed. Parking trades a slot back and keeps the tokens, so a reparker's budget arithmetic is unchanged either way, and --cache-ram 0 cannot produce a reparker at all. Reasoning in the thread.

Staging CI on the previous head flagged the formatter fixed-point test against studio/backend/core/inference/llama_cpp.py; main hit the same thing and fixed it in #10926, which this merge picks up. The remaining studio UI failures were a WebKit/Firefox permission-pill mount and two reasoning_toggle parity digests that differ in opposite directions across repetitions, on a branch that changes no frontend file — the chromium arm passed the same assertion in the same run.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: e9a0009c7f

ℹ️ 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".

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Lyxot
Lyxot merged commit c2bfd21 into unslothai:main Sep 14, 2026
45 of 48 checks passed
@Imagineer99

Imagineer99 commented Sep 14, 2026 •

Copy link
Copy Markdown
Member Author

@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 --cache-ram 0.

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, e9a0009c7f.

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.

rhsCZ pushed a commit to rhsCZ/unsloth that referenced this pull request Sep 15, 2026
…ool-approval park reclaim from unslothai#10673 and this branch's preemption on one ticket ledger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants