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:解决skillTurbo场景中ask_user后重复推送已完成任务进度描述问题

Chenchong_RD4adf63049c59
diff --git a/jiuwenswarm/server/runtime/skill_turbo/executor.py b/jiuwenswarm/server/runtime/skill_turbo/executor.py
index 79c70539fd..c277bfa5c8 100644
--- a/jiuwenswarm/server/runtime/skill_turbo/executor.py
+++ b/jiuwenswarm/server/runtime/skill_turbo/executor.py
@@ -2733,6 +2733,38 @@ class SkillTurboExecutor:
)
return True
+ async def _should_suppress_subplan_start_banner(
+ self,
+ subplan: PlanNode,
+ inputs: dict[str, Any],
+ ) -> bool:
+ """HITL resume 重放时,抑制二层 stage 的「开始执行」进度横幅。
+
+ completed stage 已由 ``_should_skip_subplan_execute`` 静默跳过;
+ in_progress stage 仍需重入(命中 ask_user tool_call_id),但不应再刷横幅。
+ """
+ del inputs
+ if not self._resume_replay:
+ return False
+ if subplan.depth != 1:
+ return False
+ task_states = self._live_task_states()
+ if not task_states:
+ return False
+ found = self._find_task_state_by_plan_name(subplan.plan_name, task_states)
+ if found is None:
+ return False
+ _task_id, task_state = found
+ if task_state.get("status") != "in_progress":
+ return False
+ logger.info(
+ "[SkillTurboExecutor] suppress start banner for in-progress stage "
+ "(HITL resume replay): plan_name=%s task_id=%s",
+ subplan.plan_name,
+ _task_id,
+ )
+ return True
+
async def _before_subplan_execute(
self, subplan: PlanNode, inputs: dict[str, Any]
) -> None:
@@ -3244,6 +3276,7 @@ class SkillTurboExecutor:
before_subplan_execute=self._before_subplan_execute,
after_subplan_execute=self._after_subplan_execute,
should_skip_subplan_execute=self._should_skip_subplan_execute,
+ should_suppress_subplan_start_banner=self._should_suppress_subplan_start_banner,
)
@staticmethod
diff --git a/jiuwenswarm/server/runtime/skill_turbo/plan_node.py b/jiuwenswarm/server/runtime/skill_turbo/plan_node.py
index 17f6879089..f836d77eb9 100644
--- a/jiuwenswarm/server/runtime/skill_turbo/plan_node.py
+++ b/jiuwenswarm/server/runtime/skill_turbo/plan_node.py
@@ -82,6 +82,10 @@ class PlanNode(ABC):
self._should_skip_subplan_execute: (
Callable[[PlanNode, dict[str, Any]], Awaitable[bool]] | None
) = None
+ # HITL resume:in_progress 的二层 stage 重入时不广播「开始执行」横幅
+ self._should_suppress_subplan_start_banner: (
+ Callable[[PlanNode, dict[str, Any]], Awaitable[bool]] | None
+ ) = None
def _update_subplans_depth(self) -> None:
"""递归更新所有子节点的深度。
@@ -111,6 +115,9 @@ class PlanNode(ABC):
should_skip_subplan_execute: (
Callable[[PlanNode, dict[str, Any]], Awaitable[bool]] | None
) = None,
+ should_suppress_subplan_start_banner: (
+ Callable[[PlanNode, dict[str, Any]], Awaitable[bool]] | None
+ ) = None,
) -> None:
self._has_tool_callback = has_tool
self._call_tool_callback = use_tool
@@ -123,6 +130,7 @@ class PlanNode(ABC):
self._before_subplan_execute = before_subplan_execute
self._after_subplan_execute = after_subplan_execute
self._should_skip_subplan_execute = should_skip_subplan_execute
+ self._should_suppress_subplan_start_banner = should_suppress_subplan_start_banner
for node in self.sub_plans:
node.set_runtime_callbacks(
has_tool=has_tool,
@@ -136,6 +144,7 @@ class PlanNode(ABC):
before_subplan_execute=before_subplan_execute,
after_subplan_execute=after_subplan_execute,
should_skip_subplan_execute=should_skip_subplan_execute,
+ should_suppress_subplan_start_banner=should_suppress_subplan_start_banner,
)
def log(self, level: str, message: str, *args: Any) -> None:
@@ -368,15 +377,33 @@ class PlanNode(ABC):
"resume_skip": True,
}
+ async def should_skip_subplan(
+ self,
+ subplan: "PlanNode",
+ inputs: dict[str, Any],
+ ) -> bool:
+ """HITL resume 重放时,编排层可查询是否应静默跳过该二层 stage。"""
+ if self._should_skip_subplan_execute is None:
+ return False
+ return await self._should_skip_subplan_execute(subplan, inputs)
+
+ async def should_suppress_subplan_start_banner(
+ self,
+ subplan: "PlanNode",
+ inputs: dict[str, Any],
+ ) -> bool:
+ """HITL resume 重放时,编排层可查询是否抑制「开始执行」进度横幅。"""
+ if self._should_suppress_subplan_start_banner is None:
+ return False
+ return await self._should_suppress_subplan_start_banner(subplan, inputs)
+
async def _maybe_skip_subplan_execute(
self,
subplan: "PlanNode",
inputs: dict[str, Any],
) -> dict[str, Any] | None:
"""若回调判定应跳过真实执行,触发 after 并返回 skip result;否则返回 None。"""
- if self._should_skip_subplan_execute is None:
- return None
- if not await self._should_skip_subplan_execute(subplan, inputs):
+ if not await self.should_skip_subplan(subplan, inputs):
return None
result = self._resume_skip_result(subplan)
if self._after_subplan_execute is not None:
diff --git a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_gen_root.py b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_gen_root.py
index 22f0e76bf1..c44731caf9 100644
--- a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_gen_root.py
+++ b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_gen_root.py
@@ -1,9 +1,11 @@
from __future__ import annotations
+import logging
from collections.abc import AsyncIterator
from typing import Any
-from jiuwenswarm.server.runtime.skill_turbo.plan_node import PlanNode
+from jiuwenswarm.server.runtime.skill_turbo.plan_node import AbortError, PlanNode
+
from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_common import NODE_DISPLAY_NAMES
from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.pipeline_init import PipelineInitNode
from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.intent_classify import IntentClassifyNode
@@ -20,6 +22,8 @@ from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_export import PP
from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.delivery import DeliveryNode
from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.speaker_notes import SpeakerNotesNode
+logger = logging.getLogger(__name__)
+
_P3_SKIP_MESSAGE = "未检测到待解析文档,跳过文档解析"
_P3_SKIP_FIELDS = {
"doc_parse_ok": False,
@@ -56,6 +60,20 @@ def _result_status(result: Any) -> str:
return "ok"
+def _append_subplan_step(
+ results: list[dict[str, Any]],
+ subplan: PlanNode,
+ result: Any,
+) -> None:
+ results.append(
+ {
+ "node": subplan.plan_name,
+ "status": _result_status(result),
+ "result": result,
+ }
+ )
+
+
class PPTGenRootNode(PlanNode):
# 节点显示名映射:供 Executor 读取,将内部 plan_name 转为前端展示的中文名。
display_names: dict[str, str] = NODE_DISPLAY_NAMES
@@ -102,19 +120,19 @@ class PPTGenRootNode(PlanNode):
) -> None:
result = await self.execute_subplan(subplan, inputs)
_merge_subplan_result(inputs, result)
- results.append(
- {
- "node": subplan.plan_name,
- "status": _result_status(result),
- "result": result,
- }
- )
+ _append_subplan_step(results, subplan, result)
async def _skip_p3_subplan(
self,
inputs: dict[str, Any],
results: list[dict[str, Any]],
) -> None:
+ if await self.should_skip_subplan(self._p3, inputs):
+ result = await self.execute_subplan(self._p3, inputs)
+ _merge_subplan_result(inputs, result)
+ _append_subplan_step(results, self._p3, result)
+ return
+
result = await self.skip_subplan(
self._p3,
inputs,
@@ -122,13 +140,7 @@ class PPTGenRootNode(PlanNode):
extra=_P3_SKIP_FIELDS,
)
_merge_subplan_result(inputs, result)
- results.append(
- {
- "node": self._p3.plan_name,
- "status": _result_status(result),
- "result": result,
- }
- )
+ _append_subplan_step(results, self._p3, result)
async def _run_p3_and_p2(self, inputs: dict[str, Any], results: list[dict[str, Any]]) -> None:
if inputs.get("has_documents"):
@@ -159,6 +171,44 @@ class PPTGenRootNode(PlanNode):
"steps": results,
}
+ async def _silent_resume_skip_subplan_stream(
+ self,
+ subplan: PlanNode,
+ inputs: dict[str, Any],
+ results: list[dict[str, Any]],
+ ) -> AsyncIterator[dict[str, Any]]:
+ """Resume 重放时已 completed 的 stage:不广播进度,仍走 subplan 回调链。"""
+ if self._before_subplan_execute is not None:
+ await self._before_subplan_execute(subplan, inputs)
+ skipped = await self._maybe_skip_subplan_execute(subplan, inputs)
+ if skipped is not None:
+ _merge_subplan_result(inputs, skipped)
+ _append_subplan_step(results, subplan, skipped)
+ return
+ yield # pragma: no cover - async generator marker
+
+ # should_skip_subplan 与 _maybe_skip_subplan_execute 二次判定不一致时
+ # (理论上不应发生),回退真实执行,避免 subplan 被静默丢弃。
+ logger.warning(
+ "[PPTGenRoot] resume skip disagreement for %s: "
+ "entered silent skip path but skip execute declined; falling back to run_stream",
+ subplan.plan_name,
+ )
+ last_chunk: Any = None
+ hitl_interrupt = False
+ try:
+ async for chunk in subplan.run_stream(inputs):
+ last_chunk = chunk
+ yield chunk
+ except AbortError:
+ hitl_interrupt = True
+ raise
+ finally:
+ if self._after_subplan_execute is not None and not hitl_interrupt:
+ await self._after_subplan_execute(subplan, inputs, last_chunk)
+ _merge_subplan_result(inputs, last_chunk)
+ _append_subplan_step(results, subplan, last_chunk)
+
async def _run_subplan_stream(
self,
subplan: PlanNode,
@@ -168,14 +218,22 @@ class PPTGenRootNode(PlanNode):
index: int,
total_steps: int,
) -> AsyncIterator[dict[str, Any]]:
- yield {
- "node": self.plan_name,
- "status": "progress",
- "message": f"开始执行 {subplan.plan_name}({index}/{total_steps})",
- "current_node": subplan.plan_name,
- "step": index,
- "total_steps": total_steps,
- }
+ if await self.should_skip_subplan(subplan, inputs):
+ async for chunk in self._silent_resume_skip_subplan_stream(
+ subplan, inputs, results
+ ):
+ yield chunk
+ return
+
+ if not await self.should_suppress_subplan_start_banner(subplan, inputs):
+ yield {
+ "node": self.plan_name,
+ "status": "progress",
+ "message": f"开始执行 {subplan.plan_name}({index}/{total_steps})",
+ "current_node": subplan.plan_name,
+ "step": index,
+ "total_steps": total_steps,
+ }
last_chunk: Any = None
async for chunk in self.execute_subplan_stream(subplan, inputs):
@@ -183,13 +241,7 @@ class PPTGenRootNode(PlanNode):
yield chunk
_merge_subplan_result(inputs, last_chunk)
- results.append(
- {
- "node": subplan.plan_name,
- "status": _result_status(last_chunk),
- "result": last_chunk,
- }
- )
+ _append_subplan_step(results, subplan, last_chunk)
yield {
"node": self.plan_name,
"status": "progress",
@@ -207,14 +259,22 @@ class PPTGenRootNode(PlanNode):
index: int,
total_steps: int,
) -> AsyncIterator[dict[str, Any]]:
- yield {
- "node": self.plan_name,
- "status": "progress",
- "message": f"开始执行 {self._p3.plan_name}({index}/{total_steps})",
- "current_node": self._p3.plan_name,
- "step": index,
- "total_steps": total_steps,
- }
+ if await self.should_skip_subplan(self._p3, inputs):
+ async for chunk in self._silent_resume_skip_subplan_stream(
+ self._p3, inputs, results
+ ):
+ yield chunk
+ return
+
+ if not await self.should_suppress_subplan_start_banner(self._p3, inputs):
+ yield {
+ "node": self.plan_name,
+ "status": "progress",
+ "message": f"开始执行 {self._p3.plan_name}({index}/{total_steps})",
+ "current_node": self._p3.plan_name,
+ "step": index,
+ "total_steps": total_steps,
+ }
last_chunk: Any = None
async for chunk in self.skip_subplan_stream(
@@ -227,13 +287,7 @@ class PPTGenRootNode(PlanNode):
yield chunk
_merge_subplan_result(inputs, last_chunk)
- results.append(
- {
- "node": self._p3.plan_name,
- "status": _result_status(last_chunk),
- "result": last_chunk,
- }
- )
+ _append_subplan_step(results, self._p3, last_chunk)
yield {
"node": self.plan_name,
"status": "progress",
@@ -271,11 +325,14 @@ class PPTGenRootNode(PlanNode):
results: list[dict[str, Any]] = []
total_steps = len(self.sub_plans)
- yield {
- "node": self.plan_name,
- "status": "progress",
- "message": "PPT生成任务流开始执行",
- }
+ # HITL resume 重放时首段 stage 往往已是 completed;不再广播「全流程开始」,
+ # 避免对话框重复刷 Stage 1–N 的假进度。
+ if not await self.should_skip_subplan(self._p0, inputs):
+ yield {
+ "node": self.plan_name,
+ "status": "progress",
+ "message": "PPT生成任务流开始执行",
+ }
for index, subplan in enumerate([self._p0, self._p1], start=1):
async for chunk in self._run_subplan_stream(
diff --git a/tests/unit_tests/server/runtime/skill_turbo/test_resume_skip_completed.py b/tests/unit_tests/server/runtime/skill_turbo/test_resume_skip_completed.py
index eb9eac6afa..86a86ac590 100644
--- a/tests/unit_tests/server/runtime/skill_turbo/test_resume_skip_completed.py
+++ b/tests/unit_tests/server/runtime/skill_turbo/test_resume_skip_completed.py
@@ -100,6 +100,20 @@ class TestPlanNodeResumeSkip:
assert child.run_calls == 1
assert result.get("ran") is True
+ @pytest.mark.asyncio
+ async def test_should_skip_subplan_delegates_to_callback(self):
+ parent = _LeafNode("root", depth=0)
+ child = _LeafNode("p0_pipeline_init", depth=1)
+
+ async def should_skip(_sp: PlanNode, _inp: dict[str, Any]) -> bool:
+ return _sp.plan_name == "p0_pipeline_init"
+
+ parent.set_runtime_callbacks(should_skip_subplan_execute=should_skip)
+ assert await parent.should_skip_subplan(child, {}) is True
+ assert await parent.should_skip_subplan(
+ _LeafNode("p2_requirement_collect", depth=1), {}
+ ) is False
+
def _make_executor() -> SkillTurboExecutor:
env = MagicMock()
@@ -161,6 +175,44 @@ class TestExecutorShouldSkipSubplanExecute:
assert await ex._should_skip_subplan_execute(p0, {}) is False
+class TestExecutorSuppressSubplanStartBanner:
+ @pytest.mark.asyncio
+ async def test_resume_suppresses_in_progress_only(self):
+ ex = _make_executor()
+ ex._resume_replay = True
+ ex._task_states_holder = {
+ "task_p2": {
+ "task_id": "task_p2",
+ "task_content": "p2_requirement_collect",
+ "status": "in_progress",
+ },
+ "task_p5": {
+ "task_id": "task_p5",
+ "task_content": "p3_5_template_context",
+ "status": "pending",
+ },
+ }
+ p2 = _LeafNode("p2_requirement_collect", depth=1)
+ p5 = _LeafNode("p3_5_template_context", depth=1)
+
+ assert await ex._should_suppress_subplan_start_banner(p2, {}) is True
+ assert await ex._should_suppress_subplan_start_banner(p5, {}) is False
+
+ @pytest.mark.asyncio
+ async def test_non_resume_never_suppresses(self):
+ ex = _make_executor()
+ ex._resume_replay = False
+ ex._task_states_holder = {
+ "task_p2": {
+ "task_id": "task_p2",
+ "task_content": "p2_requirement_collect",
+ "status": "in_progress",
+ },
+ }
+ p2 = _LeafNode("p2_requirement_collect", depth=1)
+ assert await ex._should_suppress_subplan_start_banner(p2, {}) is False
+
+
class TestMergeSubplanResultIgnoresSkipFields:
def test_ignores_skipped_and_resume_skip(self):
inputs: dict[str, Any] = {"query": "keep"}
@@ -178,3 +230,150 @@ class TestMergeSubplanResultIgnoresSkipFields:
assert inputs == {"query": "keep", "useful": 1}
assert "skipped" not in inputs
assert "resume_skip" not in inputs
+
+
+class TestPPTGenRootResumeProgressSilence:
+ @pytest.mark.asyncio
+ async def test_run_subplan_stream_silent_when_resume_skip(self):
+ from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_gen_root import (
+ PPTGenRootNode,
+ )
+
+ root = PPTGenRootNode()
+
+ async def should_skip(_sp: PlanNode, _inp: dict[str, Any]) -> bool:
+ return True
+
+ root.set_runtime_callbacks(should_skip_subplan_execute=should_skip)
+
+ messages: list[str] = []
+ results: list[dict[str, Any]] = []
+ async for chunk in root._run_subplan_stream(
+ root._p0, {}, results, index=1, total_steps=14
+ ):
+ msg = chunk.get("message")
+ if isinstance(msg, str) and msg.strip():
+ messages.append(msg)
+
+ assert messages == []
+ assert len(results) == 1
+ assert results[0]["node"] == "p0_pipeline_init"
+
+ @pytest.mark.asyncio
+ async def test_skip_p3_subplan_stream_silent_when_resume_skip(self):
+ from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_gen_root import (
+ PPTGenRootNode,
+ _P3_SKIP_MESSAGE,
+ )
+
+ root = PPTGenRootNode()
+
+ async def should_skip(_sp: PlanNode, _inp: dict[str, Any]) -> bool:
+ return _sp.plan_name == "p3_document_parse"
+
+ root.set_runtime_callbacks(should_skip_subplan_execute=should_skip)
+
+ messages: list[str] = []
+ results: list[dict[str, Any]] = []
+ async for chunk in root._skip_p3_subplan_stream(
+ {}, results, index=3, total_steps=14
+ ):
+ msg = chunk.get("message")
+ if isinstance(msg, str) and msg.strip():
+ messages.append(msg)
+
+ assert messages == []
+ assert _P3_SKIP_MESSAGE not in messages
+ assert len(results) == 1
+ assert results[0]["node"] == "p3_document_parse"
+
+ @pytest.mark.asyncio
+ async def test_execute_stream_omits_root_banner_on_resume(self):
+ from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_gen_root import (
+ PPTGenRootNode,
+ )
+
+ root = PPTGenRootNode()
+
+ async def should_skip(sp: PlanNode, _inp: dict[str, Any]) -> bool:
+ return sp.plan_name == "p0_pipeline_init"
+
+ root.set_runtime_callbacks(should_skip_subplan_execute=should_skip)
+
+ # p0 静默跳过后,首条可见消息不应是根节点 banner(即便后续 stage 仍会正常广播)。
+ collected: list[str] = []
+ gen = root._execute_stream({"has_documents": False})
+ try:
+ async for chunk in gen:
+ msg = chunk.get("message")
+ if isinstance(msg, str) and msg.strip():
+ collected.append(msg)
+ if collected:
+ break
+ finally:
+ await gen.aclose()
+
+ assert "PPT生成任务流开始执行" not in collected
+
+ @pytest.mark.asyncio
+ async def test_run_subplan_stream_omits_start_banner_for_in_progress_resume(self):
+ from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_gen_root import (
+ PPTGenRootNode,
+ )
+
+ root = PPTGenRootNode()
+ child = _LeafNode("p2_requirement_collect", depth=1)
+
+ async def should_skip(_sp: PlanNode, _inp: dict[str, Any]) -> bool:
+ return False
+
+ async def suppress_start(_sp: PlanNode, _inp: dict[str, Any]) -> bool:
+ return _sp.plan_name == "p2_requirement_collect"
+
+ root.set_runtime_callbacks(
+ should_skip_subplan_execute=should_skip,
+ should_suppress_subplan_start_banner=suppress_start,
+ )
+
+ messages: list[str] = []
+ results: list[dict[str, Any]] = []
+ async for chunk in root._run_subplan_stream(
+ child, {}, results, index=4, total_steps=14
+ ):
+ msg = chunk.get("message")
+ if isinstance(msg, str) and msg.strip():
+ messages.append(msg)
+
+ assert not any(msg.startswith("开始执行") for msg in messages)
+ assert child.run_stream_calls == 1
+ assert any(msg.startswith("完成执行") for msg in messages)
+
+ @pytest.mark.asyncio
+ async def test_silent_resume_skip_falls_back_when_skip_disagrees(self):
+ from jiuwenswarm.server.runtime.skill_turbo.skill_codes.ppt.ppt_gen_root import (
+ PPTGenRootNode,
+ )
+
+ root = PPTGenRootNode()
+ child = _LeafNode("p0_pipeline_init", depth=1)
+ calls = {"n": 0}
+
+ async def flaky_should_skip(_sp: PlanNode, _inp: dict[str, Any]) -> bool:
+ calls["n"] += 1
+ return calls["n"] == 1
+
+ root.set_runtime_callbacks(should_skip_subplan_execute=flaky_should_skip)
+
+ results: list[dict[str, Any]] = []
+ chunks = [
+ c
+ async for c in root._run_subplan_stream(
+ child, {}, results, index=1, total_steps=14
+ )
+ ]
+
+ assert calls["n"] == 2
+ assert child.run_stream_calls == 1
+ assert len(results) == 1
+ assert results[0]["result"].get("ran") is True
+ assert chunks == [{"node": "p0_pipeline_init", "status": "ok", "ran": True}]