Skip to content

Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.

fix: honor configured capability discovery timeout (#251)

Rudy Mizrahi Celeklia3c375be5d10
diff --git a/ifixai/core/connection.py b/ifixai/core/connection.py
index b9e1152..da46e26 100644
--- a/ifixai/core/connection.py
+++ b/ifixai/core/connection.py
@@ -42,7 +42,10 @@ async def test_connection(
latency = round((time.monotonic() - start) * 1000, 1)
try:
- capabilities = await detect_capabilities(provider, config)
+ capabilities = await asyncio.wait_for(
+ detect_capabilities(provider, config),
+ timeout=config.timeout if config.timeout > 0 else None,
+ )
except Exception: # noqa: BLE001 — connection health probe; any failure is treated as unavailable
capabilities = None
diff --git a/ifixai/tests/test_connection_capability_timeout.py b/ifixai/tests/test_connection_capability_timeout.py
new file mode 100644
index 0000000..66ec86e
--- /dev/null
+++ b/ifixai/tests/test_connection_capability_timeout.py
@@ -0,0 +1,81 @@
+import asyncio
+
+import pytest
+
+from ifixai.core import connection
+from ifixai.core.types import ProviderConfig
+from ifixai.providers.base import ChatProvider
+
+
+class HungCapabilities(ChatProvider):
+ async def send_message(self, messages, config):
+ return "Hello"
+
+ async def list_tools(self, config):
+ await asyncio.Event().wait()
+
+
+async def test_connection_probe_bounds_capability_discovery(monkeypatch):
+ monkeypatch.setattr(connection, "CONNECTION_TEST_TIMEOUT", 0.01)
+ result = await asyncio.wait_for(
+ connection.test_connection(HungCapabilities(), ProviderConfig(provider="mock", timeout=1)),
+ timeout=2,
+ )
+ assert result.success
+ assert result.capabilities is None
+
+
+class SlowCapabilities(HungCapabilities):
+ async def list_tools(self, config):
+ await asyncio.sleep(0.03)
+ return []
+
+
[email protected]("timeout", [0, -1, 2])
+async def test_capability_probe_honors_configured_timeout(monkeypatch, timeout):
+ monkeypatch.setattr(connection, "CONNECTION_TEST_TIMEOUT", 0.01)
+ result = await connection.test_connection(
+ SlowCapabilities(), ProviderConfig(provider="mock", timeout=timeout)
+ )
+ assert result.success
+ assert result.capabilities is not None
+
+
+async def test_slow_http_retrieval_uses_provider_timeout(monkeypatch):
+ from aiohttp import web
+
+ from ifixai.providers.http import HttpProvider
+
+ async def chat(request):
+ return web.json_response({"choices": [{"message": {"content": "Hello"}}]})
+
+ async def retrieval(request):
+ await asyncio.sleep(0.3)
+ return web.json_response({"sources": []})
+
+ app = web.Application()
+ app.router.add_post("/chat/completions", chat)
+ app.router.add_post("/retrieve", retrieval)
+ runner = web.AppRunner(app)
+ await runner.setup()
+ site = web.TCPSite(runner, "127.0.0.1", 0)
+ await site.start()
+ provider = HttpProvider()
+ monkeypatch.setattr(connection, "CONNECTION_TEST_TIMEOUT", 0.2)
+ try:
+ result = await connection.test_connection(
+ provider,
+ ProviderConfig(
+ provider="http", timeout=2,
+ endpoint=f"http://127.0.0.1:{site._server.sockets[0].getsockname()[1]}",
+ ),
+ )
+ assert result.success
+ assert result.capabilities is not None
+ assert result.capabilities.has_retrieval
+ finally:
+ await provider.aclose()
+ await runner.cleanup()