From 92e1ba6acee5e04b908e512a6ee7aa0b483932af Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 17:18:45 -0600 Subject: [PATCH 1/3] tests: judge the keyword budget on the least of up to three readings The 64K keyword-budget test took one wall-clock reading of the real budget on a shared runner and went red on hosted windows-2025 on changes nowhere near the guard. It now reads up to three times, stops at the first reading under the line, and judges the least. The line, the 500 ms room, the budget ceiling, the control arm and the scaled arm are unchanged. The per-test timeout moves from 600 to 960 s for five runs of at most 180 s. Measured locally, least of three: shipped budget 2004 and 2025 ms, no budget 3593 (no-quote) and 9446 (quoted), against a 2500 ms line. Verified-by: tests --- tests/test_unbounded_fs_scan_guard.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/test_unbounded_fs_scan_guard.py b/tests/test_unbounded_fs_scan_guard.py index 443c0161d0..405f09f63f 100644 --- a/tests/test_unbounded_fs_scan_guard.py +++ b/tests/test_unbounded_fs_scan_guard.py @@ -958,11 +958,12 @@ def _with_keyword_budget(source: str, budget: int, replacement: str) -> str: return changed -# Three runs of at most 180 s each, under a cap the marker sets above CI's --timeout. -@pytest.mark.timeout(600) +# Five runs of at most 180 s each, under a cap the marker sets above CI's --timeout. +@pytest.mark.timeout(960) @pytest.mark.parametrize("shape", sorted(_KEYWORD_GLUED_SHAPES)) def test_the_keyword_passes_stop_within_their_budget_on_a_64k_command(shape: str) -> None: - """The keyword passes must stop within their budget on a 64K keyword-glued command. + """The keyword passes must stop within their budget on a 64K keyword-glued command, on the least + of up to three readings. The real budget's reading alone proves nothing on a runner fast enough to finish under it, so the control is scaled to the runner. A copy with no budget measures what the passes spend here; @@ -975,9 +976,20 @@ def test_the_keyword_passes_stop_within_their_budget_on_a_64k_command(shape: str assert budget <= 2000, f"the keyword budget is {budget} ms, over the hold's ceiling" command = _keyword_glued_command(shape) assert 65_000 < len(command) <= 65_536 - spent = _keyword_clock_ms(source, command) - assert spent < budget + _KEYWORD_OVERRUN_MS, ( - f"the keyword passes ran {spent} ms, past {budget} ms and {_KEYWORD_OVERRUN_MS} ms of room" + # Judge the least of up to three readings. A stall on a shared runner after the budget expires + # only adds time, and a guard that ignored its budget would overrun every time: with no budget, + # the least of three read 3593 ms here and 9446 on the quoted shape (local, 2026-12-02). An + # overrun on only some runs can pass. Hosted windows-2025 runs read 2519 to 2636 ms on no-quote + # that day, on changes nowhere near the guard; that a stall caused them is inferred. + line = budget + _KEYWORD_OVERRUN_MS + readings: list[int] = [] + for _ in range(3): + readings.append(_keyword_clock_ms(source, command)) + if readings[-1] < line: + break + assert min(readings) < line, ( + f"the keyword passes ran {readings} ms, each past {budget} ms and " + f"{_KEYWORD_OVERRUN_MS} ms of room" ) control = _keyword_clock_ms(_with_keyword_budget(source, budget, "[long]::MaxValue"), command) assert control >= _KEYWORD_CONTROL_FLOOR_MS, ( From fef6a04c282c936b99b30afeac23960ebe04bf01 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 17:59:20 -0600 Subject: [PATCH 2/3] tests: the keyword budget's room follows the no-budget control This replaces the previous commit's statement that the line and the 500 ms room are unchanged. The control is now measured first, and the room is a tenth of it, at least 500 ms and at most 1000 ms, so the line is at most 3000 ms at the 2000 ms budget. The budget ceiling check and the scaled arm are unchanged. The control, the readings and the line go to the junit report through record_property. This allows up to 500 ms more overrun on a run whose control is over 5000 ms. The copy with no budget still fails the line locally: no-quote control 5455, line 2545, least 4976; quoted control 13643, line 3000, least 19677. Verified-by: tests Verified-by: code-review xhigh --- tests/test_unbounded_fs_scan_guard.py | 63 +++++++++++++++++++-------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/tests/test_unbounded_fs_scan_guard.py b/tests/test_unbounded_fs_scan_guard.py index 405f09f63f..6cc682d4b9 100644 --- a/tests/test_unbounded_fs_scan_guard.py +++ b/tests/test_unbounded_fs_scan_guard.py @@ -36,7 +36,7 @@ import tempfile import threading import time -from collections.abc import Iterator +from collections.abc import Callable, Iterator from contextlib import contextmanager from pathlib import Path from typing import Any, cast @@ -903,6 +903,31 @@ def test_what_keyword_arithmetic_reads_as_data_is_allowed(command: str) -> None: #: control arm scales its own budget to what the runner measures rather than using the real one. _KEYWORD_OVERRUN_MS = 500 +#: The most room a slow runner gets. Hosted runs read 2519 to 2661 ms on 2026-12-02, on both shapes, +#: on changes nowhere near the guard. The unit being read at expiry takes longer on a slower runner, +#: which likely explains them, so the room follows the no-budget control. The cap keeps an absolute +#: bound however slow the runner is. +_KEYWORD_OVERRUN_CAP_MS = 1000 + + +def _keyword_room_ms(control: int) -> int: + """Room past the budget on a runner whose no-budget run spent ``control`` ms: a tenth of it, no + less than the floor and no more than the cap.""" + return min(_KEYWORD_OVERRUN_CAP_MS, max(_KEYWORD_OVERRUN_MS, control // 10)) + + +def test_the_keyword_room_never_lets_a_budget_that_does_nothing_pass() -> None: + """The room leaves its floor only once the control is past 5000 ms. From there the line, at the + 2000 ms budget ceiling, is at most six tenths of the control, which is what a budget that does + nothing would read.""" + for control in range(200, 5001, 100): + assert _keyword_room_ms(control) == 500 + for control in range(5010, 60_000, 10): + assert 500 < _keyword_room_ms(control) <= 1000 + assert 2000 + _keyword_room_ms(control) <= control * 6 // 10 + assert _keyword_room_ms(60_000) == 1000 + + #: The fewest milliseconds the no-budget copy must spend before a budget a fifth of it can be told #: apart from noise. Under it the command is too small for this runner, and the test fails rather #: than passing on a reading that proves nothing. @@ -961,9 +986,11 @@ def _with_keyword_budget(source: str, budget: int, replacement: str) -> str: # Five runs of at most 180 s each, under a cap the marker sets above CI's --timeout. @pytest.mark.timeout(960) @pytest.mark.parametrize("shape", sorted(_KEYWORD_GLUED_SHAPES)) -def test_the_keyword_passes_stop_within_their_budget_on_a_64k_command(shape: str) -> None: - """The keyword passes must stop within their budget on a 64K keyword-glued command, on the least - of up to three readings. +def test_the_keyword_passes_stop_within_their_budget_on_a_64k_command( + shape: str, record_property: Callable[[str, object], None] +) -> None: + """The keyword passes must stop within their budget, and the room ``_keyword_room_ms`` gives, on + a 64K keyword-glued command. The least of up to three readings is judged. The real budget's reading alone proves nothing on a runner fast enough to finish under it, so the control is scaled to the runner. A copy with no budget measures what the passes spend here; @@ -976,25 +1003,27 @@ def test_the_keyword_passes_stop_within_their_budget_on_a_64k_command(shape: str assert budget <= 2000, f"the keyword budget is {budget} ms, over the hold's ceiling" command = _keyword_glued_command(shape) assert 65_000 < len(command) <= 65_536 - # Judge the least of up to three readings. A stall on a shared runner after the budget expires - # only adds time, and a guard that ignored its budget would overrun every time: with no budget, - # the least of three read 3593 ms here and 9446 on the quoted shape (local, 2026-12-02). An - # overrun on only some runs can pass. Hosted windows-2025 runs read 2519 to 2636 ms on no-quote - # that day, on changes nowhere near the guard; that a stall caused them is inferred. - line = budget + _KEYWORD_OVERRUN_MS + control = _keyword_clock_ms(_with_keyword_budget(source, budget, "[long]::MaxValue"), command) + record_property("keyword_control_ms", control) + assert control >= _KEYWORD_CONTROL_FLOOR_MS, ( + f"with no budget the keyword passes ran only {control} ms, under the " + f"{_KEYWORD_CONTROL_FLOOR_MS} ms floor, so the command does not test the budget here" + ) + # Judge the least of up to three readings, since a stall after the budget expires only adds + # time. A guard that ignored its budget reads near the control every time, so wherever the + # control is over the line it still fails. An overrun on only some runs can pass. + room = _keyword_room_ms(control) + line = budget + room readings: list[int] = [] for _ in range(3): readings.append(_keyword_clock_ms(source, command)) if readings[-1] < line: break + record_property("keyword_budget_readings_ms", readings) + record_property("keyword_line_ms", line) assert min(readings) < line, ( - f"the keyword passes ran {readings} ms, each past {budget} ms and " - f"{_KEYWORD_OVERRUN_MS} ms of room" - ) - control = _keyword_clock_ms(_with_keyword_budget(source, budget, "[long]::MaxValue"), command) - assert control >= _KEYWORD_CONTROL_FLOOR_MS, ( - f"with no budget the keyword passes ran only {control} ms, under the " - f"{_KEYWORD_CONTROL_FLOOR_MS} ms floor, so the command does not test the budget here" + f"the keyword passes ran {readings} ms, each past {budget} ms and {room} ms of room, " + f"against {control} ms with no budget" ) scaled = control // 5 scaled_spent = _keyword_clock_ms(_with_keyword_budget(source, budget, str(scaled)), command) From bdb7a2464c52533ed5c4a0789a6169477eed78b8 Mon Sep 17 00:00:00 2001 From: Scott Hall Date: Wed, 2 Dec 2026 18:12:35 -0600 Subject: [PATCH 3/3] tests: the keyword room's test name and comments credit the scaled arm Text only. The room test's name claims only controls over 2500 ms, and the comments say 500 ms is the least room and that the scaled arm fails a budget that does nothing where the line does not. Verified-by: tests --- tests/test_unbounded_fs_scan_guard.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/test_unbounded_fs_scan_guard.py b/tests/test_unbounded_fs_scan_guard.py index 6cc682d4b9..c330025a7e 100644 --- a/tests/test_unbounded_fs_scan_guard.py +++ b/tests/test_unbounded_fs_scan_guard.py @@ -896,7 +896,7 @@ def test_what_keyword_arithmetic_reads_as_data_is_allowed(command: str) -> None: #: The guard's last allow. The instrumented copy prints the keyword clock just before it. _GUARD_ALLOW_EXIT = "\n exit 0\n} catch {" -#: Room past the budget for the one text, or the one view's bounds, a pass is reading when it +#: The LEAST room past the budget for the one text, or the one view's bounds, a pass is reading when it #: expires. Measured locally on 2026-12-02 at a 2000 ms budget, the clock read 2029 to 2060 ms on the #: quoted shape below and 2023 on the other; with no budget, 13361 to 13689 and 4291. A hosted #: ubuntu runner read about 440 ms with no budget on the second, under the real budget, so the @@ -916,10 +916,11 @@ def _keyword_room_ms(control: int) -> int: return min(_KEYWORD_OVERRUN_CAP_MS, max(_KEYWORD_OVERRUN_MS, control // 10)) -def test_the_keyword_room_never_lets_a_budget_that_does_nothing_pass() -> None: +def test_the_keyword_line_is_under_any_control_over_2500_ms() -> None: """The room leaves its floor only once the control is past 5000 ms. From there the line, at the 2000 ms budget ceiling, is at most six tenths of the control, which is what a budget that does - nothing would read.""" + nothing would read. With a control at or below 2500 ms the line does not catch such a budget, + and the scaled arm is what fails it.""" for control in range(200, 5001, 100): assert _keyword_room_ms(control) == 500 for control in range(5010, 60_000, 10): @@ -1010,8 +1011,9 @@ def test_the_keyword_passes_stop_within_their_budget_on_a_64k_command( f"{_KEYWORD_CONTROL_FLOOR_MS} ms floor, so the command does not test the budget here" ) # Judge the least of up to three readings, since a stall after the budget expires only adds - # time. A guard that ignored its budget reads near the control every time, so wherever the - # control is over the line it still fails. An overrun on only some runs can pass. + # time. A guard that ignored its budget reads near the control every time, so it fails here where + # the control is well over the line, and the scaled arm below is what fails it elsewhere. An + # overrun on only some runs can pass. room = _keyword_room_ms(control) line = budget + room readings: list[int] = []