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: 丢弃 controller_output.task_interaction,避免 HITL 打断泄漏内部 repr
renquanjiaedfeb78ac217
diff --git a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.pyindex d25473facd..9cc712b70e 100644--- a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py+++ b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py@@ -18486,8 +18486,6 @@ class JiuWenSwarmDeepAdapter:if inner_t is None and isinstance(payload, dict):inner_t = payload.get("type")inner_val = getattr(inner_t, "value", inner_t) if inner_t is not None else None- if inner_val == "task_completion":- return Noneif inner_val == "task_failed":data = getattr(payload, "data", None)if data is None and isinstance(payload, dict):@@ -18511,6 +18509,20 @@ class JiuWenSwarmDeepAdapter:"任务执行失败",)return {"event_type": "chat.error", "error": error or "任务执行失败"}+ # Close the controller_output enum: HITL cards are emitted via+ # ``__interaction__``; remaining types are control-plane metadata.+ # Never fall through to ``str(payload)`` → chat.delta (ISSUE #3892).+ if inner_val not in (+ "task_completion",+ "task_interaction",+ "processing",+ "all_tasks_processed",+ ):+ logger.debug(+ "[interface_deep] drop unhandled controller_output type=%r",+ inner_val,+ )+ return Noneif chunk_type == "llm_output":content = (diff --git a/jiuwenswarm/server/utils/stream_utils.py b/jiuwenswarm/server/utils/stream_utils.pyindex 9063d4248f..fb63005e05 100644--- a/jiuwenswarm/server/utils/stream_utils.py+++ b/jiuwenswarm/server/utils/stream_utils.py@@ -228,8 +228,6 @@ def _parse_typed_chunk(chunk: Any, _has_streamed_content: bool) -> dict[str, Anyinner_val = (getattr(inner_t, "value", inner_t) if inner_t is not None else None)- if inner_val == "task_completion":- return Noneif inner_val == "task_failed":data = getattr(payload, "data", None)if data is None and isinstance(payload, dict):@@ -252,6 +250,18 @@ def _parse_typed_chunk(chunk: Any, _has_streamed_content: bool) -> dict[str, Any"任务执行失败",)return {"event_type": "chat.error", "error": error}+ # Close the enum: do not stringify ControllerOutputPayload as visible text.+ if inner_val not in (+ "task_completion",+ "task_interaction",+ "processing",+ "all_tasks_processed",+ ):+ logger.debug(+ "[stream_utils] drop unhandled controller_output type=%r",+ inner_val,+ )+ return Noneif chunk_type == "llm_output":content = (diff --git a/tests/unit_tests/agentserver/test_interface_deep_stream_outbound.py b/tests/unit_tests/agentserver/test_interface_deep_stream_outbound.pyindex fe1a4dbde0..a65306ae5a 100644--- a/tests/unit_tests/agentserver/test_interface_deep_stream_outbound.py+++ b/tests/unit_tests/agentserver/test_interface_deep_stream_outbound.py@@ -216,6 +216,58 @@ def test_hitl_suppress_dict_task_failed_not_noise() -> None:assert parsed == {"event_type": "chat.error", "error": "model failed"}+def test_controller_output_task_interaction_is_dropped() -> None:+ """ISSUE #3892: TASK_INTERACTION must not stringify as chat.delta body."""+ chunk = SimpleNamespace(+ type="controller_output",+ payload=SimpleNamespace(+ type="task_interaction",+ data=[SimpleNamespace(data={"result_type": "interrupt", "state": []})],+ metadata={"task_id": "t1"},+ ),+ )+ parsed = JiuWenSwarmDeepAdapter._parse_stream_chunk(chunk)+ assert parsed is None+++def test_controller_output_control_plane_types_are_dropped() -> None:+ for inner in ("task_completion", "processing", "all_tasks_processed"):+ chunk = SimpleNamespace(+ type="controller_output",+ payload=SimpleNamespace(type=inner, data=[]),+ )+ assert JiuWenSwarmDeepAdapter._parse_stream_chunk(chunk) is None+++def test_controller_output_dict_task_interaction_is_dropped() -> None:+ chunk = SimpleNamespace(+ type="controller_output",+ payload={+ "type": "task_interaction",+ "data": [+ {+ "data": {+ "result_type": "interrupt",+ "state": [],+ "interrupt_ids": ["call_x"],+ "_interaction_emitted": True,+ }+ }+ ],+ "metadata": {"task_id": "t2"},+ },+ )+ assert JiuWenSwarmDeepAdapter._parse_stream_chunk(chunk) is None+++def test_controller_output_unknown_type_is_dropped() -> None:+ chunk = SimpleNamespace(+ type="controller_output",+ payload=SimpleNamespace(type="future_new_type", data=[]),+ )+ assert JiuWenSwarmDeepAdapter._parse_stream_chunk(chunk) is None++def test_hitl_suppress_cleared_on_resume_or_unknown_chunk() -> None:"""Content and unknown SDK frames clear suppress (default = resumed)."""for chunk_type in ("llm_output", "answer", "chat.file", "task.start", "tool_call"):