Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Give the cancel drain a budget sized for a loaded runner (#10008)

Daniel Hanf1fc268bf41c
diff --git a/studio/backend/tests/test_openai_tool_passthrough.py b/studio/backend/tests/test_openai_tool_passthrough.py
index 803882dac07..68a0a48894a 100644
--- a/studio/backend/tests/test_openai_tool_passthrough.py
+++ b/studio/backend/tests/test_openai_tool_passthrough.py
@@ -5206,13 +5206,26 @@ class TestGgufVisionToolRouting:
current_subject = "test",
)
)
- assert await asyncio.to_thread(started.wait, 1.0)
+ # Generous budgets. What this test asserts is that cancelling the
+ # request drains the worker, and none of the numbers below are part
+ # of that: they only bound how long to wait before calling it hung.
+ # A one-second bound on a THREAD START is a bound on the scheduler,
+ # not on this code, and it went red once on a runner busy with the
+ # rest of the backend suite. Failing here still takes seconds, and
+ # the assertion is unchanged.
+ assert await asyncio.to_thread(started.wait, self._DRAIN_BUDGET_S)
task.cancel()
with pytest.raises(asyncio.CancelledError):
- await asyncio.wait_for(task, timeout = 1.0)
-
- assert released.is_set()
+ await asyncio.wait_for(task, timeout = self._DRAIN_BUDGET_S)
+
+ # Waited on, not sampled. Cancelling the task unblocks the awaiting
+ # coroutine; it does not join the worker, which is off polling
+ # cancel_event every 5ms and only then sets this. Reading it the
+ # instant the await returns is a race that happens to be won on an
+ # idle box, and it is the drain itself that matters, not whether it
+ # had already finished by the time we looked.
+ assert await asyncio.to_thread(released.wait, self._DRAIN_BUDGET_S)
assert get_llama_admission_queue("http://llama.tool.test").snapshot().active == 0
[entry] = monitor.snapshot()
assert entry["status"] == "cancelled"
@@ -5325,6 +5338,11 @@ class TestGgufVisionToolRouting:
assert json.loads(response.body)["choices"][0]["message"]["content"] == "reply"
assert captured["perf_callback"] is None
+ # Wall-clock bound for the cancel drain. Only ever hit when something is
+ # genuinely stuck, so it is sized for a loaded runner rather than for the
+ # ~5ms this takes when it works.
+ _DRAIN_BUDGET_S = 30.0
+
def test_non_streaming_gguf_cancel_drains_worker(self, monkeypatch):
async def _run():
import routes.inference as inf_mod