The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(relay): fail sends fast while the reconnect supervisor is mid-redial
Victor Kyriazakosa7946f6502e3
diff --git a/gateway/relay/ws_transport.py b/gateway/relay/ws_transport.pyindex 2eebdd32115..be7ddb71ad7 100644--- a/gateway/relay/ws_transport.py+++ b/gateway/relay/ws_transport.py@@ -775,6 +775,16 @@ class WebSocketRelayTransport:return {"success": False, "error": "relay transport closed"}if self._ws is None:return {"success": False, "error": "relay transport not connected"}+ if self._supervisor is not None and not self._supervisor.done():+ # The reconnect supervisor is mid-redial (backing off after an+ # unexpected close). `self._ws` still points at the DEAD socket+ # until _dial_and_start() replaces it, so the check above does not+ # cover this window — a send here would register a future no+ # reader can resolve and block the caller for _outbound_timeout_s+ # (Coatue incident 2026-08-18). Fail fast with the dict shape+ # callers expect; a live supervisor's dial success ends the task,+ # so `not done()` is exactly the redial window.+ return {"success": False, "error": "relay transport reconnecting"}request_id = uuid.uuid4().hexloop = asyncio.get_running_loop()fut: asyncio.Future[Dict[str, Any]] = loop.create_future()diff --git a/tests/gateway/relay/test_ws_transport_hardening.py b/tests/gateway/relay/test_ws_transport_hardening.pyindex edeb1414864..07991041c51 100644--- a/tests/gateway/relay/test_ws_transport_hardening.py+++ b/tests/gateway/relay/test_ws_transport_hardening.py@@ -81,3 +81,26 @@ async def test_read_loop_exit_fails_pending_futures_promptly():assert result == {"success": False, "error": "relay transport connection lost"}assert t._pending == {}await t._reader+++async def test_send_during_redial_window_fails_fast():+ """While the reconnect supervisor is backing off, _ws still points at the+ dead socket — a send must return an error dict immediately (no+ RuntimeError, no 30s timeout on an unresolvable future)."""+ t = WebSocketRelayTransport("ws://unused", "discord", "bot1", outbound_timeout_s=30.0)+ t._ws = _DroppingWS() # stale/dead socket left over from before the drop+ t._supervisor = asyncio.create_task(asyncio.sleep(60)) # mid-redial backoff+ try:+ result = await asyncio.wait_for(+ t.send_outbound({"op": "send_message", "text": "hi"}), timeout=1.0+ )+ assert result["success"] is False+ assert "reconnect" in result["error"]+ assert t._pending == {}+ finally:+ t._supervisor.cancel()+ try:+ await t._supervisor+ except asyncio.CancelledError:+ pass