From c6813e047446d8aa57b160fe754d559fb0b8fb47 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Tue, 17 Nov 2026 16:55:42 +0000 Subject: [PATCH 1/3] test(repo): the Ctrl-C test waits for the interrupt to reach the main thread, not for time (#871) The driver sent SIGINT from rep 1 and let both running cells go on at once. `_map_cells` cancels the queued cells only when the main thread handles the KeyboardInterrupt, so on a busy runner the worker that finished rep 2 took rep 3 (and 4, 5) from the queue, which have no barrier, and they finished: the test listed r1..r5 instead of r1, r2. The two running cells now wait, after the SIGINT, until `ThreadPoolExecutor.shutdown(cancel_futures=True)` has returned in the main thread, which is the call that cancels the queue. No worker is free before then, so the result no longer depends on how fast the main thread handles the signal. The assertions are unchanged. Signed-off-by: Anton Volkov --- dokimi/tests/test_repo_batch_lifecycle.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dokimi/tests/test_repo_batch_lifecycle.py b/dokimi/tests/test_repo_batch_lifecycle.py index 36ed317aa..f880f5d63 100644 --- a/dokimi/tests/test_repo_batch_lifecycle.py +++ b/dokimi/tests/test_repo_batch_lifecycle.py @@ -259,6 +259,7 @@ def test_compare_with_a_model_refuses_only_a_mixed_row_of_that_model(setup): _CTRL_C_DRIVER = """ import os, signal, sys, threading +from concurrent.futures import ThreadPoolExecutor from pathlib import Path sys.path.insert(0, sys.argv[1]) from repo_eval_fixture import FakeRunner, fake_harness, make_repo @@ -272,11 +273,18 @@ def test_compare_with_a_model_refuses_only_a_mixed_row_of_that_model(setup): container.DockerRunner = lambda *a, **k: fake os.environ["FAKE_ACTION"] = "fix" both, real = threading.Barrier(2), repo_runner.run_cell +cancelled, real_shutdown = threading.Event(), ThreadPoolExecutor.shutdown +def shutdown(self, wait=True, *, cancel_futures=False): + real_shutdown(self, wait=wait, cancel_futures=cancel_futures) + if cancel_futures: + cancelled.set() +ThreadPoolExecutor.shutdown = shutdown def run_cell(ctx, task, arm, rep, *args, **kwargs): if rep <= 2: both.wait(30) if rep == 1: signal.pthread_kill(threading.main_thread().ident, signal.SIGINT) + cancelled.wait(30) # no worker is free to take a queued cell until the main thread has cancelled them return real(ctx, task, arm, rep, *args, **kwargs) repo_runner.run_cell = run_cell signal.signal(signal.SIGINT, signal.default_int_handler) From 052829acb210d8a7ef5b0970be70dec66f63fe01 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Tue, 17 Nov 2026 17:57:44 +0000 Subject: [PATCH 2/3] test(repo): the Ctrl-C test sends SIGINT once every cell is submitted (#871) Settles the failed `Test Linux Wheels Python 3.11` check: its traceback shows the KeyboardInterrupt raised inside `ThreadPoolExecutor.submit`, while the main thread waited for a worker thread to start, and the child exited 1 instead of by SIGINT. The driver now wraps `ThreadPoolExecutor.map`, which returns only after every cell is submitted and its threads started, and the first cell sends SIGINT after that. The interrupt then always reaches the main thread in the wait for results, the case the test is about. If the submission never finishes, the child exits 3 and the test fails. Signed-off-by: Anton Volkov --- dokimi/tests/test_repo_batch_lifecycle.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dokimi/tests/test_repo_batch_lifecycle.py b/dokimi/tests/test_repo_batch_lifecycle.py index f880f5d63..6e0cb9490 100644 --- a/dokimi/tests/test_repo_batch_lifecycle.py +++ b/dokimi/tests/test_repo_batch_lifecycle.py @@ -279,10 +279,18 @@ def shutdown(self, wait=True, *, cancel_futures=False): if cancel_futures: cancelled.set() ThreadPoolExecutor.shutdown = shutdown +submitted, real_map = threading.Event(), ThreadPoolExecutor.map +def pool_map(self, *args, **kwargs): + results = real_map(self, *args, **kwargs) # returns once every cell is submitted and its thread has started + submitted.set() + return results +ThreadPoolExecutor.map = pool_map def run_cell(ctx, task, arm, rep, *args, **kwargs): if rep <= 2: both.wait(30) if rep == 1: + if not submitted.wait(30): # an interrupt inside submit() is a slow thread start, not the Ctrl-C under test + os._exit(3) signal.pthread_kill(threading.main_thread().ident, signal.SIGINT) cancelled.wait(30) # no worker is free to take a queued cell until the main thread has cancelled them return real(ctx, task, arm, rep, *args, **kwargs) From 924e417152a48d1e0ccd8488d6ef2da36c398a86 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Tue, 17 Nov 2026 21:24:02 +0000 Subject: [PATCH 3/3] test(repo): the Ctrl-C test fails when the queue is never cancelled The running cells waited for the cancel event and ignored a timeout, so without `cancelled.set()` they sat out 30 s and the test still passed. A timed-out wait now exits the child with 4, so the test fails when the release does not come from the queue being cancelled. Signed-off-by: Anton Volkov --- dokimi/tests/test_repo_batch_lifecycle.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dokimi/tests/test_repo_batch_lifecycle.py b/dokimi/tests/test_repo_batch_lifecycle.py index 6e0cb9490..492b3718a 100644 --- a/dokimi/tests/test_repo_batch_lifecycle.py +++ b/dokimi/tests/test_repo_batch_lifecycle.py @@ -292,7 +292,8 @@ def run_cell(ctx, task, arm, rep, *args, **kwargs): if not submitted.wait(30): # an interrupt inside submit() is a slow thread start, not the Ctrl-C under test os._exit(3) signal.pthread_kill(threading.main_thread().ident, signal.SIGINT) - cancelled.wait(30) # no worker is free to take a queued cell until the main thread has cancelled them + if not cancelled.wait(30): # no worker is free to take a queued cell until the main thread has cancelled them + os._exit(4) return real(ctx, task, arm, rep, *args, **kwargs) repo_runner.run_cell = run_cell signal.signal(signal.SIGINT, signal.default_int_handler)