From 2072aad6c81e8329a2b834980655baa020fd5420 Mon Sep 17 00:00:00 2001 From: Million <15158090088@163.com> Date: Mon, 6 Jul 2026 16:59:08 +0800 Subject: [PATCH 1/3] fix: resolve flaky test_nested_subagents_create_recursive_toolparts Add 200ms sleep before publishing depth=2 spawn event to ensure the parent consumer is fully started. Without this, the event can be missed on slow CI runners, causing the test to hang until timeout. --- tests/orchestrator/test_subagent_events.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/orchestrator/test_subagent_events.py b/tests/orchestrator/test_subagent_events.py index 266d7ee93..0e28eb625 100644 --- a/tests/orchestrator/test_subagent_events.py +++ b/tests/orchestrator/test_subagent_events.py @@ -564,6 +564,9 @@ async def test_nested_subagents_create_recursive_toolparts() -> None: # But actually, the parent consumer subscribes with descendants scope to parent_id, # and the spawn event for child would be published on parent_id by the agent runtime. # Let's publish on parent_id. + # Extra sleep to ensure parent consumer is fully started before publishing + # depth=2 event — without this, the event can be missed on slow CI runners. + await asyncio.sleep(0.2) await _publish_spawn_event( session_pool, parent_id, child_id, source_name="worker2", depth=2 ) From 326f45925abf6519de15c9269ef7e08fa79afa39 Mon Sep 17 00:00:00 2001 From: Million <15158090088@163.com> Date: Mon, 6 Jul 2026 17:04:33 +0800 Subject: [PATCH 2/3] fix: increase sleep in test_child_done_events_timeout_continues Increase wait from 150ms to 300ms to avoid timing flakiness on slow CI runners where 50ms timeout + two turn executions exceed 150ms. --- tests/orchestrator/test_child_done_events.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/orchestrator/test_child_done_events.py b/tests/orchestrator/test_child_done_events.py index 560def575..87933391c 100644 --- a/tests/orchestrator/test_child_done_events.py +++ b/tests/orchestrator/test_child_done_events.py @@ -224,7 +224,8 @@ async def _consume() -> None: consumer_task = asyncio.create_task(_consume()) # Wait for: first turn (instant) + 50ms timeout + second turn (instant). - await asyncio.sleep(0.15) + # Use generous sleep to avoid flakiness on slow CI runners. + await asyncio.sleep(0.3) # Close to unblock idle. handle.close() From 95739aa76351a7218d5db8ba6f3aec26ba204637 Mon Sep 17 00:00:00 2001 From: Million <15158090088@163.com> Date: Mon, 6 Jul 2026 17:05:41 +0800 Subject: [PATCH 3/3] refactor: use polling loop instead of hardcoded sleep for race condition Replace fixed 200ms sleep with a polling loop that waits for the parent consumer to register in integration._contexts before publishing the depth=2 spawn event. Faster on local machines, more robust on slow CI. Accepts Gemini Code Assist review suggestion. --- tests/orchestrator/test_subagent_events.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/orchestrator/test_subagent_events.py b/tests/orchestrator/test_subagent_events.py index 0e28eb625..71b91e678 100644 --- a/tests/orchestrator/test_subagent_events.py +++ b/tests/orchestrator/test_subagent_events.py @@ -564,9 +564,12 @@ async def test_nested_subagents_create_recursive_toolparts() -> None: # But actually, the parent consumer subscribes with descendants scope to parent_id, # and the spawn event for child would be published on parent_id by the agent runtime. # Let's publish on parent_id. - # Extra sleep to ensure parent consumer is fully started before publishing - # depth=2 event — without this, the event can be missed on slow CI runners. - await asyncio.sleep(0.2) + # Wait for parent consumer to initialize before publishing depth=2 event. + for _ in range(50): + if parent_id in integration._contexts: + break + await asyncio.sleep(0.01) + await asyncio.sleep(0.05) await _publish_spawn_event( session_pool, parent_id, child_id, source_name="worker2", depth=2 )