Repository navigation
Take the wall clock out of two backend guards that fail on a loaded runner - #10952
Conversation
…unner test_cache_does_not_bypass_expiry issued a key expiring in 600ms and asserted the first validate_api_key call still accepted it. That call runs PBKDF2, so on a busy runner the key is already expired when the first assertion reads it: assert None == 'unsloth'. Rewritten in the shape of its neighbour test_cache_does_not_bypass_revocation, warming the cache on a key valid for a day and then expiring the row, which also drops the 0.8s sleep. Verified it still fails when the expiry check is made conditional on a cache miss. The four ReDoS guards asserted a single wall-clock sample under 50ms. The tilde case measures about 11ms and was seen at 60.9ms on CI, which is preemption, not backtracking. They now take the fastest of five runs, since catastrophic backtracking costs seconds and every repeat pays it.
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. |
perf_counter still counts the time this process spends off the CPU, so under sustained contention every one of the five samples carries it and the minimum can still cross the budget. The budget is about the regex's own CPU work, so process_time measures it directly. Best-of-five stays on top for the contention process_time cannot see. Same pairing as test_tool_loop_controller.
…xture Third guard in the same family as the two already here. The fixture dribbles response headers from its own thread, and the test asserted `lines >= 3` immediately after the probe returned, which assumes 0.5s of probe bought that thread 0.5s of CPU. On a loaded runner it does not: seen on #10928 as AssertionError: fixture stopped trickling headers after 0 bytes on a probe that had timed out exactly as intended, so the assertion was reporting contention as a broken fixture. It now waits on an event the drip loop sets after its first byte instead of sampling a counter at an arbitrary moment. The companion `lines < 100` bound went the same way. It was a proxy for "the fixture is not sending whole header lines", measured through a byte count that a slow runner made small and a fast one made large. The property is about what the fixture writes, not how often it got to write it, so it is now asserted against the repeated chunk itself. Both directions mutation-checked: a fixture that never trickles fails the first, and a chunk carrying CRLF fails the second.
|
Added a third guard in the same family, found while sweeping the failing CI on the open PRs.
The probe there had timed out exactly as intended. The fixture dribbles response headers from its own thread, and the test read The companion Both mutation-checked: a fixture that never trickles fails the first assertion, a chunk carrying CRLF fails the second. For the two guards this PR already had, the sweep confirmed both are live failures on other people's PRs rather than hypothetical:
Local: 156 passed across the three files. |
|
@codex security review |
|
will this now merge the #10928 ? @danielhanchen |
The previous version waited for the fixture's first byte and accepted it. That is too weak, and in the direction that matters. urllib applies its own per-socket-operation timeout, so a peer that sends one byte and then goes quiet for longer than that trips it on its own, the probe returns "timeout" inside budget, and every assertion below passes against a build with no whole-request deadline at all. The old count-based check was reaching for this and could not express it, because a count cannot say when the bytes landed. The fixture now records the longest silence it ever left. While every gap stays under the socket timeout, and the last write lands within one timeout of the probe returning, no per-operation timeout can have fired, so a probe that returned anyway returned on the whole-request deadline. That is the distinction the test exists to make, asserted rather than assumed. A runner too contended to hold that has not produced a failure, it has produced no evidence, so the test skips with the measured numbers instead of passing on a broken build or going red on a busy machine. Mutation-checked both ways: a fixture that stalls after one byte now skips where it previously passed, and replacing worker.join(timeout) with worker.join() fails with the fixture still trickling.
Three backend guards that fail on a busy runner rather than on a defect. All three were found failing on other people's open PRs, not hypothesised.
test_cache_does_not_bypass_expiry(failed on #10950)It minted a key expiring 600ms out, validated it to warm the cache, slept 800ms and expected the second call to be rejected. The first call races the KDF, which on a loaded runner can outlast any margin short enough to keep the sleep cheap.
Now shaped like its neighbour
test_cache_does_not_bypass_revocation: warm the cache on a comfortably valid key, expire it in the row, re-validate. It still proves the thing that matters, that a cache hit re-checksexpires_at, and it no longer depends on the wall clock. It also asserts the cache was actually populated, so the second call is known to take the cache path rather than passing for free.The ReDoS guards (
test_no_backtrack_on_tilde_fence_spamfailed on #10941)These look for catastrophic backtracking, which costs seconds or minutes, not a few extra milliseconds. A wall clock cannot tell a regressed quantifier from the runner descheduling the process mid-match: the tilde case measures about 11ms of work and was seen at 60.9ms for that reason alone.
The quantity the budget is about is the regex's own CPU time, so it is measured with
time.process_time(), which does not advance while the process is off the CPU, best of five for the contentionprocess_timecannot see. A genuine blow-up survives both, since every repeat pays it in full. Same pairing astest_tool_loop_controller.py.test_trickling_response_headers_cannot_outlive_the_probe_budget(failed on #10928)The probe had timed out exactly as intended. The fixture dribbles response headers from its own thread, and the test read
state["lines"] >= 3the instant the probe returned, which assumes 0.5s of probe bought that thread 0.5s of CPU.The first fix waited for the fixture's first byte instead. That was too weak, and in the direction that matters: urllib applies a per-socket-operation timeout, so a peer that sends one byte and then goes quiet trips it on its own, the probe returns "timeout" in budget, and every assertion below passes against a build with no whole-request deadline at all.
So the fixture now records the longest silence it ever left. While every gap stays under the socket timeout, and the last write lands within one timeout of the probe returning, no per-operation timeout can have fired, so a probe that returned anyway returned on the whole-request deadline. That is the distinction the test exists to make, asserted rather than assumed. A counter could not express it, because a count cannot say when the bytes landed.
A runner too contended to hold that has not produced a failure, it has produced no evidence, so the test skips with the measured numbers instead of passing on a broken build or going red on a busy machine.
The companion
lines < 100bound went the same way. It was a proxy for "the fixture is not sending whole header lines" measured through a byte count that a slow runner made small and a fast one made large, so it is now asserted against the repeated chunk itself.Verification
156 passed across the three files.
Mutation-checked both directions on the trickling guard: a fixture that stalls after one byte skips where the first version passed, and replacing
worker.join(timeout)withworker.join()fails with the fixture still trickling.Tests only, no production code.