From 27bdf317ee51916be0fa3fd938cd7e4914572d4a Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Mon, 10 Aug 2026 02:59:46 -0500 Subject: [PATCH] retry-config-contract: assert the worker cap as a ceiling, not exact overlap Reaching a cap requires every worker in flight simultaneously, and the retry workers share an Io thread pool with the firehose reconnect and accept loops. The 16-worker default reproducibly peaks at 13-14 on a 32-core Linux box and 16 on macOS; the config is honored either way (the process logs workers 16 and all 20 candidates are attempted). Small caps saturate regardless and still assert equality. Co-Authored-By: Claude Opus 5 (1M context) --- tests/retry_config_contract.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/retry_config_contract.py b/tests/retry_config_contract.py index 3f53ab4..059c330 100644 --- a/tests/retry_config_contract.py +++ b/tests/retry_config_contract.py @@ -66,7 +66,7 @@ def run(*args): subprocess.run(args, cwd=ROOT, check=True) -def run_case(name, mode, count, workers, host_workers, expected_peak): +def run_case(name, mode, count, workers, host_workers, expected_peak, min_peak=None): State.reset() with tempfile.TemporaryDirectory(prefix=f"stream-retry-{name}-") as raw: data = pathlib.Path(raw) / "data" @@ -103,7 +103,19 @@ def run_case(name, mode, count, workers, host_workers, expected_peak): raise AssertionError(log_path.read_text(errors="replace")) with State.lock: assert State.requests == count, (name, State.requests, text) - assert State.peak == expected_peak, (name, State.peak, text) + # The cap is a ceiling, not a promise of simultaneity: reaching + # it requires every worker to be in flight at once, and the + # retry workers share an Io thread pool with the firehose + # reconnect and accept loops. A small cap is saturated + # regardless, so those cases still assert equality; the + # 16-worker default reproducibly peaks at 13-14 on a 32-core + # Linux box while hitting 16 on macOS. Assert the ceiling holds + # and that the default is still far above the explicit caps -- + # pinning the exact overlap only asserts the scheduler. + assert State.peak <= expected_peak, (name, State.peak, text) + assert State.peak >= (expected_peak if min_peak is None else min_peak), ( + name, State.peak, text, + ) assert State.first_at is not None assert State.first_at - started_at >= 0.9, (name, State.first_at - started_at) finally: @@ -179,7 +191,9 @@ try: time.sleep(0.01) run_case("explicit-global", "unique", 6, 3, 1, 3) run_case("explicit-host", "same", 6, 4, 2, 2) - run_case("default-global", "unique", 20, 0, 1, 16) + # min_peak 8 is twice the largest explicit cap below it (default-host's 4), + # so a regression to any smaller worker default still fails loudly. + run_case("default-global", "unique", 20, 0, 1, 16, min_peak=8) run_case("default-host", "same", 8, 8, 0, 4) run_disabled() finally: -- 2.51.2