tests/tools/test_serve_low_client.py::test_request_shape_concurrency_cap_and_error_propagation fails under load with peak 3 <= 2. The defect is in the test's own instrument, not in the client's concurrency cap.
The mechanism
_CompletionHandler counts in-flight requests by incrementing a shared active on entry and decrementing it in a finally:
self.wfile.write(body)
finally:
with self.lock:
type(self).active -= 1
The decrement runs after the response body has been written. The client is free to receive that response and dispatch its next request before the finished handler reaches its finally, so active transiently counts a handler that has already answered. At max_concurrency=2 the recorded peak reads 3, and the assertion fails.
Nothing is actually over-dispatched: the client never has more than two requests outstanding. The instrument counts handler lifetime while the assertion is about requests in flight, and those two differ by exactly the window between the last write and the finally.
Why it is load-sensitive rather than flaky
The window is short and widens under scheduling pressure. Observed on a box carrying many concurrent sessions; the same case passed 8 of 8 in isolation and 4 of 4 on full-suite re-runs immediately afterwards.
Evidence that it is not a change under test
Found during the third repair round of PR #1776, which touches nothing under tools/ or tests/tools/. tests/tools/test_serve_low_client.py is blob 10220a8969d82a167075224c49ad8f1be131ac60 on both that branch and origin/main — byte-identical. The module imports only the standard library plus tools.bench.*.
Why it matters beyond one red
A load-sensitive assertion in a shared suite trains readers to re-run rather than read, which is how a real regression gets waved through. This repository already carries that cost on test_cpu_x86_llamacpp_floor (#618); a second case of the same shape compounds it.
Owed
- Count what the assertion is about. Decrement before the response is written, or have the client acknowledge completion, or assert on a counter the handler owns for its whole lifetime rather than mixing the two.
- Decide whether
peak should be a strict bound at all, given the handler's lifetime necessarily exceeds the request's.
Filed by the operator rather than by the agent that found it: creating an issue is a remote write and that session had no recorded authority for one, so it reported the defect with its diagnosis instead of filing. That was the correct call.
tests/tools/test_serve_low_client.py::test_request_shape_concurrency_cap_and_error_propagationfails under load withpeak 3 <= 2. The defect is in the test's own instrument, not in the client's concurrency cap.The mechanism
_CompletionHandlercounts in-flight requests by incrementing a sharedactiveon entry and decrementing it in afinally:The decrement runs after the response body has been written. The client is free to receive that response and dispatch its next request before the finished handler reaches its
finally, soactivetransiently counts a handler that has already answered. Atmax_concurrency=2the recordedpeakreads 3, and the assertion fails.Nothing is actually over-dispatched: the client never has more than two requests outstanding. The instrument counts handler lifetime while the assertion is about requests in flight, and those two differ by exactly the window between the last write and the
finally.Why it is load-sensitive rather than flaky
The window is short and widens under scheduling pressure. Observed on a box carrying many concurrent sessions; the same case passed 8 of 8 in isolation and 4 of 4 on full-suite re-runs immediately afterwards.
Evidence that it is not a change under test
Found during the third repair round of PR #1776, which touches nothing under
tools/ortests/tools/.tests/tools/test_serve_low_client.pyis blob10220a8969d82a167075224c49ad8f1be131ac60on both that branch andorigin/main— byte-identical. The module imports only the standard library plustools.bench.*.Why it matters beyond one red
A load-sensitive assertion in a shared suite trains readers to re-run rather than read, which is how a real regression gets waved through. This repository already carries that cost on
test_cpu_x86_llamacpp_floor(#618); a second case of the same shape compounds it.Owed
peakshould be a strict bound at all, given the handler's lifetime necessarily exceeds the request's.Filed by the operator rather than by the agent that found it: creating an issue is a remote write and that session had no recorded authority for one, so it reported the defect with its diagnosis instead of filing. That was the correct call.