fix: resolve flaky test_nested_subagents_create_recursive_toolparts - #117
Conversation
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.
There was a problem hiding this comment.
Code Review
This pull request adds a hardcoded sleep to prevent a race condition in a subagent events test. The reviewer correctly points out that using a hardcoded sleep is an anti-pattern and suggests replacing it with a polling loop to wait for the parent consumer to initialize, ensuring both speed and robustness.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| # 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) |
There was a problem hiding this comment.
Using a hardcoded asyncio.sleep(0.2) to resolve race conditions in tests is an anti-pattern. It can still be flaky on extremely slow CI runners, while unnecessarily slowing down the test suite on fast local machines.
Instead, we can use a polling loop with a timeout to wait for the parent consumer to be registered in integration._contexts, followed by a very brief sleep to allow the subscription to complete. This is both faster and more robust.
| # 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 | |
| for _ in range(50): | |
| if parent_id in integration._contexts: | |
| break | |
| await asyncio.sleep(0.01) | |
| await asyncio.sleep(0.05) |
Increase wait from 150ms to 300ms to avoid timing flakiness on slow CI runners where 50ms timeout + two turn executions exceed 150ms.
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.
2cb1e58
into
wolf1069b:feat/openai-compatible-native-tool-return
Problem
PR #115 的 Unit tests CI 挂了——
test_nested_subagents_create_recursive_toolparts在 CI 慢速环境下死锁,触发--timeout=60后 rerun 也卡住,最终 10 分钟 job 超时被 cancel。Root Cause
Depth=2 spawn event 在 parent consumer 还没完全启动时就发布了,事件丢失导致 assertion 永远等不到,测试挂起。
Fix
在发布 depth=2 spawn event 之前加
await asyncio.sleep(0.2),确保 parent consumer 完全启动。本地验证 3 次全部 < 1s 通过,无 rerun。