Repository navigation
Stop two CI guards failing for the machine they ran on - #11164
Conversation
Both went red on branches that touch neither of them. tests/studio/test_update_release_notes.py's linearity guard reported 7.2x against a bar of 6.0 on #11152. Pairing divides most contention out but not all of it: the big leg runs four times longer than the small one, so a scheduler stall is four times more likely to land in the big half, which biases a pair upward and never downward, and three pairs is few enough that two unlucky ones move the median. Re-measure on a larger sample instead of loosening the bar. That is not a second chance, because a genuinely quadratic path measures about sixteen in every pair and comes back over the bar as surely the second time, while a stall does not survive being asked again. The cost is paid only on the reading that would otherwise have failed. assert_linear decides four test files and had no rows of its own, so it gets them: linear passes, quadratic fails, a stalled linear path passes and is shown to have really taken the retry, a stalled quadratic path still fails, and the backstop reads the best big time rather than the worst. Cost is simulated rather than spent, so the shapes are exact and the file runs in seconds. studio/backend/tests/test_data_recipe_dataset_download.py snapshotted the shared system temp dir to check a failed export unlinked what it created, which made it a claim about the whole box. Its siblings each leave a NamedTemporaryFile with the same .jsonl suffix in flight until their own finally runs, and CI shards this suite with -n 4 --dist loadgroup, so one of them on another worker could fail this test for something it does not measure. Point tempfile.tempdir at a directory only this test can reach; the assertion becomes nothing at all rather than the same set as a moment ago. Confirmed it still fails when the cleanup arm is removed.
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 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. |
The rows were driven by real sleeps, so on a loaded runner they could overshoot independently and stop meaning what they say: stretch either nominal 4 ms small leg in the stalled-but-linear row past about 6.7 ms and its injected ratio falls under the bar, and if both stretch the retry is never reached and the call-count assertion fails. That is the same unrelated red this change exists to remove, reintroduced in the test of the fix. growth and assert_linear now take an optional clock, defaulting to time.perf_counter, and the rows drive a fake one that advances by exactly the cost the shape declares. A quadratic path here is quadratic to the last digit, the file runs in 0.04s, and fifteen consecutive runs give the same seven passes. Nothing in the repo passes clock outside these tests. Costs are scaled so the quadratic rows fail on the ratio rather than on the 60s backstop, which now has a row of its own for each arm: one stalled leg must not trip it, and a path genuinely too slow to measure must.
The retry could be accepted from a sample that never finished. If its first pair blew the 60s backstop the loop stopped there, and if that same pair's small leg was also slow the one surviving ratio could sit under the tolerance, so a superlinear path passed on one aborted pair. Taking min(big, big_again) then hid the abort, because the first sample's best big time was well under budget. Both halves are now required of the confirmation itself: its own big time under the budget, and all of its pairs completed. Verified against the old code, which accepts exactly this shape and now does not, with a row that sizes the stalls so the surviving ratio really is under the bar and the failure is the abort rather than the ratio. growth reports how many pairs it completed, since a caller that reads its median as a verdict cannot tell an aborted sample from a finished one.
The 60s backstop bounds a single leg. It does not bound the sample: a regression that holds each big leg just under it still costs about 7 * 60s in the confirmation, and the four pytest invocations in studio-backend-ci.yml pass --timeout=330. The worker is killed part way through, and the run reports a bare timeout instead of the linearity failure this guard was written to name, which is the same complaint the docstring already makes about the absolute budget it replaced. The retry now takes as many pairs as it can afford of a 120s budget, estimating the pair from the big leg already measured and the ratio already formed. Fewer pairs is a weaker vote, not a broken one, since contention is the same size in every pair. Below three there is nothing worth buying, so the reading already taken becomes the verdict and says so in its message rather than spending five minutes to reach the same answer. Two rows for the two arms: a 40s big leg over the bar fails as a linearity failure and provably does not start a confirmation (six legs, no more), and a 20s one still takes five pairs and passes on them.
Sizing the retry from the first sample was an estimate dressed as a bound. It reads the BEST big leg and the MEDIAN ratio, and those come from different pairs: a sample of 59s, 59s and 1s big legs against 1s small legs offers a one-second pair cost alongside a ratio of 59, so it authorises all seven pairs, and if the confirmation's own legs then arrive at 40s the run overruns --timeout=330 exactly as before. growth() takes a budget_s that bounds the whole call, checked on the pair boundary so a stopped sample still holds a whole number of ratios. abort_over_s bounds one big leg and budget_s bounds the sample; neither implies the other, which is the gap this closes. A confirmation cut short already fails through the pairs_completed assertion, so the verdict arrives as a sentence naming the unfinished sample rather than as the runner's timeout, which is the whole point. The pre-sizing stays, demoted to what it is: it refuses a retry that obviously cannot fit and keeps a green run cheap. One row for the exact mixed-estimate shape, pinning that the loop gives up after three of the seven pairs it was authorised.
A bound tested once a pair is already home is not a bound on that pair. Three 59-second pairs under a 120-second budget all run, because each one is inside the budget at the moment its predecessor finishes, and the sample costs 177s. With a first sample of 39s, 59s and 59s big legs -- which sizes the retry at three pairs, since the estimate reads the best leg and the median ratio from different pairs -- the whole test reaches about 334s and --timeout=330 kills it before the assertion, which is what the budget was added to prevent. The loop now reserves room for another pair at the cost of the worst pair it has seen in this sample, and stops when that no longer fits. Worst rather than mean because contention only adds. On the shape above it stops at two pairs, the confirmation spends 118s of its 120, and the test lands around 275s. One row for that shape, asserting the pair count, the message, and that the whole test stays under the runner's timeout. The existing mixed-estimate row now stops at two pairs rather than three, for the same reason.
The retry got a fresh 120s no matter what the first sample had already spent. The first sample has no bound of its own past the 60s per big leg, so a scheduler stall in one of its small legs can burn most of the runner's patience before the re-measurement is even considered, and a confirmation counted fresh from there overruns whatever was left. confirm_budget_s becomes total_budget_s and covers the whole call, first sample included. The retry is sized and bounded by what remains, and the message says how much that was. 240s against --timeout=330, leaving margin for collection and the rest of the test body. Two rows retuned rather than rewritten, since deducting the first sample changes what each affords. The partial-affordability row now uses 30s big legs, which put 90s into the first sample and leave four pairs of the remaining 150. The before-the-pair row uses 13s / 20s / 20s big legs, which cost 56s and authorise all seven, and its confirmation's 59s legs stop at three for 177s of the 184 left; asked after the pair instead, the fourth would have run to 236 and blown a bound it was never tested against while inside it.
total_budget_s documented a whole-call guarantee and was only ever handed to the confirmation. Contention landing in the SMALL legs is what that misses: 50s small against 55s big reads as a ratio of 1.1, comfortably under the tolerance, so nothing reaches the retry branch where the budget was enforced, and three of those pairs run to 315s past --timeout=330 while returning a cheerful pass. The first growth call now takes the budget too, and a sample that stopped short is not accepted as a verdict: two pairs is not the reading the caller asked for, so it fails saying so rather than reporting a median of whatever it managed. The per-leg backstop is still checked first, so a path with one enormous leg keeps its own clearer message. One row for that shape, asserting the pair count, the message, and that the call stays under the runner's timeout.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! 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". |
* Stop two CI guards failing for the machine they ran on Both went red on branches that touch neither of them. tests/studio/test_update_release_notes.py's linearity guard reported 7.2x against a bar of 6.0 on unslothai#11152. Pairing divides most contention out but not all of it: the big leg runs four times longer than the small one, so a scheduler stall is four times more likely to land in the big half, which biases a pair upward and never downward, and three pairs is few enough that two unlucky ones move the median. Re-measure on a larger sample instead of loosening the bar. That is not a second chance, because a genuinely quadratic path measures about sixteen in every pair and comes back over the bar as surely the second time, while a stall does not survive being asked again. The cost is paid only on the reading that would otherwise have failed. assert_linear decides four test files and had no rows of its own, so it gets them: linear passes, quadratic fails, a stalled linear path passes and is shown to have really taken the retry, a stalled quadratic path still fails, and the backstop reads the best big time rather than the worst. Cost is simulated rather than spent, so the shapes are exact and the file runs in seconds. studio/backend/tests/test_data_recipe_dataset_download.py snapshotted the shared system temp dir to check a failed export unlinked what it created, which made it a claim about the whole box. Its siblings each leave a NamedTemporaryFile with the same .jsonl suffix in flight until their own finally runs, and CI shards this suite with -n 4 --dist loadgroup, so one of them on another worker could fail this test for something it does not measure. Point tempfile.tempdir at a directory only this test can reach; the assertion becomes nothing at all rather than the same set as a moment ago. Confirmed it still fails when the cleanup arm is removed. * Declare the cost in the guard's own tests instead of sleeping for it The rows were driven by real sleeps, so on a loaded runner they could overshoot independently and stop meaning what they say: stretch either nominal 4 ms small leg in the stalled-but-linear row past about 6.7 ms and its injected ratio falls under the bar, and if both stretch the retry is never reached and the call-count assertion fails. That is the same unrelated red this change exists to remove, reintroduced in the test of the fix. growth and assert_linear now take an optional clock, defaulting to time.perf_counter, and the rows drive a fake one that advances by exactly the cost the shape declares. A quadratic path here is quadratic to the last digit, the file runs in 0.04s, and fifteen consecutive runs give the same seven passes. Nothing in the repo passes clock outside these tests. Costs are scaled so the quadratic rows fail on the ratio rather than on the 60s backstop, which now has a row of its own for each arm: one stalled leg must not trip it, and a path genuinely too slow to measure must. * Make the confirmation stand on its own reading The retry could be accepted from a sample that never finished. If its first pair blew the 60s backstop the loop stopped there, and if that same pair's small leg was also slow the one surviving ratio could sit under the tolerance, so a superlinear path passed on one aborted pair. Taking min(big, big_again) then hid the abort, because the first sample's best big time was well under budget. Both halves are now required of the confirmation itself: its own big time under the budget, and all of its pairs completed. Verified against the old code, which accepts exactly this shape and now does not, with a row that sizes the stalls so the surviving ratio really is under the bar and the failure is the abort rather than the ratio. growth reports how many pairs it completed, since a caller that reads its median as a verdict cannot tell an aborted sample from a finished one. * Bound what the confirmation may spend, not just one leg of it The 60s backstop bounds a single leg. It does not bound the sample: a regression that holds each big leg just under it still costs about 7 * 60s in the confirmation, and the four pytest invocations in studio-backend-ci.yml pass --timeout=330. The worker is killed part way through, and the run reports a bare timeout instead of the linearity failure this guard was written to name, which is the same complaint the docstring already makes about the absolute budget it replaced. The retry now takes as many pairs as it can afford of a 120s budget, estimating the pair from the big leg already measured and the ratio already formed. Fewer pairs is a weaker vote, not a broken one, since contention is the same size in every pair. Below three there is nothing worth buying, so the reading already taken becomes the verdict and says so in its message rather than spending five minutes to reach the same answer. Two rows for the two arms: a 40s big leg over the bar fails as a linearity failure and provably does not start a confirmation (six legs, no more), and a 20s one still takes five pairs and passes on them. * Stop the confirmation on a measured deadline, not on a prediction Sizing the retry from the first sample was an estimate dressed as a bound. It reads the BEST big leg and the MEDIAN ratio, and those come from different pairs: a sample of 59s, 59s and 1s big legs against 1s small legs offers a one-second pair cost alongside a ratio of 59, so it authorises all seven pairs, and if the confirmation's own legs then arrive at 40s the run overruns --timeout=330 exactly as before. growth() takes a budget_s that bounds the whole call, checked on the pair boundary so a stopped sample still holds a whole number of ratios. abort_over_s bounds one big leg and budget_s bounds the sample; neither implies the other, which is the gap this closes. A confirmation cut short already fails through the pairs_completed assertion, so the verdict arrives as a sentence naming the unfinished sample rather than as the runner's timeout, which is the whole point. The pre-sizing stays, demoted to what it is: it refuses a retry that obviously cannot fit and keeps a green run cheap. One row for the exact mixed-estimate shape, pinning that the loop gives up after three of the seven pairs it was authorised. * Ask the budget before a pair runs, not after it has A bound tested once a pair is already home is not a bound on that pair. Three 59-second pairs under a 120-second budget all run, because each one is inside the budget at the moment its predecessor finishes, and the sample costs 177s. With a first sample of 39s, 59s and 59s big legs -- which sizes the retry at three pairs, since the estimate reads the best leg and the median ratio from different pairs -- the whole test reaches about 334s and --timeout=330 kills it before the assertion, which is what the budget was added to prevent. The loop now reserves room for another pair at the cost of the worst pair it has seen in this sample, and stops when that no longer fits. Worst rather than mean because contention only adds. On the shape above it stops at two pairs, the confirmation spends 118s of its 120, and the test lands around 275s. One row for that shape, asserting the pair count, the message, and that the whole test stays under the runner's timeout. The existing mixed-estimate row now stops at two pairs rather than three, for the same reason. * Count the first sample against the budget it is part of The retry got a fresh 120s no matter what the first sample had already spent. The first sample has no bound of its own past the 60s per big leg, so a scheduler stall in one of its small legs can burn most of the runner's patience before the re-measurement is even considered, and a confirmation counted fresh from there overruns whatever was left. confirm_budget_s becomes total_budget_s and covers the whole call, first sample included. The retry is sized and bounded by what remains, and the message says how much that was. 240s against --timeout=330, leaving margin for collection and the rest of the test body. Two rows retuned rather than rewritten, since deducting the first sample changes what each affords. The partial-affordability row now uses 30s big legs, which put 90s into the first sample and leave four pairs of the remaining 150. The before-the-pair row uses 13s / 20s / 20s big legs, which cost 56s and authorise all seven, and its confirmation's 59s legs stop at three for 177s of the 184 left; asked after the pair instead, the fourth would have run to 236 and blown a bound it was never tested against while inside it. * Put the first sample inside the budget it belongs to total_budget_s documented a whole-call guarantee and was only ever handed to the confirmation. Contention landing in the SMALL legs is what that misses: 50s small against 55s big reads as a ratio of 1.1, comfortably under the tolerance, so nothing reaches the retry branch where the budget was enforced, and three of those pairs run to 315s past --timeout=330 while returning a cheerful pass. The first growth call now takes the budget too, and a sample that stopped short is not accepted as a verdict: two pairs is not the reading the caller asked for, so it fails saying so rather than reporting a median of whatever it managed. The per-leg backstop is still checked first, so a path with one enormous leg keeps its own clearer message. One row for that shape, asserting the pair count, the message, and that the call stays under the runner's timeout.
Two CI guards have been going red on branches that touch neither of them. Both are timing or environment reads rather than claims about the code under test, and both are fixed here without loosening what they assert.
The linearity guard re-measures instead of loosening
tests/studio/test_update_release_notes.py::test_stripping_comments_stays_linear_in_the_code_spansreported4x the input cost 7.2x the timeagainst a bar of 6.0 on #11152, a branch that changes none of this code.tests/_shared/growth.pyalready forms paired ratios and takes a median, which divides most contention out. Not all of it: the big leg runs four times longer than the small one, so a scheduler stall is four times more likely to land in the big half, which biases a pair upward and never downward. Three pairs is few enough that two unlucky ones move the median.assert_linearnow re-measures on a larger sample when the first reading is over the bar, and fails only if that second reading is over it too. This is not a second chance. A genuinely quadratic path measures aboutfactor ** 2in every pair, so its second median comes back over the bar as surely as its first, while a contention spike does not survive being asked again on a bigger sample. The extra pairs are paid only on the reading that would otherwise have failed, so a green run still costs three pairs.assert_lineardecides the verdict of four test files and had no rows of its own, so it gets them intests/test_growth_ratio_guard.py:growthreports the best big time, not the worst, so the 60s backstop does not fire on a runner that stalled onceCost is simulated rather than spent:
runsleeps for a duration computed from the input size, so a quadratic shape here is quadratic exactly and the whole file runs in a few seconds.A temp-file check that was reading the whole box
studio/backend/tests/test_data_recipe_dataset_download.py::test_build_dataset_download_leaves_no_temp_file_when_export_failssnapshottedtempfile.gettempdir()before and after, to check that a failed export unlinked what it created.Its siblings in the same file each leave a
NamedTemporaryFile(delete = False, suffix = ".jsonl")in flight until their ownfinallyruns, and the backend job shards this suite with-n 4 --dist loadgroupwith noxdist_groupon the file. A sibling on another worker can therefore put a.jsonlin that directory between the two reads and fail this test for something it does not measure. It failed that way on #11159.Pointing
tempfile.tempdirat a directory only this test can reach makes the reading exact, and lets the assertion be "nothing at all" rather than "the same set as a moment ago".Verification
tests/test_growth_ratio_guard.pyandtests/studio/test_update_release_notes.py: 195 passedstudio/backend/tests/test_data_recipe_dataset_download.pyandstudio/backend/tests/test_tool_xml_strip.py: 122 passedjsonl_path.unlink(missing_ok = True)arm incore/data_recipe/export.pyremoved, it fails.