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: websocket超时断连接及消息丢失问题
ray_lec4af62550cc5
diff --git a/jiuwenclaw/app_gateway.py b/jiuwenclaw/app_gateway.pyindex 21da5b5c98..961944c60a 100644--- a/jiuwenclaw/app_gateway.py+++ b/jiuwenclaw/app_gateway.py@@ -1134,7 +1134,7 @@ async def _run(logger.info("[App] using extension AgentServerClient: %s", agent_server_ext.metadata.name)client = agent_server_ext.get_client()else:- client = WebSocketAgentServerClient(ping_interval=20.0, ping_timeout=20.0)+ client = WebSocketAgentServerClient(ping_interval=20.0, ping_timeout=600.0)await _connect_with_retry(client,agent_server_url,diff --git a/jiuwenclaw/gateway/agent_client.py b/jiuwenclaw/gateway/agent_client.pyindex 50abc7466c..ef41f66684 100644--- a/jiuwenclaw/gateway/agent_client.py+++ b/jiuwenclaw/gateway/agent_client.py@@ -22,7 +22,7 @@ from jiuwenclaw.schema.agent import AgentResponse, AgentResponseChunklogger = logging.getLogger(__name__)-_STREAM_TRAILING_MESSAGE_GRACE_SECONDS = 0.35+_STREAM_TRAILING_MESSAGE_GRACE_SECONDS = 0.7def _wire_request_id_key(request_id: Any) -> str:diff --git a/jiuwenclaw/gateway/message_handler.py b/jiuwenclaw/gateway/message_handler.pyindex c7ae629d66..2ce15e0139 100644--- a/jiuwenclaw/gateway/message_handler.py+++ b/jiuwenclaw/gateway/message_handler.py@@ -1228,15 +1228,22 @@ class MessageHandler(ABC):# 有新输入:取消旧任务 → 保留 todo → 启动新任务(非并发)- # 1. 取消 gateway 侧所有运行中的流式任务+ # 1. 取消 gateway 侧当前 session 相关的流式任务(而非所有任务)tasks_to_cancel = []+ rids_cancelled = []+ current_sid = msg.session_idfor rid, task in list(self._stream_tasks.items()):+ # 只取消与当前 session_id 关联的任务+ if self._stream_sessions.get(rid) != current_sid:+ continueif not task.done():logger.info(- "[MessageHandler] supplement: 取消流式任务 request_id=%s", rid,+ "[MessageHandler] supplement: 取消流式任务 request_id=%s session_id=%s",+ rid, current_sid,)task.cancel()tasks_to_cancel.append(task)+ rids_cancelled.append(rid)if tasks_to_cancel:await asyncio.gather(*tasks_to_cancel, return_exceptions=True)