From 1cae1bd0de786dd473807e169ffa40277d65c0c0 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Tue, 30 Jun 2026 03:53:23 -0700 Subject: [PATCH] test(cli): deterministically join bg worker thread instead of polling deadline test_background_task_registers_thread_local_approval_callbacks polled a 2s wall-clock deadline waiting for the background daemon thread to pop its entry from _background_tasks. Under loaded CI the thread's finally-block cleanup could lag the deadline, flaking the final 'assert not cli._background_tasks'. Join the actual worker thread (timeout=10) so the wait ends exactly when the thread finishes. --- tests/cli/test_cli_approval_ui.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/cli/test_cli_approval_ui.py b/tests/cli/test_cli_approval_ui.py index 0d58bf8f56a..0366ed628d9 100644 --- a/tests/cli/test_cli_approval_ui.py +++ b/tests/cli/test_cli_approval_ui.py @@ -354,9 +354,11 @@ class TestCliApprovalUi: chat_console.return_value.print = MagicMock() cli._handle_background_command("/btw check weather") - deadline = time.time() + 2 - while cli._background_tasks and time.time() < deadline: - time.sleep(0.01) + # Join the worker thread deterministically rather than polling a + # wall-clock deadline — under load the thread's finally-block pop + # of _background_tasks can lag a fixed timeout, which flaked CI. + for _thread in list(cli._background_tasks.values()): + _thread.join(timeout=10) assert seen["approval"].__self__ is cli assert seen["approval"].__func__ is HermesCLI._approval_callback