Repository navigation
Assert the companion scan's thread, not how fast the machine is - #11288
Conversation
test_companion_root_scan_does_not_block_the_event_loop failed on main in Backend
CI (Python 3.13, l-r) at 'assert loop_was_responsive', on a shard that took 565s
against a 371s baseline.
The assertion was time.monotonic() - started < 0.5, a proxy for the loop staying
responsive. It is only a proxy, and it measures the wrong thing: the elapsed
window includes dispatching asyncio.to_thread(entered.wait, ...) through the
default executor, so a runner that is merely busy blows the 0.5s budget while
the loop is behaving perfectly. Against a 1.0s block it had a 2x margin to spend
on scheduling.
routes.inference awaits the scan through
await asyncio.to_thread(local_gguf_companion_roots, ...)
so running on another thread IS the mechanism the wall clock was standing in
for. The test records the thread the scan executed on and compares it with the
loop's own thread, which is the same claim with no timing in it and cannot be
defeated by a slow machine. The waits that remain are generous upper bounds for
a hung test rather than thresholds anything is measured against.
Proved by making routes.inference call the scan synchronously instead of through
to_thread: the test fails with both idents equal. Restored, 694 passed.
Not reproduced locally first, unlike the sibling fix in #11284: CPU contention
on a pinned cpuset and a saturated default executor both left it passing 10 and
8 times. The CI traceback names the assertion, and the assertion is a wall-clock
threshold, so the diagnosis does not depend on reproducing the timing.
|
@codex review |
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. |
|
@codex security 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". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…othai#11288) test_companion_root_scan_does_not_block_the_event_loop failed on main in Backend CI (Python 3.13, l-r) at 'assert loop_was_responsive', on a shard that took 565s against a 371s baseline. The assertion was time.monotonic() - started < 0.5, a proxy for the loop staying responsive. It is only a proxy, and it measures the wrong thing: the elapsed window includes dispatching asyncio.to_thread(entered.wait, ...) through the default executor, so a runner that is merely busy blows the 0.5s budget while the loop is behaving perfectly. Against a 1.0s block it had a 2x margin to spend on scheduling. routes.inference awaits the scan through await asyncio.to_thread(local_gguf_companion_roots, ...) so running on another thread IS the mechanism the wall clock was standing in for. The test records the thread the scan executed on and compares it with the loop's own thread, which is the same claim with no timing in it and cannot be defeated by a slow machine. The waits that remain are generous upper bounds for a hung test rather than thresholds anything is measured against. Proved by making routes.inference call the scan synchronously instead of through to_thread: the test fails with both idents equal. Restored, 694 passed. Not reproduced locally first, unlike the sibling fix in unslothai#11284: CPU contention on a pinned cpuset and a saturated default executor both left it passing 10 and 8 times. The CI traceback names the assertion, and the assertion is a wall-clock threshold, so the diagnosis does not depend on reproducing the timing.
Summary
test_companion_root_scan_does_not_block_the_event_loopfailed onmaininBackend CI (Python 3.13, l-r)(run 35379669649, job 105712593993):on a shard that took 565s against a 371s baseline, i.e. a slower runner.
The assertion measured the machine, not the invariant
The window it measures includes dispatching
asyncio.to_thread(entered.wait, ...)through the default executor, so a busy runner blows the 0.5s budget while the loop is behaving perfectly. Against a 1.0s block that is a 2x margin to spend on scheduling.What it should assert
routes.inferenceawaits the scan throughso running on another thread is the mechanism the wall clock was standing in for. The test now records the thread the scan executed on and compares it with the loop's own thread, captured from inside the coroutine. Same claim, no timing, cannot be defeated by a slow machine.
The
Event.waittimeouts that remain are generous upper bounds so a broken run fails rather than hangs. Nothing is measured against them.Verification
What I could not do
I did not reproduce this locally first, unlike the sibling fix in #11284 where a pinned cpuset reproduced the flake 2 times in 12. Here CPU contention on a 2-CPU and then a 1-CPU cpuset left it passing 10 of 10, and saturating the default executor left it passing 8 of 8.
That is stated rather than glossed because it changes what the evidence is. The diagnosis does not rest on reproducing the timing: the CI traceback names the failing assertion, and that assertion is a wall-clock threshold on a machine-dependent window. The fix removes the timing dependence entirely rather than widening a budget, so there is no threshold left to tune against a runner I cannot measure.