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(agent-teams): reversed is_processing flicker on cluster-mode follow-up requests

tangfei0306456a17ca6ed2
diff --git a/jiuwenswarm/gateway/message_handler/message_handler.py b/jiuwenswarm/gateway/message_handler/message_handler.py
index 4826e83dd5..8ea3901075 100644
--- a/jiuwenswarm/gateway/message_handler/message_handler.py
+++ b/jiuwenswarm/gateway/message_handler/message_handler.py
@@ -3149,12 +3149,23 @@ class MessageHandler(ABC):
continue
await self._handle_evolution_chunk(chunk, session_id, request_metadata)
# 携带 request metadata,供 Feishu/Xiaoyi 用平台身份回发
- # 检查是否是 processing_status=false 事件
+ # Detect processing_status=false event
payload = chunk.payload or {}
if isinstance(payload, dict):
- if payload.get("event_type") == "chat.processing_status":
+ event_type = payload.get("event_type")
+ if event_type == "chat.processing_status":
if payload.get("is_processing") is False:
has_processing_status_false = True
+ elif event_type == "chat.processing_status_deferred":
+ # Internal placeholder from the cluster-mode
+ # follow-up short stream: the real round-complete
+ # signal will be broadcast by the background team
+ # stream on team.completed. This marker only
+ # prevents the Gateway from auto-emitting
+ # is_processing=False when this short stream
+ # ends, and is NOT forwarded to the frontend.
+ has_processing_status_false = True
+ continue
out = self._chunk_to_message(
chunk,
diff --git a/jiuwenswarm/server/runtime/agent_adapter/team_helpers.py b/jiuwenswarm/server/runtime/agent_adapter/team_helpers.py
index 4f5241e399..705e2a5efc 100644
--- a/jiuwenswarm/server/runtime/agent_adapter/team_helpers.py
+++ b/jiuwenswarm/server/runtime/agent_adapter/team_helpers.py
@@ -883,7 +883,26 @@ async def process_team_message_stream(
session_id,
rid,
)
- yield _team_processing_done_chunk(rid, channel_id, session_id)
+ # NOTE: do NOT emit is_processing=False here.
+ # A follow-up request only enqueues the query into the running
+ # team stream; the actual LLM work still happens inside
+ # _consume_stream_with_query. The real "round complete" signal
+ # will be broadcast by that background stream once team.completed
+ # arrives, and forwarded to the frontend via the long-lived
+ # waiter that was registered by the first request.
+ # The deferred placeholder below tells the Gateway not to
+ # auto-emit is_processing=False when this short stream ends,
+ # which prevents the frontend from flashing
+ # "finished -> wait -> running again" before the LLM replies.
+ yield AgentResponseChunk(
+ request_id=rid,
+ channel_id=channel_id,
+ payload={
+ "event_type": "chat.processing_status_deferred",
+ "session_id": session_id,
+ },
+ is_complete=False,
+ )
yield AgentResponseChunk(
request_id=rid,
channel_id=channel_id,
diff --git a/tests/unit_tests/agentserver/test_team_helpers.py b/tests/unit_tests/agentserver/test_team_helpers.py
index fb112ea385..dbdd916f4d 100644
--- a/tests/unit_tests/agentserver/test_team_helpers.py
+++ b/tests/unit_tests/agentserver/test_team_helpers.py
@@ -1116,7 +1116,7 @@ async def test_process_team_message_stream_handles_team_evolve_list(monkeypatch,
@pytest.mark.anyio
-async def test_process_team_message_stream_emits_processing_done_for_followup(monkeypatch):
+async def test_process_team_message_stream_emits_deferred_marker_for_followup(monkeypatch):
class _FakeManager:
interact_calls: list[tuple[str, str]] = []
@@ -1156,12 +1156,14 @@ async def test_process_team_message_stream_emits_processing_done_for_followup(mo
assert _FakeManager.interact_calls == [
("sess-team-followup", "$human-reporter claim task"),
]
+ # follow-up short stream must NOT emit is_processing=False directly;
+ # it emits an internal deferred marker so the Gateway suppresses the
+ # auto-complete signal. The real round-complete event is broadcast
+ # later by the background team stream on team.completed.
assert len(chunks) == 2
assert chunks[0].payload == {
- "event_type": "chat.processing_status",
+ "event_type": "chat.processing_status_deferred",
"session_id": "sess-team-followup",
- "is_processing": False,
- "is_complete": True,
}
assert chunks[0].is_complete is False
assert chunks[1].payload is None
@@ -1503,10 +1505,8 @@ async def test_process_team_message_stream_recovers_paused_runtime_for_interacti
("sess-team-plan-recover", approval_input),
]
assert chunks[0].payload == {
- "event_type": "chat.processing_status",
+ "event_type": "chat.processing_status_deferred",
"session_id": "sess-team-plan-recover",
- "is_processing": False,
- "is_complete": True,
}
assert chunks[-1].is_complete is True
@@ -1650,10 +1650,8 @@ async def test_process_team_message_stream_converts_a2ui_followup_event(monkeypa
assert "submitDietForm" in prompt
assert "dietType" in prompt
assert chunks[0].payload == {
- "event_type": "chat.processing_status",
+ "event_type": "chat.processing_status_deferred",
"session_id": "sess-team-a2ui",
- "is_processing": False,
- "is_complete": True,
}
assert chunks[1].is_complete is True