From 756dd75fbe8b799b94461ce5be4599f0eca3a8ac Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Sun, 5 Jul 2026 19:55:40 -0700 Subject: [PATCH] fix(mcp): iteration-bound the session-ready poll so frozen-clock tests can't spin forever _wait_for_server_session_ready used a time.monotonic deadline; the circuit-breaker tests freeze monotonic, turning the loop into an infinite spin (300s SIGKILL in CI-parity runs). Bound by iteration count instead. --- tools/mcp_tool.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/mcp_tool.py b/tools/mcp_tool.py index 50c5dcc57e9..6a148acd6d8 100644 --- a/tools/mcp_tool.py +++ b/tools/mcp_tool.py @@ -2836,8 +2836,12 @@ def _wait_for_server_session_ready( different so callers do not mistake the pre-reconnect, stale session for a fresh one. """ - deadline = time.monotonic() + max(float(timeout), 0.0) - while time.monotonic() < deadline: + # Iteration-bounded rather than deadline-bounded: several tests (and the + # circuit-breaker cooldown logic) monkeypatch time.monotonic to a frozen + # clock, which would make a monotonic-deadline loop spin forever. + poll_interval = 0.25 + iterations = max(1, int(max(float(timeout), 0.0) / poll_interval)) + for i in range(iterations): session = getattr(srv, "session", None) ready = getattr(srv, "_ready", None) is_ready = True @@ -2848,7 +2852,8 @@ def _wait_for_server_session_ready( is_ready = True if session is not None and session is not old_session and is_ready: return True - time.sleep(0.25) + if i < iterations - 1: + time.sleep(poll_interval) return False