Skip to content

The agent that grows with you

fix(tests): de-flake sequential-tool-timeout race on loaded runners

Tekniuma2cc86787069
diff --git a/tests/run_agent/test_sequential_tool_timeout.py b/tests/run_agent/test_sequential_tool_timeout.py
index fbcb46a133b..e50f71ab187 100644
--- a/tests/run_agent/test_sequential_tool_timeout.py
+++ b/tests/run_agent/test_sequential_tool_timeout.py
@@ -105,12 +105,27 @@ def test_sequential_tool_timeout_emits_result_and_continues(tmp_path, monkeypatc
),
):
execute_tool_calls_sequential(agent, assistant, messages, "task")
+ elapsed = time.monotonic() - started
+ release_first.set()
+ # Give a late-scheduled worker a moment to drain inside the patch
+ # context (if the with block exits first, a late worker would hit
+ # the REAL handle_function_call).
+ for _ in range(100):
+ if "next" in dispatched:
+ break
+ time.sleep(0.05)
finally:
release_first.set()
- assert first_started.is_set()
- assert time.monotonic() - started < 1.0
- assert dispatched == ["hung", "next"]
+ assert elapsed < 1.0 # the EXECUTOR must not have waited for the hung call
+ # The hung call's dispatch is NOT guaranteed: on a loaded runner the
+ # 0.05s timeout can expire before its worker thread starts, in which case
+ # future.cancel() legitimately prevents the dispatch entirely
+ # (tool_executor timeout path). The contract is: the executor emitted a
+ # timeout result for it and CONTINUED — the next tool must have actually
+ # run, and the message stream must carry both call ids in order.
+ assert "next" in dispatched
+ assert set(dispatched) <= {"hung", "next"}
assert [message["tool_call_id"] for message in messages] == ["hung", "next"]
assert "timed out after 0.1s" in messages[0]["content"]
assert messages[0]["effect_disposition"] == "unknown"