diff --git a/agents/fce.py b/agents/fce.py index da33ad5..1a8b747 100644 --- a/agents/fce.py +++ b/agents/fce.py @@ -74,13 +74,20 @@ async def run_fce( origin = flight_status.get("origin", "") destination = flight_status.get("destination", "") - async def _call(server, tool, args, is_live=False): + async def _call(server, tool, args, is_live=False, timeout=15.0): t = time.time() try: - result = await mcp.call_tool(server, tool, args) + result = await asyncio.wait_for( + mcp.call_tool(server, tool, args), timeout=timeout, + ) lat = int((time.time() - t) * 1000) await emit("tool_call_end", tool=tool, latency_ms=lat, is_live=is_live) return result + except asyncio.TimeoutError: + lat = int((time.time() - t) * 1000) + await emit("tool_call_error", tool=tool, error="timeout", latency_ms=lat) + errors.append(f"{tool}: timeout after {timeout}s") + return None except Exception as e: lat = int((time.time() - t) * 1000) await emit("tool_call_error", tool=tool, error=str(e), latency_ms=lat) diff --git a/agents/handover.py b/agents/handover.py index 14897bf..6efbb16 100644 --- a/agents/handover.py +++ b/agents/handover.py @@ -52,13 +52,20 @@ async def run_handover( await emit("node_enter", node="gather_all") - async def _call(server, tool, args, is_live=False): + async def _call(server, tool, args, is_live=False, timeout=15.0): t = time.time() try: - result = await mcp.call_tool(server, tool, args) + result = await asyncio.wait_for( + mcp.call_tool(server, tool, args), timeout=timeout, + ) lat = int((time.time() - t) * 1000) await emit("tool_call_end", tool=tool, latency_ms=lat, is_live=is_live) return result + except asyncio.TimeoutError: + lat = int((time.time() - t) * 1000) + await emit("tool_call_error", tool=tool, error="timeout", latency_ms=lat) + errors.append(f"{tool}: timeout after {timeout}s") + return None except Exception as e: lat = int((time.time() - t) * 1000) await emit("tool_call_error", tool=tool, error=str(e), latency_ms=lat)