Repository navigation
Give the cancel drain a budget sized for a loaded runner - #10008
Conversation
Backend CI (Python 3.13) failed on main 8849f48: test_non_streaming_gguf_cancel_drains_worker - assert False That assert is `await asyncio.to_thread(started.wait, 1.0)`, so what timed out is a THREAD START. It is a bound on the scheduler, not on the code under test, and the job was running the rest of the backend suite beside it. What this test asserts is that cancelling the request drains the worker. None of the numbers are part of that claim: they only decide how long to wait before calling it hung. So they move to one constant, 30s, sized for a loaded runner rather than for the ~5ms this takes when it works. The last assertion also stops being a sample. 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 `released`. Reading `released.is_set()` the instant the await returns is a race that happens to be won on an idle box. It is waited on now, because the drain is the point, not whether it had already finished by the time the test looked. It keeps its teeth. With the worker changed to ignore cancel_event entirely, the test fails, taking 50s to do it: FAILED ...::test_non_streaming_gguf_cancel_drains_worker 1 failed, 346 deselected in 50.05s Honest about what this is: a robustification, not a demonstrated fix. The original failure did not reproduce here. Pinned to one core against 16 spinners the test still passed, taking 173s against a normal 4.4s, a 39x slowdown that never came near the one-second bound. One failure in eight runs on main, green on the four commits before it. The budgets were incidental either way, and widening them costs a test that is already only slow when something is wrong. studio/backend/tests/test_openai_tool_passthrough.py: 347 passed.
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: b2120cf4a5
ℹ️ 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".
| # 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) |
There was a problem hiding this comment.
Preserve the drain-before-slot-release assertion
Do not wait for released after the cancelled request task has already completed. If cancellation ever returns and releases the admission slot before the blocking worker exits, the worker will normally observe cancel_event milliseconds later and this new 30-second wait will still pass, so the test no longer detects the concurrency regression named in its title. The original immediate check is not inherently racy under the required behavior: _run_blocking_generation must drain the worker before propagating cancellation, and the worker sets released before it returns.
Useful? React with 👍 / 👎.
| # 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 |
There was a problem hiding this comment.
Apply the budget to the test that actually failed
Use this new budget in the immediately following test_non_streaming_gguf_cancel_drains_worker, which is the exact test identified as flaky in the commit message. Its thread-start and task waits remain hard-coded to 1.0, so a loaded runner can reproduce the same failure despite this change; only the earlier tool-enabled sibling currently references _DRAIN_BUDGET_S.
Useful? React with 👍 / 👎.
…the drain check deterministic (unslothai#11662) test_non_streaming_gguf_cancel_drains_worker failed again with assert False on its 1.0s start wait (Backend CI on unslothai#11644). unslothai#10008 sized this for a loaded runner, but its hunk landed on the tool twin of the test it named, so that test and three others shaped like it kept waiting 1.0s for a thread-pool worker to be scheduled. All of them now use one module-level _DRAIN_BUDGET_S (30s, only reached when something is stuck). The stub workers also linger 0.3s after seeing the cancel flag, so a route that skips its drain is caught by released.is_set() every time rather than whenever the assertion beats the worker's 5 ms poll.
…the drain check deterministic (unslothai#11662) test_non_streaming_gguf_cancel_drains_worker failed again with assert False on its 1.0s start wait (Backend CI on unslothai#11644). unslothai#10008 sized this for a loaded runner, but its hunk landed on the tool twin of the test it named, so that test and three others shaped like it kept waiting 1.0s for a thread-pool worker to be scheduled. All of them now use one module-level _DRAIN_BUDGET_S (30s, only reached when something is stuck). The stub workers also linger 0.3s after seeing the cancel flag, so a route that skips its drain is caught by released.is_set() every time rather than whenever the assertion beats the worker's 5 ms poll.
Backend CI→(Python 3.13)failed on main8849f481d:That
assertisawait asyncio.to_thread(started.wait, 1.0), so what timed out is a thread start. It is a bound on the scheduler, not on the code under test, and the job was running the rest of the backend suite beside it.The change
What this test asserts is that cancelling the request drains the worker. None of the numbers are part of that claim; they only decide how long to wait before calling it hung. They move to one constant,
30.0, sized for a loaded runner rather than for the ~5ms this takes when it works.The last assertion also stops being a sample:
Cancelling the task unblocks the awaiting coroutine; it does not join the worker, which is off polling
cancel_eventevery 5ms and only then setsreleased. Reading it the instant the await returns is a race that happens to be won on an idle box. The drain is the point, not whether it had already finished by the time the test looked.It keeps its teeth
With the worker changed to ignore
cancel_evententirely:What this is, honestly
A robustification, not a demonstrated fix. The original failure did not reproduce here. Pinned to one core against 16 spinners the test still passed, taking 173s against a normal 4.4s — a 39x slowdown that never came near the one-second bound. It is one failure in eight runs on main, with the four commits before it green.
I am not claiming to have proven the mechanism. The budgets were incidental to the assertion either way, and widening them costs nothing on a test that is only slow when something is genuinely wrong.
studio/backend/tests/test_openai_tool_passthrough.py: 347 passed.