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(xiaoyi): CLI notice 下发 is_complete 终止信号
NickFuryXXX2d369f1b617c
diff --git a/jiuwenswarm/gateway/message_handler/message_handler.py b/jiuwenswarm/gateway/message_handler/message_handler.pyindex 995a45d8d9..0f937feea1 100644--- a/jiuwenswarm/gateway/message_handler/message_handler.py+++ b/jiuwenswarm/gateway/message_handler/message_handler.py@@ -659,16 +659,18 @@ class MessageHandler(ABC):- str: 兼容历史行为,封装为 {"content": text, "is_complete": True}- dict: 透传给 channel(仅确保 is_complete=True)++ 小艺 channel 按 payload.is_complete 判定任务结束(True → WS final=true,+ 关闭「处理中」接收周期)。CLI 控制指令等 notice 均为终态回包,必须默认 True;+ 若确需多帧未完结,调用方显式传入 is_complete=False。"""from jiuwenswarm.common.schema.message import Message, EventType- # 小艺 channel 按 payload.is_complete 判定任务结束(收到 True 即关闭接收周期)。- _default_complete = False if channel_id == "xiaoyi" else Trueif isinstance(text_or_payload, dict):payload = dict(text_or_payload)- payload.setdefault("is_complete", _default_complete)+ payload.setdefault("is_complete", True)else:- payload = {"content": text_or_payload, "is_complete": _default_complete}+ payload = {"content": text_or_payload, "is_complete": True}_app_id = user_infos.get("app_id") or user_infos.get("bot_id", "")msg = Message(diff --git a/tests/unit_tests/gateway/test_send_channel_notice_complete.py b/tests/unit_tests/gateway/test_send_channel_notice_complete.pynew file mode 100644index 0000000000..beff941729--- /dev/null+++ b/tests/unit_tests/gateway/test_send_channel_notice_complete.py@@ -0,0 +1,112 @@+# Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.++"""Tests for MessageHandler.send_channel_notice is_complete defaults.++Issue #300: 小艺 CLI 指令(/mode agent、/new_session 等)回包若 is_complete=False,+WS 只下发 lastChunk 而不带 final=true,界面会一直处于「处理中」直到超时。+"""++from __future__ import annotations++from types import SimpleNamespace++import pytest++from jiuwenswarm.common.schema.message import EventType+from jiuwenswarm.gateway.message_handler.message_handler import MessageHandler+++class _FakeAgentClient:+ @staticmethod+ async def send_request(env: object) -> SimpleNamespace:+ return SimpleNamespace(ok=True, payload={})++ @staticmethod+ async def send_request_stream(env: object):+ if False: # pragma: no cover+ yield env+++class _TestMessageHandler(MessageHandler):+ @classmethod+ def create(cls) -> "_TestMessageHandler":+ setattr(MessageHandler, "_instance", None)+ setattr(cls, "_instance", None)+ handler = cls(_FakeAgentClient())+ handler.published = []+ return handler++ async def publish_robot_messages(self, msg: object) -> None:+ self.published.append(msg)+++def _user_infos() -> dict:+ return {+ "id": "req-notice-1",+ "meta_data": {"xiaoyi_session_id": "xy-sess", "xiaoyi_task_id": "xy-task"},+ "app_id": "app-1",+ }+++async def test_send_channel_notice_xiaoyi_defaults_is_complete_true() -> None:+ """CLI notice to xiaoyi must complete so UI exits processing (Issue #300)."""+ handler = _TestMessageHandler.create()++ await handler.send_channel_notice(+ _user_infos(),+ "xiaoyi",+ "sess-1",+ "[收到 CLI 指令], mode 已变更为 agent",+ )++ assert len(handler.published) == 1+ msg = handler.published[0]+ assert msg.channel_id == "xiaoyi"+ assert msg.event_type == EventType.CHAT_FINAL+ assert msg.payload["content"] == "[收到 CLI 指令], mode 已变更为 agent"+ assert msg.payload["is_complete"] is True+++async def test_send_channel_notice_other_channel_defaults_is_complete_true() -> None:+ handler = _TestMessageHandler.create()++ await handler.send_channel_notice(+ _user_infos(),+ "feishu",+ "sess-1",+ "ok",+ )++ assert handler.published[0].payload["is_complete"] is True+++async def test_send_channel_notice_dict_setdefault_preserves_explicit_false() -> None:+ """Callers that need multi-frame notices can still pass is_complete=False."""+ handler = _TestMessageHandler.create()++ await handler.send_channel_notice(+ _user_infos(),+ "xiaoyi",+ "sess-1",+ {"content": "partial", "is_complete": False},+ )++ assert handler.published[0].payload["is_complete"] is False+ assert handler.published[0].payload["content"] == "partial"+++async def test_send_channel_notice_dict_fills_missing_is_complete_true() -> None:+ handler = _TestMessageHandler.create()++ await handler.send_channel_notice(+ _user_infos(),+ "xiaoyi",+ "sess-1",+ {"content": "skills list"},+ )++ assert handler.published[0].payload["is_complete"] is True