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(team): silence chat.error on gate_closed during shutdown race
iamcandiceguo569d4ca91e03
diff --git a/jiuwenswarm/server/runtime/agent_adapter/team_helpers.py b/jiuwenswarm/server/runtime/agent_adapter/team_helpers.pyindex 3dc3273d4d..afd5303c11 100644--- a/jiuwenswarm/server/runtime/agent_adapter/team_helpers.py+++ b/jiuwenswarm/server/runtime/agent_adapter/team_helpers.py@@ -1528,8 +1528,18 @@ async def process_team_message_stream(else:reason = reason or "gate_closed"if not success and not is_first_request:+ final_reason = reason or ""+ # gate_closed 是 shutdown race(leader stream 正在收尾),静默结束流+ if final_reason == "gate_closed":+ yield AgentResponseChunk(+ request_id=rid,+ channel_id=channel_id,+ payload=None,+ is_complete=True,+ )+ returnerror_msg = _INTERACT_REASON_ERROR_MAP.get(- reason or "",+ final_reason,"Failed to send message, please try again later",)yield AgentResponseChunk(diff --git a/jiuwenswarm/server/ws_send.py b/jiuwenswarm/server/ws_send.pyindex 2e490edbbe..fa9b58bfea 100644--- a/jiuwenswarm/server/ws_send.py+++ b/jiuwenswarm/server/ws_send.py@@ -101,14 +101,22 @@ async def send_wire_payload(ws: Any, wire: dict[str, Any]) -> bool:await ws.send(serialized)return True+ _preview = serialized[:1000]+ if len(serialized) > 1000:+ _preview += "...(truncated)"logger.error(- "AgentServer WebSocket response too large: request_id=%s "- "response_kind=%s is_stream=%s actual_bytes=%d max_bytes=%d",+ "AgentServer WebSocket response too large: "+ "request_id=%s session_id=%s channel=%s type=%s is_stream=%s "+ "response_kind=%s actual_bytes=%d max_bytes=%d preview=%s",wire.get("request_id"),- wire.get("response_kind"),+ wire.get("session_id"),+ wire.get("channel") or wire.get("channel_id"),+ wire.get("type"),wire.get("is_stream"),+ wire.get("response_kind"),actual_bytes,AGENT_WS_SEND_BUDGET_BYTES,+ _preview,)fallback = _build_oversized_fallback(wire, actual_bytes)fallback_json = json.dumps(fallback, ensure_ascii=False)diff --git a/tests/unit_tests/agentserver/test_team_helpers.py b/tests/unit_tests/agentserver/test_team_helpers.pyindex 4bfc1b682b..a50e54ebfd 100644--- a/tests/unit_tests/agentserver/test_team_helpers.py+++ b/tests/unit_tests/agentserver/test_team_helpers.py@@ -1750,7 +1750,7 @@ async def test_process_team_message_stream_fallback_reuses_first_request_directi@pytest.mark.anyio-async def test_process_team_message_stream_reports_error_when_shutdown_race_wait_times_out(monkeypatch):+async def test_process_team_message_stream_silences_gate_closed_when_shutdown_race_times_out(monkeypatch):class _FakeManager(_InactiveTeamRuntimeManagerMixin):@staticmethoddef has_stream_task(session_id: str) -> bool:@@ -1806,11 +1806,12 @@ async def test_process_team_message_stream_reports_error_when_shutdown_race_wait):chunks.append(chunk)- assert chunks[0].payload == {- "event_type": "chat.error",- "error": "Team is shutting down, please try again later",- }+ # gate_closed 静默处理:不报 chat.error,直接以 is_complete=True 结束流assert chunks[-1].is_complete is True+ assert not any(+ chunk.payload and chunk.payload.get("event_type") == "chat.error"+ for chunk in chunks+ )@pytest.mark.anyio