From b9858acb0ce504dcfd0ade16792ee68033507d84 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 16 Jul 2026 04:24:29 -0700 Subject: [PATCH] =?UTF-8?q?test(tui):=20fix=20flaky=20notification-requeue?= =?UTF-8?q?=20test=20=E2=80=94=20assert=20contract,=20not=20queue=20order?= =?UTF-8?q?=20(#65506)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_run_prompt_submit_requeues_all_unstarted_notifications_with_real_threading asserted strict FIFO order of the requeued events. The completion_queue is process-global, and notification pollers leaked by earlier session.init tests in the same file legitimately steal-and-requeue foreign-session events (_notification_poller_loop's belongs-elsewhere branch), rotating the queue — CI slice 6/8 saw [batch_3, batch_2] and failed on ordering alone. Assert the actual requeue contract instead: batch_1 is consumed while batch_2 and batch_3 both remain queued — membership via a deadline drain (an event can be transiently held by a poller mid-cycle), not order. Verified: single test 10/10 green, full file 337/337 across 3 consecutive CI-parity runs. --- tests/test_tui_gateway_server.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.py index afb38a1b9365..6122314eebd9 100644 --- a/tests/test_tui_gateway_server.py +++ b/tests/test_tui_gateway_server.py @@ -2765,13 +2765,26 @@ def test_run_prompt_submit_requeues_all_unstarted_notifications_with_real_thread assert nested_started.wait(timeout=5) threads[0].join(timeout=5) assert not threads[0].is_alive() - queued = [] - while not isolated_queue.empty(): - queued.append(isolated_queue.get_nowait()) - assert [event["session_id"] for event in queued] == [ + # Membership, not order: the completion_queue is process-global, and + # notification pollers leaked by earlier session.init tests in this + # file legitimately steal-and-requeue foreign-session events (see + # _notification_poller_loop's belongs-elsewhere branch), rotating the + # queue. The requeue contract is that batch_2 and batch_3 both remain + # queued (never consumed) while batch_1's turn is in flight — so drain + # with a deadline (an event may be transiently held by a poller + # mid-cycle) and assert exactly {batch_2, batch_3} come back. + queued: dict = {} + deadline = time.time() + 5.0 + while time.time() < deadline and set(queued) != { "proc_batch_2", "proc_batch_3", - ] + }: + try: + evt = isolated_queue.get(timeout=0.1) + except _queue_mod.Empty: + continue + queued[evt["session_id"]] = evt + assert set(queued) == {"proc_batch_2", "proc_batch_3"} finally: release_nested.set() for thread in threads: