Repository navigation
Studio: re-run admission when a cancelled waiter was blocking the line - #9415
Conversation
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
|
Confirmed against main: cancel() in studio/backend/core/inference/llama_admission.py is the only capacity-freeing path that does not re-run _grant_waiters_locked, so the waiters behind a cancelled oversized head sit there until unrelated traffic arrives. Will get this reviewed. |
923bcb3 to
9337ebc
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. 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. You're on a roll. 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". |
Follow-up to #9392, which added the KV budget to llama admission. Reviewing that PR turned up a deadlock in
LlamaAdmissionQueue.cancel()that the budget makes reachable, and I got the diagnosis wrong the first time, so this fixes the mechanism that is actually live.The bug
Every path that frees capacity ends by re-running admission.
cancel()did not:A cancelled waiter owns no slot and no tokens, so on the face of it there is nothing to hand back and nothing to re-run. That is true for a waiter in the middle of the line. It is not true for the head, because
_grant_waiters_lockedtests the head's own cost against the remaining budget and stops there:That head-of-line rule is deliberate (granting past a large waiter whenever a small one fits would starve it). But it means a large head blocks smaller waiters behind it, and when that head cancels, nothing re-opens the line.
Reproduction
Capacity 4, budget 2048. A=1000 admitted. B=1500 queued, blocking on budget. C=500 queued behind it. Cancel B through the ordinary public path,
reservation.cancel():C wants 500 tokens with three free slots and 1048 free budget, and stays queued. It is only reconsidered on the next reserve or release. When the one active lease is parked waiting on a tool approval prompt, that never arrives.
The fix
One call, inside
cancel(), still under_lock:The cancelled waiter is already off
_waiters, so the loop sees the new head. In thegranted_leasebranch those tokens are still in_committedat that point, so granting here is conservative and thelease_to_release.release()below re-grants anyway._grant_waiters_lockedonly doescall_soon_threadsafe, so there is no re-entrant lock acquisition. FIFO is unchanged.Tests
TestCancellingTheBlockingHeadReopensTheLineintests/test_llama_admission_kv_budget.py:test_a_smaller_waiter_runs_once_the_oversized_head_is_cancelledreproduces the deadlock. Fails before this commit, passes after.test_cancelling_a_waiter_that_is_not_the_head_admits_nobody_earlyguards the head-of-line trade in the other direction: cancelling a tail waiter must not let anyone skip the oversized head. Passes before and after, so the fix does not quietly turn FIFO into best-fit.test_llama_admission_kv_budget,test_llama_admission_kv_budget_media_and_tools,test_llama_admission,test_anthropic_admission: 130 passed.Note on the review of #9392
An earlier revision of this was raised there and I turned it down, on the grounds that a cancelled waiter can never be left at the head because
cancel()removes it under the lock before cancelling its future. That part is correct and still is. It was the wrong thing to check: the bug is not a dead waiter sitting at the head, it is a live head being removed with nothing re-running admission behind it. I claimed a control run throughcancel()granted the waiter immediately. It does not, and re-running it cleanly is what turned this up.