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(evolution): hide status before evolution signal is detected
z2tngd10d8c1c9852
diff --git a/jiuwenswarm/channels/web/frontend/src/components/ChatPanel/evolution-status.ts b/jiuwenswarm/channels/web/frontend/src/components/ChatPanel/evolution-status.tsindex d5f68fd8d4..e1286c8ba6 100644--- a/jiuwenswarm/channels/web/frontend/src/components/ChatPanel/evolution-status.ts+++ b/jiuwenswarm/channels/web/frontend/src/components/ChatPanel/evolution-status.ts@@ -4,12 +4,20 @@ import type { EvolutionStatusPayload } from '../../types/websocket.ts';type Translate = (key: string) => string;const STAGE_KEY_MAP: Record<string, string> = {+ started: 'statusBar.evolutionStages.detecting',collecting: 'statusBar.evolutionStages.collecting',detecting: 'statusBar.evolutionStages.detecting',+ detecting_signals: 'statusBar.evolutionStages.detecting',generating: 'statusBar.evolutionStages.generating',+ generating_updates: 'statusBar.evolutionStages.generating',+ staging: 'statusBar.evolutionStages.generating',awaiting_approval: 'statusBar.evolutionStages.awaitingApproval',approval_required: 'statusBar.evolutionStages.awaitingApproval',+ auto_approved: 'statusBar.evolutionStages.completed',no_evolution_generated: 'statusBar.evolutionStages.noEvolutionGenerated',+ no_evolution_no_skill: 'statusBar.evolutionStages.noEvolutionNoSkill',+ no_evolution_no_signal: 'statusBar.evolutionStages.noEvolutionNoSignal',+ no_evolution_no_records: 'statusBar.evolutionStages.noEvolutionNoRecords',completed: 'statusBar.evolutionStages.completed',timed_out: 'statusBar.evolutionStages.timedOut',failed: 'statusBar.evolutionStages.failed',@@ -25,7 +33,7 @@ export function getEvolutionPillLabel(}const stage = (evolutionStatus.stage || '').trim().toLowerCase();- if (stage === 'hidden' || (mode !== 'team' && stage === 'failed')) {+ if (stage === 'hidden' || stage === 'cancelled' || (mode !== 'team' && stage === 'failed')) {return null;}const translationKey = STAGE_KEY_MAP[stage];diff --git a/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json b/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.jsonindex 18a36f1861..b5bb44dfd6 100644--- a/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json+++ b/jiuwenswarm/channels/web/frontend/src/i18n/locales/en.json@@ -74,13 +74,16 @@"pause": "Pause","resume": "Resume","processing": "Processing...",- "evolving": "Background skill evolution in progress...",+ "evolving": "Checking whether skill evolution is needed...","evolutionStages": {- "collecting": "Background skill evolution in progress...",- "detecting": "Detecting evolution signals...",- "generating": "Generating evolution experience...",+ "collecting": "Preparing skill evolution check...",+ "detecting": "Checking whether skill evolution is needed...",+ "generating": "Signal detected, generating evolution experience...","awaitingApproval": "Evolution proposal ready, awaiting approval...","noEvolutionGenerated": "No evolution generated",+ "noEvolutionNoSkill": "No evolution generated: no related skill found",+ "noEvolutionNoSignal": "No evolution generated: no durable improvement found",+ "noEvolutionNoRecords": "No evolution generated: no savable experience produced","completed": "Skill evolution completed","timedOut": "Skill evolution timed out","failed": "Skill evolution failed"diff --git a/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json b/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.jsonindex 4ef4f323c3..894f5491af 100644--- a/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json+++ b/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json@@ -74,13 +74,16 @@"pause": "暂停","resume": "恢复","processing": "处理中...",- "evolving": "后台技能演进中...",+ "evolving": "正在检测是否需要技能演进...","evolutionStages": {- "collecting": "后台技能演进中...",- "detecting": "正在检测演进信号...",- "generating": "正在生成演进经验...",+ "collecting": "正在准备技能演进检测...",+ "detecting": "正在检测是否需要技能演进...",+ "generating": "检测到信号,正在生成演进经验...","awaitingApproval": "演进经验已生成,等待审批...","noEvolutionGenerated": "无演进生成",+ "noEvolutionNoSkill": "未生成演进经验:未识别到相关技能",+ "noEvolutionNoSignal": "未生成演进经验:未发现可沉淀的改进点",+ "noEvolutionNoRecords": "未生成演进经验:未生成可保存的经验","completed": "技能演进已完成","timedOut": "技能演进已超时","failed": "技能演进失败"diff --git a/jiuwenswarm/server/runtime/agent_adapter/evolution_helpers.py b/jiuwenswarm/server/runtime/agent_adapter/evolution_helpers.pyindex c52fd615e0..255793294a 100644--- a/jiuwenswarm/server/runtime/agent_adapter/evolution_helpers.py+++ b/jiuwenswarm/server/runtime/agent_adapter/evolution_helpers.py@@ -15,12 +15,38 @@ TEAM_EVOLUTION_EVENT_TIMEOUT_SEC = 900.0TEAM_EVOLUTION_START_STAGE = "collecting"TEAM_EVOLUTION_START_MESSAGE = "Running team skill evolution analysis..."TEAM_EVOLUTION_NOOP_STAGE = "no_evolution_generated"+TEAM_EVOLUTION_NOOP_NO_SKILL_STAGE = "no_evolution_no_skill"+TEAM_EVOLUTION_NOOP_NO_SIGNAL_STAGE = "no_evolution_no_signal"+TEAM_EVOLUTION_NOOP_NO_RECORDS_STAGE = "no_evolution_no_records"TEAM_EVOLUTION_HIDDEN_STAGE = "hidden"TEAM_EVOLUTION_NOOP_MARKERS = ("no existing skill found","no evolution signals detected","no evolution records generated",)+TEAM_EVOLUTION_NO_SKILL_MARKERS = (+ "no skill usage",+ "no existing skill",+ "no regular skill could be attributed",+ "no team/swarm skill",+)+TEAM_EVOLUTION_NO_SIGNAL_MARKERS = (+ "no actionable evolution signals detected",+ "no evolution signals detected",+)+TEAM_EVOLUTION_NOOP_STAGES = {+ TEAM_EVOLUTION_NOOP_STAGE,+ TEAM_EVOLUTION_NOOP_NO_SKILL_STAGE,+ TEAM_EVOLUTION_NOOP_NO_SIGNAL_STAGE,+ TEAM_EVOLUTION_NOOP_NO_RECORDS_STAGE,+}+TEAM_EVOLUTION_HIDDEN_TERMINAL_STAGES = {TEAM_EVOLUTION_HIDDEN_STAGE, "failed", "timed_out"}+TEAM_EVOLUTION_VISIBLE_PROGRESS_STAGES = {+ "generating",+ "approval_required",+ "completed",+ *TEAM_EVOLUTION_NOOP_STAGES,+}@dataclass(frozen=True)@@ -38,6 +64,36 @@ class EvolutionStatusUpdate:message: str = ""+@dataclass(frozen=True)+class EvolutionProgressStatus:+ stage: str+ message: str = ""+ request_id: str | None = None+ terminal: bool = False+++_SDK_PROGRESS_STAGE_MAP = {+ "started": "detecting",+ "detecting_signals": "detecting",+ "staging": "generating",+ "generating_updates": "generating",+ "approval_required": "approval_required",+ "auto_approved": "completed",+ "cancelled": TEAM_EVOLUTION_HIDDEN_STAGE,+ "completed": "completed",+ "failed": "failed",+ "timed_out": "timed_out",+}++_SDK_PROGRESS_TERMINAL_STAGES = {+ "auto_approved",+ "cancelled",+ "completed",+ "failed",+ "timed_out",+}++def event_payload_dict(evt: Any) -> dict[str, Any]:if hasattr(evt, "payload") and isinstance(evt.payload, dict):return dict(evt.payload)@@ -84,7 +140,10 @@ def evolution_outcome_from_event(evt: Any) -> dict[str, str]:return {"status": "completed", "message": str(payload)}meta = payload.get("_evolution_meta")meta_status = meta.get("status") if isinstance(meta, dict) else None- status = str(payload.get("status") or meta_status or "completed").strip().lower() or "completed"+ status = (+ str(payload.get("status") or meta_status or "completed").strip().lower()+ or "completed"+ )message = str(payload.get("message") or payload.get("content") or "")return {"status": status, "message": message}@@ -92,36 +151,124 @@ def evolution_outcome_from_event(evt: Any) -> dict[str, str]:def extract_evolution_request_id(evt: Any) -> str | None:payload = event_payload_dict(evt)request_id = payload.get("request_id")+ if not request_id:+ meta = payload.get("_evolution_meta")+ if isinstance(meta, dict):+ request_id = meta.get("request_id")if isinstance(request_id, str):request_id = request_id.strip()return request_id or None-def is_evolution_started_progress(evt: Any) -> bool:+def evolution_progress_status_from_event(evt: Any) -> EvolutionProgressStatus | None:payload = event_payload_dict(evt)meta = payload.get("_evolution_meta")if not isinstance(meta, dict):- return False+ return Noneevent_kind = str(meta.get("event_kind") or "").strip().lower()- stage = str(payload.get("stage") or meta.get("stage") or "").strip().lower()- return event_kind == "progress" and stage == "started"+ if event_kind != "progress":+ return None+ raw_stage = str(payload.get("stage") or meta.get("stage") or "").strip().lower()+ if not raw_stage:+ return None+ message = str(payload.get("message") or payload.get("content") or "").strip()+ noop_stage = _noop_stage_from_message(message.lower())+ stage = (+ noop_stage+ if raw_stage != "cancelled" and noop_stage is not None+ else _SDK_PROGRESS_STAGE_MAP.get(raw_stage, raw_stage)+ )+ return EvolutionProgressStatus(+ stage=stage,+ message=message,+ request_id=extract_evolution_request_id(evt),+ terminal=raw_stage in _SDK_PROGRESS_TERMINAL_STAGES,+ )+++def visible_evolution_progress_from_events(events: list[Any]) -> list[EvolutionProgressStatus]:+ return [+ progress+ for progress in (evolution_progress_status_from_event(evt) for evt in events)+ if progress is not None and progress.stage in TEAM_EVOLUTION_VISIBLE_PROGRESS_STAGES+ ]+++def progress_for_request(+ progress_statuses: list[EvolutionProgressStatus],+ request_id: str,+) -> list[EvolutionProgressStatus]:+ return [+ progress+ for progress in progress_statuses+ if progress.request_id is None or progress.request_id == request_id+ ]+++def terminal_stage(terminal: dict[str, str]) -> str:+ return str(terminal.get("stage") or terminal.get("status") or "").strip().lower()+++def terminal_progress_from_events(events: list[Any]) -> list[tuple[str | None, dict[str, str]]]:+ terminal_progress: list[tuple[str | None, dict[str, str]]] = []+ for evt in events:+ terminal = team_evolution_terminal_progress(evt)+ if terminal is not None:+ terminal_progress.append((extract_evolution_request_id(evt), terminal))+ return terminal_progress+++def _noop_stage_from_message(message_lower: str) -> str | None:+ if any(marker in message_lower for marker in TEAM_EVOLUTION_NO_SKILL_MARKERS):+ return TEAM_EVOLUTION_NOOP_NO_SKILL_STAGE+ if any(marker in message_lower for marker in TEAM_EVOLUTION_NO_SIGNAL_MARKERS):+ return TEAM_EVOLUTION_NOOP_NO_SIGNAL_STAGE+ if "no evolution records generated" in message_lower:+ return TEAM_EVOLUTION_NOOP_NO_RECORDS_STAGE+ if any(marker in message_lower for marker in TEAM_EVOLUTION_NOOP_MARKERS):+ return TEAM_EVOLUTION_NOOP_STAGE+ return Nonedef team_evolution_terminal_progress(evt: Any) -> dict[str, str] | None:payload = event_payload_dict(evt)- meta = payload.get("_evolution_meta")- meta_status = meta.get("status") if isinstance(meta, dict) else None- meta_stage = meta.get("stage") if isinstance(meta, dict) else None- status = str(payload.get("status") or meta_status or "").strip().lower()- stage = str(payload.get("stage") or meta_stage or "").strip().lower()+ progress = evolution_progress_status_from_event(evt)+ if (+ progress is not None+ and progress.terminal+ and progress.stage == TEAM_EVOLUTION_HIDDEN_STAGE+ ):+ return {+ "status": progress.stage,+ "stage": progress.stage,+ "message": progress.message,+ }message = str(payload.get("message") or payload.get("content") or "")message_lower = message.lower()- if any(marker in message_lower for marker in TEAM_EVOLUTION_NOOP_MARKERS):+ noop_stage = _noop_stage_from_message(message_lower)+ if noop_stage is not None:return {"status": "completed",- "stage": TEAM_EVOLUTION_NOOP_STAGE,+ "stage": noop_stage,"message": message or "No evolution generated",}+ if progress is not None and progress.terminal:+ if progress.stage == TEAM_EVOLUTION_NOOP_STAGE:+ return {+ "status": "completed",+ "stage": TEAM_EVOLUTION_NOOP_STAGE,+ "message": progress.message or "No evolution generated",+ }+ return {+ "status": progress.stage,+ "stage": progress.stage,+ "message": progress.message,+ }+ meta = payload.get("_evolution_meta")+ meta_status = meta.get("status") if isinstance(meta, dict) else None+ meta_stage = meta.get("stage") if isinstance(meta, dict) else None+ status = str(payload.get("status") or meta_status or "").strip().lower()+ stage = str(payload.get("stage") or meta_stage or "").strip().lower()if status == "end" or stage in {"completed", "failed", "timed_out"}:return {"status": status or "end",@@ -165,7 +312,7 @@ def team_evolution_end_update(stage=TEAM_EVOLUTION_HIDDEN_STAGE,message=message,)- if stage == TEAM_EVOLUTION_NOOP_STAGE:+ if stage in TEAM_EVOLUTION_NOOP_STAGES:return build_evolution_status_update(request_id=request_id,status="end",diff --git a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.pyindex ee620ad70b..2cdfff7f77 100644--- a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py+++ b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py@@ -134,6 +134,7 @@ from jiuwenswarm.server.runtime.skill.skill_manager import SkillManagerfrom jiuwenswarm.server.runtime.agent_adapter.evolution_helpers import (EvolutionPushContext,TEAM_EVOLUTION_EVENT_TIMEOUT_SEC,+ TEAM_EVOLUTION_HIDDEN_TERMINAL_STAGES,TEAM_EVOLUTION_IDLE_SLEEP_SEC,build_evolution_status_update,evolution_outcome_from_event,@@ -143,6 +144,8 @@ from jiuwenswarm.server.runtime.agent_adapter.evolution_helpers import (push_evolution_progress,push_evolution_status,team_evolution_terminal_progress,+ terminal_stage,+ visible_evolution_progress_from_events,)from jiuwenswarm.agents.harness.common.tools.multimodal_config import (apply_audio_model_config_from_yaml,@@ -5434,14 +5437,15 @@ class JiuWenClawDeepAdapter:if not getattr(self._skill_evolution_rail, "auto_scan", True):return- await _push_status("start", "collecting", "Running evolution analysis...")+ active = Falselast_event_at = time.monotonic()while True:if self._skill_evolution_rail is None:returnif not getattr(self._skill_evolution_rail, "auto_scan", True):- await _push_status("end", "hidden", "")+ if active:+ await _push_status("end", "hidden", "")await _cleanup_rail()return@@ -5449,10 +5453,6 @@ class JiuWenClawDeepAdapter:if not events:idle_for = time.monotonic() - last_event_atif idle_for >= TEAM_EVOLUTION_EVENT_TIMEOUT_SEC:- message = (- f"Evolution analysis timed out after "- f"{TEAM_EVOLUTION_EVENT_TIMEOUT_SEC:.0f}s without host events"- )logger.warning("[JiuWenClawDeepAdapter] evolution watcher timed out: ""request_id=%s session_id=%s idle_for=%.1fs",@@ -5460,13 +5460,27 @@ class JiuWenClawDeepAdapter:session_id,idle_for,)- await _push_status("end", "hidden", message)+ if active:+ message = (+ f"Evolution analysis timed out after "+ f"{TEAM_EVOLUTION_EVENT_TIMEOUT_SEC:.0f}s without host events"+ )+ await _push_status("end", "hidden", message)await _cleanup_rail()returnawait asyncio.sleep(TEAM_EVOLUTION_IDLE_SLEEP_SEC)continuelast_event_at = time.monotonic()+ visible_progress_statuses = visible_evolution_progress_from_events(events)+ just_started = False+ if not active and visible_progress_statuses:+ start_stage = visible_progress_statuses[0].stage+ start_message = visible_progress_statuses[0].message+ await _push_status("start", start_stage, start_message)+ active = True+ just_started = True+await push_evolution_progress(push_context,rid,@@ -5475,8 +5489,21 @@ class JiuWenClawDeepAdapter:build_push_message=build_server_push_message,)+ progress_statuses_to_push = (+ visible_progress_statuses[1:]+ if just_started+ else visible_progress_statuses+ )+ for progress_status in progress_statuses_to_push:+ if progress_status.terminal:+ continue+ await _push_status("progress", progress_status.stage, progress_status.message)+approval_events = [evt for evt in events if is_evolution_approval_event(evt)]if approval_events:+ if not active:+ await _push_status("start", "approval_required", "")+ active = Truefor evt in approval_events:await _push_approval(evt)await _push_status("end", "approval_required", "")@@ -5489,6 +5516,9 @@ class JiuWenClawDeepAdapter:if is_evolution_outcome_event(evt)]if outcomes:+ if not active:+ await _cleanup_rail()+ returnoutcome = outcomes[-1]stage = str(outcome.get("status") or "completed").strip().lower()message = str(outcome.get("message") or "")@@ -5510,12 +5540,22 @@ class JiuWenClawDeepAdapter:]if terminal_progress:terminal = terminal_progress[-1]- terminal_stage = str(terminal.get("stage") or "no_evolution_generated")- if terminal_stage in {"failed", "timed_out"}:- terminal_stage = "hidden"+ end_stage = terminal_stage(terminal) or "no_evolution_generated"+ if end_stage in TEAM_EVOLUTION_HIDDEN_TERMINAL_STAGES:+ end_stage = "hidden"+ if not active and end_stage == "hidden":+ await _cleanup_rail()+ return+ if not active:+ await _push_status(+ "start",+ end_stage,+ str(terminal.get("message") or ""),+ )+ active = Trueawait _push_status("end",- terminal_stage,+ end_stage,str(terminal.get("message") or ""),)await _cleanup_rail()diff --git a/jiuwenswarm/server/runtime/agent_adapter/team_helpers.py b/jiuwenswarm/server/runtime/agent_adapter/team_helpers.pyindex 9dec6b89b3..ec7ea8b546 100644--- a/jiuwenswarm/server/runtime/agent_adapter/team_helpers.py+++ b/jiuwenswarm/server/runtime/agent_adapter/team_helpers.py@@ -24,8 +24,10 @@ from jiuwenswarm.agents.harness.team.monitor_handler import TeamMonitorHandlerfrom jiuwenswarm.server.utils.stream_utils import parse_stream_chunkfrom jiuwenswarm.common.schema.agent import AgentResponseChunkfrom jiuwenswarm.server.runtime.agent_adapter.evolution_helpers import (+ EvolutionProgressStatus,EvolutionPushContext,TEAM_EVOLUTION_EVENT_TIMEOUT_SEC,+ TEAM_EVOLUTION_HIDDEN_TERMINAL_STAGES,TEAM_EVOLUTION_HIDDEN_STAGE,TEAM_EVOLUTION_IDLE_SLEEP_SEC,TEAM_EVOLUTION_START_MESSAGE,@@ -34,15 +36,18 @@ from jiuwenswarm.server.runtime.agent_adapter.evolution_helpers import (build_evolution_status_update,event_type,evolution_outcome_from_event,+ evolution_progress_status_from_event,extract_evolution_request_id,group_evolution_approvals,- is_evolution_started_progress,is_evolution_outcome_event,make_team_evolution_cycle_request_id,+ progress_for_request,push_evolution_event,push_evolution_status,team_evolution_end_update,- team_evolution_terminal_progress,+ terminal_progress_from_events,+ terminal_stage,+ visible_evolution_progress_from_events,)logger = logging.getLogger(__name__)@@ -985,6 +990,30 @@ async def _watch_team_evolution_and_push(exc,)+ async def _push_cycle_start(+ request_id: str,+ progress_statuses: list[EvolutionProgressStatus],+ ) -> bool:+ if request_id in closed_request_ids:+ return False+ request_progress = progress_for_request(progress_statuses, request_id)+ first_progress = request_progress[0] if request_progress else None+ await push_evolution_status(+ push_context,+ build_evolution_status_update(+ request_id=request_id,+ status="start",+ stage=first_progress.stage if first_progress else TEAM_EVOLUTION_START_STAGE,+ message=(+ first_progress.message+ if first_progress+ else TEAM_EVOLUTION_START_MESSAGE+ ),+ ),+ build_server_push_message,+ )+ return True+try:last_event_at = time.monotonic()while True:@@ -1048,23 +1077,50 @@ async def _watch_team_evolution_and_push(for evt in eventsif is_evolution_outcome_event(evt)]- terminal_progress = []- for evt in events:- terminal = team_evolution_terminal_progress(evt)- if terminal is not None:- terminal_progress.append(terminal)+ terminal_progress = terminal_progress_from_events(events)+ visible_progress_statuses = visible_evolution_progress_from_events(events)+ just_started = Falseif active_cycle_request_id is None:first_request_id = next(iter(grouped_approvals), None)if first_request_id is None:- first_request_id = None+ for progress_status in visible_progress_statuses:+ if progress_status.request_id:+ first_request_id = progress_status.request_id+ break+ if first_request_id is None:for evt in events:+ if evolution_progress_status_from_event(evt) is not None:+ continuerequest_id = extract_evolution_request_id(evt)if request_id:first_request_id = request_idbreakif first_request_id is None:- if any(is_evolution_started_progress(evt) for evt in events):+ for terminal_request_id, terminal in terminal_progress:+ if (+ terminal_request_id+ or terminal_stage(terminal)+ not in TEAM_EVOLUTION_HIDDEN_TERMINAL_STAGES+ ):+ first_request_id = terminal_request_id+ break+ if first_request_id is None:+ if any(+ progress_status.request_id is None+ for progress_status in visible_progress_statuses+ ):+ fallback_cycle_index += 1+ first_request_id = make_team_evolution_cycle_request_id(+ session_id,+ fallback_cycle_index,+ )+ elif any(+ terminal_request_id is None+ and terminal_stage(terminal)+ not in TEAM_EVOLUTION_HIDDEN_TERMINAL_STAGES+ for terminal_request_id, terminal in terminal_progress+ ):fallback_cycle_index += 1first_request_id = make_team_evolution_cycle_request_id(session_id,@@ -1072,37 +1128,43 @@ async def _watch_team_evolution_and_push()else:continue- if first_request_id not in closed_request_ids:+ if await _push_cycle_start(first_request_id, visible_progress_statuses):active_cycle_request_id = first_request_id- await push_evolution_status(- push_context,- build_evolution_status_update(- request_id=active_cycle_request_id,- status="start",- stage=TEAM_EVOLUTION_START_STAGE,- message=TEAM_EVOLUTION_START_MESSAGE,- ),- build_server_push_message,- )+ just_started = Trueif active_cycle_request_id is None:continue+ active_progress_statuses = progress_for_request(+ visible_progress_statuses,+ active_cycle_request_id,+ )+ progress_statuses_to_push = (+ active_progress_statuses[1:]+ if just_started+ else active_progress_statuses+ )+ for progress_status in progress_statuses_to_push:+ if progress_status.terminal:+ continue+ await push_evolution_status(+ push_context,+ build_evolution_status_update(+ request_id=active_cycle_request_id,+ status="progress",+ stage=progress_status.stage,+ message=progress_status.message,+ ),+ build_server_push_message,+ )+for request_id, approval_events in grouped_approvals.items():if request_id in closed_request_ids:continueif active_cycle_request_id != request_id:+ if not await _push_cycle_start(request_id, visible_progress_statuses):+ continueactive_cycle_request_id = request_id- await push_evolution_status(- push_context,- build_evolution_status_update(- request_id=active_cycle_request_id,- status="start",- stage=TEAM_EVOLUTION_START_STAGE,- message=TEAM_EVOLUTION_START_MESSAGE,- ),- build_server_push_message,- )if request_id in seen_request_ids:logger.debug("[TeamHelpers] skip duplicated team evolution approval batch: session_id=%s request_id=%s",@@ -1148,7 +1210,15 @@ async def _watch_team_evolution_and_push("message": str(outcome.get("message") or ""),}elif terminal_progress:- terminal = terminal_progress[-1]+ for terminal_request_id, candidate_terminal in terminal_progress:+ if active_cycle_request_id is None:+ continue+ if (+ terminal_request_id is not None+ and terminal_request_id != active_cycle_request_id+ ):+ continue+ terminal = candidate_terminalif terminal is not None and active_cycle_request_id is not None:await push_evolution_status(diff --git a/tests/unit_tests/agentserver/test_evolution_helpers.py b/tests/unit_tests/agentserver/test_evolution_helpers.pyindex 6ca4a4fbac..0215de9d46 100644--- a/tests/unit_tests/agentserver/test_evolution_helpers.py+++ b/tests/unit_tests/agentserver/test_evolution_helpers.py@@ -32,6 +32,62 @@ def test_evolution_helpers_parse_approval_and_outcome_events():assert evolution_helpers.extract_evolution_request_id(approval) == "team_skill_evolve_req1"+def test_evolution_helpers_extract_request_id_from_evolution_meta():+ progress = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {+ "event_kind": "progress",+ "stage": "generating_updates",+ "request_id": "team_skill_evolve_meta",+ },+ "content": "[Team Skill Evolution] generating",+ },+ )++ assert evolution_helpers.extract_evolution_request_id(progress) == "team_skill_evolve_meta"+++ ("raw_stage", "expected_stage", "expected_terminal"),+ [+ ("started", "detecting", False),+ ("detecting_signals", "detecting", False),+ ("staging", "generating", False),+ ("generating_updates", "generating", False),+ ("approval_required", "approval_required", False),+ ("auto_approved", "completed", True),+ ("cancelled", "hidden", True),+ ("completed", "completed", True),+ ("failed", "failed", True),+ ],+)+def test_evolution_helpers_normalize_sdk_progress_stages(+ raw_stage: str,+ expected_stage: str,+ expected_terminal: bool,+):+ progress = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {+ "event_kind": "progress",+ "stage": raw_stage,+ "request_id": "skill_evolve_req1",+ },+ "content": f"[Skill Evolution] {raw_stage}",+ },+ )++ status = evolution_helpers.evolution_progress_status_from_event(progress)++ assert status is not None+ assert status.stage == expected_stage+ assert status.message == f"[Skill Evolution] {raw_stage}"+ assert status.request_id == "skill_evolve_req1"+ assert status.terminal is expected_terminal++@pytest.mark.parametrize("stage", ["failed", "timed_out"])def test_evolution_helpers_hide_failed_and_timed_out_team_status_updates(stage: str):update = evolution_helpers.team_evolution_end_update(@@ -62,14 +118,64 @@ def test_evolution_helpers_map_noop_progress_to_no_evolution_generated():assert terminal == {"status": "completed",- "stage": "no_evolution_generated",+ "stage": "no_evolution_no_signal","message": "No evolution signals detected",}assert update.status == "end"- assert update.stage == "no_evolution_generated"+ assert update.stage == "no_evolution_no_signal"assert update.message == "No evolution signals detected"+ ("content", "expected_stage"),+ [+ ("no skill usage of a regular skill detected", "no_evolution_no_skill"),+ ("no actionable evolution signals detected", "no_evolution_no_signal"),+ ("no evolution records generated", "no_evolution_no_records"),+ ],+)+def test_evolution_helpers_map_noop_reasons_to_specific_stages(+ content: str,+ expected_stage: str,+):+ progress = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {"event_kind": "progress", "stage": "completed"},+ "content": content,+ },+ )++ terminal = evolution_helpers.team_evolution_terminal_progress(progress)++ assert terminal is not None+ assert terminal["stage"] == expected_stage+++def test_evolution_helpers_map_cancelled_progress_to_hidden():+ progress = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {"event_kind": "progress", "stage": "cancelled"},+ "content": "no skill usage of a regular skill detected",+ },+ )++ terminal = evolution_helpers.team_evolution_terminal_progress(progress)+ update = evolution_helpers.team_evolution_end_update(+ "skill_evolve_req1",+ terminal,+ )++ assert terminal == {+ "status": "hidden",+ "stage": "hidden",+ "message": "no skill usage of a regular skill detected",+ }+ assert update.status == "end"+ assert update.stage == "hidden"++def test_evolution_helpers_group_approvals_skips_missing_request_ids():missing_request_id = SimpleNamespace(type="chat.ask_user_question",diff --git a/tests/unit_tests/agentserver/test_evolution_push_delivery.py b/tests/unit_tests/agentserver/test_evolution_push_delivery.pyindex 518f17908d..c0a19a08cd 100644--- a/tests/unit_tests/agentserver/test_evolution_push_delivery.py+++ b/tests/unit_tests/agentserver/test_evolution_push_delivery.py@@ -145,6 +145,109 @@ async def test_normal_evolution_watcher_uses_delivery_context_metadata(monkeypat)+async def test_normal_evolution_watcher_does_not_push_status_without_sdk_events(monkeypatch):+ _FakeTransport.pushes = []+ rail = _FakeEvolutionRail([])+ adapter = _TestAdapter.build_with_rail(rail)++ monkeypatch.setattr(+ "jiuwenclaw.server.gateway_push.WebSocketGatewayPushTransport",+ _FakeTransport,+ )+ monkeypatch.setattr(interface_deep_module, "TEAM_EVOLUTION_IDLE_SLEEP_SEC", 0.001)+ monkeypatch.setattr(interface_deep_module, "TEAM_EVOLUTION_EVENT_TIMEOUT_SEC", 0.01)++ await adapter.watch_evolution_and_push("stream-rid", "web", "sess-no-events")++ assert _FakeTransport.pushes == []+ assert rail.drain_waits+ assert rail.cleanup_calls == 1+++async def test_normal_evolution_watcher_maps_sdk_progress_stages(monkeypatch):+ _FakeTransport.pushes = []+ rail = _FakeEvolutionRail(+ [+ [_progress_event("detecting", stage="detecting_signals")],+ [_progress_event("generating", stage="generating_updates")],+ [_outcome_event("completed", "done")],+ ]+ )+ adapter = _TestAdapter.build_with_rail(rail)++ monkeypatch.setattr(+ "jiuwenclaw.server.gateway_push.WebSocketGatewayPushTransport",+ _FakeTransport,+ )++ await adapter.watch_evolution_and_push("stream-rid", "web", "sess-sdk-stages")++ status_pushes = [+ push for push in _FakeTransport.pushes+ if push["payload"]["event_type"] == "chat.evolution_status"+ ]+ assert [push["payload"]["status"] for push in status_pushes] == [+ "start",+ "end",+ ]+ assert [push["payload"]["stage"] for push in status_pushes] == [+ "generating",+ "completed",+ ]+++async def test_normal_evolution_watcher_ends_on_cancelled_progress(monkeypatch):+ _FakeTransport.pushes = []+ rail = _FakeEvolutionRail([[_progress_event("no skill usage detected", stage="cancelled")]])+ adapter = _TestAdapter.build_with_rail(rail)++ monkeypatch.setattr(+ "jiuwenclaw.server.gateway_push.WebSocketGatewayPushTransport",+ _FakeTransport,+ )+ monkeypatch.setattr(interface_deep_module, "TEAM_EVOLUTION_IDLE_SLEEP_SEC", 0.001)+ monkeypatch.setattr(interface_deep_module, "TEAM_EVOLUTION_EVENT_TIMEOUT_SEC", 0.01)++ await adapter.watch_evolution_and_push("stream-rid", "web", "sess-sdk-cancelled")++ status_pushes = [+ push for push in _FakeTransport.pushes+ if push["payload"]["event_type"] == "chat.evolution_status"+ ]+ assert status_pushes == []+ assert rail.cleanup_calls == 1+++async def test_normal_evolution_watcher_ends_on_auto_approved_progress(monkeypatch):+ _FakeTransport.pushes = []+ rail = _FakeEvolutionRail([[_progress_event("auto saved", stage="auto_approved")]])+ adapter = _TestAdapter.build_with_rail(rail)++ monkeypatch.setattr(+ "jiuwenclaw.server.gateway_push.WebSocketGatewayPushTransport",+ _FakeTransport,+ )+ monkeypatch.setattr(interface_deep_module, "TEAM_EVOLUTION_IDLE_SLEEP_SEC", 0.001)+ monkeypatch.setattr(interface_deep_module, "TEAM_EVOLUTION_EVENT_TIMEOUT_SEC", 0.01)++ await adapter.watch_evolution_and_push("stream-rid", "web", "sess-sdk-auto")++ status_pushes = [+ push for push in _FakeTransport.pushes+ if push["payload"]["event_type"] == "chat.evolution_status"+ ]+ assert [push["payload"]["status"] for push in status_pushes] == ["start", "end"]+ assert [push["payload"]["stage"] for push in status_pushes] == [+ "completed",+ "completed",+ ]+ assert rail.cleanup_calls == 1++@pytest.mark.asyncioasync def test_normal_evolution_watcher_reads_outcome_status_from_metadata(monkeypatch):_FakeTransport.pushes = []@@ -163,8 +266,7 @@ async def test_normal_evolution_watcher_reads_outcome_status_from_metadata(monkepush for push in _FakeTransport.pushesif push["payload"]["event_type"] == "chat.evolution_status"]- assert [push["payload"]["status"] for push in status_pushes] == ["start", "end"]- assert status_pushes[-1]["payload"]["stage"] == "hidden"+ assert status_pushes == []@pytest.mark.asyncio@@ -187,13 +289,14 @@ async def test_normal_evolution_watcher_pushes_passive_progress_before_approval(event_types = [push["payload"]["event_type"] for push in _FakeTransport.pushes]assert event_types == [- "chat.evolution_status","chat.reasoning",+ "chat.evolution_status","chat.ask_user_question","chat.evolution_status",]- assert _FakeTransport.pushes[0]["payload"]["status"] == "start"- assert _FakeTransport.pushes[1]["payload"]["content"] == "evolution progress"+ assert _FakeTransport.pushes[0]["payload"]["content"] == "evolution progress"+ assert _FakeTransport.pushes[1]["payload"]["status"] == "start"+ assert _FakeTransport.pushes[1]["payload"]["stage"] == "approval_required"assert _FakeTransport.pushes[2]["payload"]["request_id"] == "skill_evolve_progress_req"assert _FakeTransport.pushes[3]["payload"]["status"] == "end"assert _FakeTransport.pushes[3]["payload"]["stage"] == "approval_required"@@ -221,9 +324,7 @@ async def test_normal_evolution_watcher_times_out_after_idle_progress(monkeypatcpush for push in _FakeTransport.pushesif push["payload"]["event_type"] == "chat.evolution_status"]- assert [push["payload"]["status"] for push in status_pushes] == ["start", "end"]- assert status_pushes[-1]["payload"]["stage"] == "hidden"- assert "timed out" in status_pushes[-1]["payload"]["message"]+ assert status_pushes == []assert rail.cleanup_calls == 1@@ -245,8 +346,7 @@ async def test_normal_evolution_watcher_hides_timed_out_terminal_progress(monkeypush for push in _FakeTransport.pushesif push["payload"]["event_type"] == "chat.evolution_status"]- assert [push["payload"]["status"] for push in status_pushes] == ["start", "end"]- assert status_pushes[-1]["payload"]["stage"] == "hidden"+ assert status_pushes == []@pytest.mark.asynciodiff --git a/tests/unit_tests/agentserver/test_team_helpers.py b/tests/unit_tests/agentserver/test_team_helpers.pyindex 38686b1f29..d6a4defb1b 100644--- a/tests/unit_tests/agentserver/test_team_helpers.py+++ b/tests/unit_tests/agentserver/test_team_helpers.py@@ -245,12 +245,220 @@ async def test_team_evolution_monitor_starts_cycle_for_started_progress_without_push for push in _FakeTransport.pushesif push["payload"]["event_type"] == "chat.evolution_status"]- assert [push["payload"]["status"] for push in status_pushes] == ["start", "end"]- assert {push["request_id"] for push in status_pushes} == {- "team_evolve_sess-progress_1"- }- assert status_pushes[0]["payload"]["stage"] == "collecting"- assert status_pushes[-1]["payload"]["stage"] == "hidden"+ assert status_pushes == []+++async def test_team_evolution_monitor_maps_sdk_progress_stages(monkeypatch):+ _FakeTransport.pushes = []+ detecting_event = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {+ "event_kind": "progress",+ "stage": "detecting_signals",+ "request_id": "team_skill_evolve_stages",+ },+ "request_id": "team_skill_evolve_stages",+ "content": "[Team Skill Evolution] detecting",+ },+ )+ generating_event = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {+ "event_kind": "progress",+ "stage": "generating_updates",+ "request_id": "team_skill_evolve_stages",+ },+ "request_id": "team_skill_evolve_stages",+ "content": "[Team Skill Evolution] generating",+ },+ )+ outcome_event = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {"event_kind": "outcome", "status": "completed"},+ "request_id": "team_skill_evolve_stages",+ "content": "done",+ },+ )+ rail = _FakeRail([[detecting_event], [generating_event], [outcome_event]], pending_first=False)++ monkeypatch.setattr(+ "jiuwenclaw.server.gateway_push.WebSocketGatewayPushTransport",+ _FakeTransport,+ )+ monkeypatch.setattr(team_helpers, "parse_stream_chunk", lambda evt: None)++ task = asyncio.create_task(+ _TeamHelpersTestApi.watch_team_evolution_and_push("web", "sess-stages", rail)+ )+ await asyncio.sleep(0.05)+ task.cancel()+ with pytest.raises(asyncio.CancelledError):+ await task++ status_pushes = [+ push for push in _FakeTransport.pushes+ if push["payload"]["event_type"] == "chat.evolution_status"+ ]+ assert [push["payload"]["status"] for push in status_pushes] == [+ "start",+ "end",+ ]+ assert [push["payload"]["stage"] for push in status_pushes] == [+ "generating",+ "completed",+ ]+ assert {push["request_id"] for push in status_pushes} == {"team_skill_evolve_stages"}+++async def test_team_evolution_monitor_uses_meta_request_id_and_ends_on_cancelled(monkeypatch):+ _FakeTransport.pushes = []+ detecting_event = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {+ "event_kind": "progress",+ "stage": "detecting_signals",+ "request_id": "team_skill_evolve_meta",+ },+ "content": "[Team Skill Evolution] detecting",+ },+ )+ generating_event = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {+ "event_kind": "progress",+ "stage": "generating_updates",+ "request_id": "team_skill_evolve_meta",+ },+ "content": "[Team Skill Evolution] generating",+ },+ )+ cancelled_event = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {+ "event_kind": "progress",+ "stage": "cancelled",+ "request_id": "team_skill_evolve_meta",+ },+ "content": "no actionable evolution signals detected",+ },+ )+ rail = _FakeRail(+ [[detecting_event], [generating_event], [cancelled_event]],+ pending_first=False,+ )++ monkeypatch.setattr(+ "jiuwenclaw.server.gateway_push.WebSocketGatewayPushTransport",+ _FakeTransport,+ )+ monkeypatch.setattr(team_helpers, "parse_stream_chunk", lambda evt: None)++ task = asyncio.create_task(+ _TeamHelpersTestApi.watch_team_evolution_and_push("web", "sess-meta", rail)+ )+ await asyncio.sleep(0.05)+ task.cancel()+ with pytest.raises(asyncio.CancelledError):+ await task++ status_pushes = [+ push for push in _FakeTransport.pushes+ if push["payload"]["event_type"] == "chat.evolution_status"+ ]+ assert [push["payload"]["status"] for push in status_pushes] == [+ "start",+ "end",+ ]+ assert [push["payload"]["stage"] for push in status_pushes] == [+ "generating",+ "hidden",+ ]+ assert {push["request_id"] for push in status_pushes} == {"team_skill_evolve_meta"}+++async def test_team_evolution_monitor_filters_progress_by_request_id(monkeypatch):+ _FakeTransport.pushes = []+ request_a_detecting = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {+ "event_kind": "progress",+ "stage": "detecting_signals",+ "request_id": "team_skill_evolve_a",+ },+ "content": "[Team Skill Evolution] detecting A",+ },+ )+ request_b_generating = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {+ "event_kind": "progress",+ "stage": "generating_updates",+ "request_id": "team_skill_evolve_b",+ },+ "content": "[Team Skill Evolution] generating B",+ },+ )+ request_a_generating = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {+ "event_kind": "progress",+ "stage": "generating_updates",+ "request_id": "team_skill_evolve_a",+ },+ "content": "[Team Skill Evolution] generating A",+ },+ )+ request_a_completed = SimpleNamespace(+ type="llm_reasoning",+ payload={+ "_evolution_meta": {+ "event_kind": "progress",+ "stage": "completed",+ "request_id": "team_skill_evolve_a",+ },+ "content": "done A",+ },+ )+ rail = _FakeRail(+ [[request_a_detecting], [request_a_generating, request_b_generating], [request_a_completed]],+ pending_first=False,+ )++ monkeypatch.setattr(+ "jiuwenclaw.server.gateway_push.WebSocketGatewayPushTransport",+ _FakeTransport,+ )+ monkeypatch.setattr(team_helpers, "parse_stream_chunk", lambda evt: None)++ task = asyncio.create_task(+ _TeamHelpersTestApi.watch_team_evolution_and_push("web", "sess-filter", rail)+ )+ await asyncio.sleep(0.05)+ task.cancel()+ with pytest.raises(asyncio.CancelledError):+ await task++ status_pushes = [+ push for push in _FakeTransport.pushes+ if push["payload"]["event_type"] == "chat.evolution_status"+ ]+ assert [(push["request_id"], push["payload"]["status"], push["payload"]["stage"]) for push in status_pushes] == [+ ("team_skill_evolve_a", "start", "generating"),+ ("team_skill_evolve_a", "end", "completed"),+ ]+ assert all("generating B" not in push["payload"].get("message", "") for push in status_pushes)@pytest.mark.anyio@@ -377,7 +585,8 @@ async def test_team_evolution_monitor_maps_noop_progress_to_no_evolution_generatpush for push in _FakeTransport.pushesif push["payload"]["event_type"] == "chat.evolution_status"]- assert status_pushes == []+ assert [push["payload"]["status"] for push in status_pushes] == ["start", "end"]+ assert status_pushes[-1]["payload"]["stage"] == "no_evolution_no_signal"@pytest.mark.anyiodiff --git a/uv.lock b/uv.lockindex 2718b075d5..faf8abafc3 100644--- a/uv.lock+++ b/uv.lock@@ -2333,7 +2333,7 @@ wheels = [[[package]]name = "openjiuwen"version = "0.1.13"-source = { registry = "https://pypi.org/simple" }+source = { git = "https://gitcode.com/openJiuwen/agent-core.git?rev=develop#ed6e8c65c6c5e851e8f9249654b00f2dd03142f3" }dependencies = [{ name = "aiofiles" },{ name = "aiohttp" },