Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(gateway): 将 Runtime Manager 客户端默认超时调到 300 秒

meizi6cc4dc8e7face
diff --git a/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/routers/runtime_notify.py b/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/routers/runtime_notify.py
index 1cfe62b460..4e4f79ccd0 100644
--- a/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/routers/runtime_notify.py
+++ b/packages/jiuwenclaw-ee/gateway/extensions/manager_config_receiver/routers/runtime_notify.py
@@ -83,12 +83,14 @@ async def _request_agentserver_refresh(
base = "link://runtime"
if not base:
return
+ # 与 session route 客户端共用同一变量,未配置时同为 300s。
+ # config_refresh 在锁内按 scope 日落,规模大时可超过原先的 40s。
try:
- timeout = float(read_env("GATEWAY_RUNTIME_MANAGER_TIMEOUT", "40"))
+ timeout = float(read_env("GATEWAY_RUNTIME_MANAGER_TIMEOUT", "300"))
except (TypeError, ValueError):
- timeout = 40.0
+ timeout = 300.0
if timeout <= 0:
- timeout = 40.0
+ timeout = 300.0
# config_refresh 是无载荷端点(rawdata 非空 → 400),配置由 runtime 自行重读 DB
url = f"{base}/api/session/config_refresh"
diff --git a/packages/jiuwenclaw-ee/gateway/extensions/runtime_management_extension/session_route_client.py b/packages/jiuwenclaw-ee/gateway/extensions/runtime_management_extension/session_route_client.py
index 4be2246d7b..ba502eafe2 100644
--- a/packages/jiuwenclaw-ee/gateway/extensions/runtime_management_extension/session_route_client.py
+++ b/packages/jiuwenclaw-ee/gateway/extensions/runtime_management_extension/session_route_client.py
@@ -93,11 +93,11 @@ class RuntimeSessionRouteClient:
timeout = timeout_seconds
if timeout is None:
try:
- timeout = float(read_env("GATEWAY_RUNTIME_MANAGER_TIMEOUT", "40"))
+ timeout = float(read_env("GATEWAY_RUNTIME_MANAGER_TIMEOUT", "300"))
except (TypeError, ValueError):
- timeout = 40.0
+ timeout = 300.0
if timeout <= 0:
- timeout = 40.0
+ timeout = 300.0
# route 可能排队到 scope_full_timeout(默认 30s),连接超时单独收短
self._http = httpx.AsyncClient(
timeout=httpx.Timeout(timeout, connect=min(5.0, timeout)),
diff --git a/tests/unit_tests/gateway/test_runtime_notify.py b/tests/unit_tests/gateway/test_runtime_notify.py
index 7603495a33..17f4af88ad 100644
--- a/tests/unit_tests/gateway/test_runtime_notify.py
+++ b/tests/unit_tests/gateway/test_runtime_notify.py
@@ -91,6 +91,59 @@ async def test_request_agentserver_refresh_posts_empty_payload(
assert captured["headers"] == {}
+ ("raw", "expected_read"),
+ [
+ (None, 300.0),
+ ("15", 15.0),
+ ("not-a-number", 300.0),
+ ("0", 300.0),
+ ("-1", 300.0),
+ ],
+)
+async def test_config_refresh_timeout_matches_runtime_manager_default(
+ monkeypatch,
+ raw: str | None,
+ expected_read: float,
+) -> None:
+ monkeypatch.setenv("GATEWAY_RUNTIME_MANAGER_URL", "http://runtime-manager:8091")
+ if raw is None:
+ monkeypatch.delenv("GATEWAY_RUNTIME_MANAGER_TIMEOUT", raising=False)
+ else:
+ monkeypatch.setenv("GATEWAY_RUNTIME_MANAGER_TIMEOUT", raw)
+ captured: dict = {}
+
+ class _FakeAsyncClient:
+ def __init__(self, **kwargs) -> None:
+ captured["timeout"] = kwargs["timeout"]
+
+ async def __aenter__(self):
+ return self
+
+ async def __aexit__(self, *args):
+ return None
+
+ async def post(self, url: str, *, json: dict | None = None, headers: dict | None = None):
+ class _Resp:
+ status_code = 200
+ text = ""
+
+ @staticmethod
+ def json() -> dict:
+ return {"rawdata": {"scopes_refreshed": 0, "pods_sunset": 0}}
+
+ return _Resp()
+
+ monkeypatch.setattr(httpx, "AsyncClient", _FakeAsyncClient)
+
+ await _request_agentserver_refresh()
+
+ timeout = captured["timeout"]
+ assert timeout.read == expected_read
+ assert timeout.connect == min(5.0, expected_read)
+
+
@pytest.mark.asyncio
async def test_request_agentserver_refresh_enforce_sends_binding_headers(
monkeypatch,
diff --git a/tests/unit_tests/gateway/test_session_route.py b/tests/unit_tests/gateway/test_session_route.py
index bf07d4c932..ae076a6bc5 100644
--- a/tests/unit_tests/gateway/test_session_route.py
+++ b/tests/unit_tests/gateway/test_session_route.py
@@ -361,4 +361,5 @@ async def test_blank_url_and_bad_timeout_fall_back(
monkeypatch.setenv("GATEWAY_RUNTIME_MANAGER_TIMEOUT", "not-a-number")
client = RuntimeSessionRouteClient()
assert client._route_url == "http://127.0.0.1:8091/api/session/route"
+ assert client._http.timeout.read == 300.0
await client.aclose()