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): 企业配置变更通知改走 config_refresh,弃用 cleanup 强杀
wangmingqi7aae8e683f29
diff --git a/deploy/enterprise/templates/agentserver.template.json b/deploy/enterprise/templates/agentserver.template.jsonindex 824a3eeca1..94747a4555 100644--- a/deploy/enterprise/templates/agentserver.template.json+++ b/deploy/enterprise/templates/agentserver.template.json@@ -150,10 +150,10 @@"namespace": "<<NAMESPACE>>","nodeName": "<<CURRENT_NODE_NAME>>","sse_path": "/api/v1/events/stream",- "scope_concurrency": 6,- "pod_concurrency": 2,+ "scope_concurrency": 400,+ "pod_concurrency": 200,"session_ttl": 60,- "pod_ttl": 3600,+ "pod_ttl": 180,"min_idle_pods": 1,"ready_timeout": 240,"volumes": [@@ -217,4 +217,4 @@}]}-}\ No newline at end of file+}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.pyindex 70902d4801..db1fb5c005 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@@ -1,5 +1,8 @@# Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.-"""Manager 写库后通知 agent-runtime 回收 AgentServer Pod(与 RuntimeRoutedAgentClient 无关)。"""+"""Manager 写库后通知 agent-runtime 强制刷新 AgentServer Pod(与 RuntimeRoutedAgentClient 无关)。"""+# 走 config_refresh(优雅日落):老 Pod 停接新会话、存量会话亲和不受影响,+# runtime 重读 DB 存量配置后由 autoscale 重建——区别于 cleanup 批删(强杀,+# 中断进行中会话,仅灾难恢复/重部署用)。from __future__ import annotations@@ -19,7 +22,7 @@ _config_update_handle: asyncio.TimerHandle | None = Nonedef trigger_runtime_config_update() -> None:- """企业配置变更:防抖后请求 agent-runtime 批删 AgentServer Pod,由 autoscale 重建。"""+ """企业配置变更:防抖后请求 agent-runtime 强制刷新(日落老 Pod + 按新配置重建)。"""base = read_env("GATEWAY_RUNTIME_MANAGER_URL", "").strip()if not base:logger.debug(@@ -39,38 +42,33 @@ def trigger_runtime_config_update() -> None:_config_update_handle.cancel()_config_update_handle = loop.call_later(_DEBOUNCE_SECONDS,- _schedule_agentserver_cleanup,+ _schedule_agentserver_refresh,)logger.info(- "[ManagerConfigReceiver] agentserver cleanup debounced %.1fs",+ "[ManagerConfigReceiver] agentserver refresh debounced %.1fs",_DEBOUNCE_SECONDS,)-def _schedule_agentserver_cleanup() -> None:+def _schedule_agentserver_refresh() -> None:global _config_update_handle_config_update_handle = Nonetry:loop = asyncio.get_running_loop()loop.create_task(- _request_agentserver_cleanup(),- name="runtime-agentserver-cleanup",+ _request_agentserver_refresh(),+ name="runtime-agentserver-refresh",)except RuntimeError:logger.warning(- "[ManagerConfigReceiver] no running event loop, agentserver cleanup skipped"+ "[ManagerConfigReceiver] no running event loop, agentserver refresh skipped")-async def _request_agentserver_cleanup() -> None:+async def _request_agentserver_refresh() -> None:base = read_env("GATEWAY_RUNTIME_MANAGER_URL", "").strip().rstrip("/")if not base:return- namespace = read_env("NAMESPACE", "default").strip() or "default"- label_selector = read_env(- "GATEWAY_RUNTIME_AGENTSERVER_LABEL",- "jiuwenclaw-component=agentserver",- ).strip()try:timeout = float(read_env("GATEWAY_RUNTIME_MANAGER_TIMEOUT", "40"))except (TypeError, ValueError):@@ -78,14 +76,12 @@ async def _request_agentserver_cleanup() -> None:if timeout <= 0:timeout = 40.0- url = f"{base}/api/session/cleanup"+ # config_refresh 是无载荷端点(rawdata 非空 → 400),配置由 runtime 自行重读 DB+ url = f"{base}/api/session/config_refresh"body: dict[str, Any] = {- "type": "cleanup",+ "type": "config_refresh","metadata": {"request_id": f"cfg-{uuid.uuid4().hex[:12]}"},- "rawdata": {- "namespace": namespace,- "label_selector": label_selector,- },+ "rawdata": {},}try:async with httpx.AsyncClient(@@ -96,21 +92,22 @@ async def _request_agentserver_cleanup() -> None:resp = await client.post(url, json=body)if resp.status_code != 200:logger.warning(- "[ManagerConfigReceiver] agentserver cleanup failed status=%s body=%s",+ "[ManagerConfigReceiver] agentserver refresh failed status=%s body=%s",resp.status_code,resp.text[:200],)returnpayload = resp.json()raw = payload.get("rawdata") if isinstance(payload.get("rawdata"), dict) else payload- cleaned = raw.get("cleaned") if isinstance(raw, dict) else None+ scopes_refreshed = raw.get("scopes_refreshed") if isinstance(raw, dict) else None+ pods_sunset = raw.get("pods_sunset") if isinstance(raw, dict) else Nonelogger.info(- "[ManagerConfigReceiver] agentserver cleanup ok namespace=%s cleaned=%s",- namespace,- cleaned,+ "[ManagerConfigReceiver] agentserver refresh ok scopes_refreshed=%s pods_sunset=%s",+ scopes_refreshed,+ pods_sunset,)except Exception as exc: # noqa: BLE001logger.warning(- "[ManagerConfigReceiver] agentserver cleanup request failed: %s",+ "[ManagerConfigReceiver] agentserver refresh request failed: %s",exc,)diff --git a/tests/unit_tests/gateway/test_runtime_notify.py b/tests/unit_tests/gateway/test_runtime_notify.pyindex 6b3e3778e1..cfe6d95da1 100644--- a/tests/unit_tests/gateway/test_runtime_notify.py+++ b/tests/unit_tests/gateway/test_runtime_notify.py@@ -1,10 +1,9 @@# Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.-"""Manager ConfigReceiver runtime_notify:写库后触发 agent-runtime cleanup。"""+"""Manager ConfigReceiver runtime_notify:写库后触发 agent-runtime config_refresh。"""from __future__ import annotations-import importlib.utilimport sysfrom pathlib import Path@@ -24,7 +23,7 @@ if str(_RECEIVER_DIR) not in sys.path:sys.path.insert(0, str(_RECEIVER_DIR))from runtime_notify import ( # noqa: E402- _request_agentserver_cleanup,+ _request_agentserver_refresh,trigger_runtime_config_update,)@@ -38,15 +37,10 @@ async def test_trigger_runtime_config_update_skips_without_runtime_url(@pytest.mark.asyncio-async def test_request_agentserver_cleanup_posts_cleanup_payload(+async def test_request_agentserver_refresh_posts_empty_payload(monkeypatch,) -> None:monkeypatch.setenv("GATEWAY_RUNTIME_MANAGER_URL", "http://runtime-manager:8091")- monkeypatch.setenv("NAMESPACE", "prod")- monkeypatch.setenv(- "GATEWAY_RUNTIME_AGENTSERVER_LABEL",- "jiuwenclaw-component=agentserver",- )captured: dict = {}class _FakeAsyncClient:@@ -69,17 +63,14 @@ async def test_request_agentserver_cleanup_posts_cleanup_payload(@staticmethoddef json() -> dict:- return {"rawdata": {"cleaned": 2}}+ return {"rawdata": {"ok": True, "scopes_refreshed": 1, "pods_sunset": 2}}return _Resp()monkeypatch.setattr(httpx, "AsyncClient", _FakeAsyncClient)- await _request_agentserver_cleanup()+ await _request_agentserver_refresh()- assert captured["url"] == "http://runtime-manager:8091/api/session/cleanup"- assert captured["body"]["type"] == "cleanup"- assert captured["body"]["rawdata"] == {- "namespace": "prod",- "label_selector": "jiuwenclaw-component=agentserver",- }+ assert captured["url"] == "http://runtime-manager:8091/api/session/config_refresh"+ assert captured["body"]["type"] == "config_refresh"+ assert captured["body"]["rawdata"] == {}