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: 修改skill自演进没有触发问题
w1101627533898235f056a0
diff --git a/jiuwenswarm/agents/harness/agent_observability.py b/jiuwenswarm/agents/harness/agent_observability.pyindex 316e8dc07f..cf6729be71 100644--- a/jiuwenswarm/agents/harness/agent_observability.py+++ b/jiuwenswarm/agents/harness/agent_observability.py@@ -244,6 +244,20 @@ def sync_agent_observability(*, force: bool = False) -> None:_agent_observability_active = True_agent_owns_provider = False_runtime_managed_agent_observability = True+ # Unified telemetry owns the TracerProvider but historically omitted+ # TrajectorySpanProcessor; attach it so SkillEvolutionRail can drain.+ try:+ from jiuwenswarm.agents.harness.observability_runtime import (+ ensure_trajectory_span_processor_attached,+ )++ ensure_trajectory_span_processor_attached()+ except Exception as exc:+ logger.warning(+ "[AgentObservability] failed to attach trajectory processor "+ "on unified path: %s",+ exc,+ )returnif force:_force_ever_enabled = Truediff --git a/jiuwenswarm/agents/harness/observability_runtime.py b/jiuwenswarm/agents/harness/observability_runtime.pyindex 93e5d5e409..0df36123d6 100644--- a/jiuwenswarm/agents/harness/observability_runtime.py+++ b/jiuwenswarm/agents/harness/observability_runtime.py@@ -53,6 +53,46 @@ def get_trajectory_span_processor() -> Any:return _TRAJECTORY_SPAN_PROCESSOR+def ensure_trajectory_span_processor_attached() -> bool:+ """Attach the shared trajectory processor to the active OTel provider.++ Idempotent: ``ObservabilityRuntime.add_span_processors`` skips processors+ already registered by object identity. Safe to call from both the unified+ telemetry path and the legacy ``acquire_observability_demand`` path.+ Returns ``True`` when a processor is present on an initialized provider.+ """+ processor = get_trajectory_span_processor()+ if processor is None:+ return False++ from openjiuwen.agent_teams.observability.setup import (+ get_config,+ init_observability,+ is_initialized,+ )++ if not is_initialized():+ return False++ config = get_config()+ if config is None:+ return False++ init_kwargs = {"additional_span_processors": (processor,)}+ compatible_kwargs = filter_unsupported_kwargs(init_observability, init_kwargs)+ dropped = set(init_kwargs) - set(compatible_kwargs)+ if dropped:+ logger.warning(+ "openjiuwen init_observability does not accept %s; "+ "trajectory capture cannot attach on unified path",+ ", ".join(sorted(dropped)),+ )+ return False++ init_observability(config, **compatible_kwargs)+ return True++def build_observability_config(config: Mapping[str, Any],*,@@ -99,6 +139,9 @@ def acquire_observability_demand(from openjiuwen.agent_teams.observability import is_initializedif runtime in _ACTIVE_RUNTIMES and is_initialized():+ # Provider may have been created by unified telemetry without the+ # trajectory processor; re-ensure attachment on every demand.+ ensure_trajectory_span_processor_attached()return Truefrom openjiuwen.agent_teams.observability import init_observability@@ -115,6 +158,10 @@ def acquire_observability_demand(", ".join(sorted(dropped)),)init_observability(observability_config, **compatible_kwargs)+ # When the provider already existed (e.g. unified telemetry), the kwargs+ # above may have been a no-op on older SDKs; force an explicit attach.+ if provider_existed:+ ensure_trajectory_span_processor_attached()if not is_initialized():raise RuntimeError(f"{runtime} observability initialization did not create a provider"diff --git a/jiuwenswarm/agents/harness/team/team_manager.py b/jiuwenswarm/agents/harness/team/team_manager.pyindex f0e612c581..a519d90a5f 100644--- a/jiuwenswarm/agents/harness/team/team_manager.py+++ b/jiuwenswarm/agents/harness/team/team_manager.py@@ -148,6 +148,20 @@ def sync_team_observability() -> None:if unified_active:_observability_active = True_runtime_managed_observability = True+ # Same gap as single-agent: unified runtime must still host the+ # shared TrajectorySpanProcessor for skill / team evolution rails.+ try:+ from jiuwenswarm.agents.harness.observability_runtime import (+ ensure_trajectory_span_processor_attached,+ )++ ensure_trajectory_span_processor_attached()+ except Exception as exc:+ logger.warning(+ "[TeamObservability] failed to attach trajectory processor "+ "on unified path: %s",+ exc,+ )returnif _runtime_managed_observability:_observability_active = Falsediff --git a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.pyindex cac940292c..f8d5030b29 100644--- a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py+++ b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py@@ -7936,6 +7936,10 @@ class JiuWenSwarmDeepAdapter:should_enable_general_agent = should_add_general_agent and (sub_mode == "plan" or (isinstance(mode, str) and mode.startswith("agent")))+ from jiuwenswarm.agents.harness.observability_runtime import (+ get_trajectory_span_processor,+ )+common_kwargs = dict(model=model,card=agent_card,@@ -7955,7 +7959,8 @@ class JiuWenSwarmDeepAdapter:),sys_operation=sys_operation,language=self._resolve_runtime_language(),- auto_create_workspace=False+ auto_create_workspace=False,+ trajectory_span_processor=get_trajectory_span_processor(),)# agent_ras YAML passthrough (Agent RAS owns loop detection / recovery).diff --git a/jiuwenswarm/telemetry/runtime.py b/jiuwenswarm/telemetry/runtime.pyindex 7e6dbf5fb4..24dd4a1ba4 100644--- a/jiuwenswarm/telemetry/runtime.py+++ b/jiuwenswarm/telemetry/runtime.py@@ -319,10 +319,22 @@ class TelemetryRuntime:max_attributes=config.max_attributes,backend="otlp",)+ # Skill / team evolution rails subscribe to this processor; without+ # registering it on the unified TracerProvider, after_invoke never+ # receives LLM/tool spans and run_evolution is skipped silently.+ from jiuwenswarm.agents.harness.observability_runtime import (+ get_trajectory_span_processor,+ )++ trajectory_processor = get_trajectory_span_processor()+ extra_processors = (+ (trajectory_processor,) if trajectory_processor is not None else ()+ )init_observability(core_config,tracer_provider_override=tracer_provider,owns_provider=False,+ additional_span_processors=extra_processors,)except Exception as error:self._set_status("agentcore", False, error)diff --git a/tests/unit_tests/agentserver/test_trajectory_runtime_wiring.py b/tests/unit_tests/agentserver/test_trajectory_runtime_wiring.pyindex c221b65822..4b14b3ccaa 100644--- a/tests/unit_tests/agentserver/test_trajectory_runtime_wiring.py+++ b/tests/unit_tests/agentserver/test_trajectory_runtime_wiring.py@@ -15,18 +15,22 @@ def reset_observability_demands():observability_runtime.reset_observability_demands()agent_observability._agent_observability_active = Falseagent_observability._force_ever_enabled = False+ agent_observability._runtime_managed_agent_observability = Falseroot_spans = getattr(agent_observability, "_ROOT_SPANS", None)if root_spans is not None:root_spans.clear()team_manager._observability_active = False+ team_manager._runtime_managed_observability = Falseyieldobservability_runtime.reset_observability_demands()agent_observability._agent_observability_active = Falseagent_observability._force_ever_enabled = False+ agent_observability._runtime_managed_agent_observability = Falseroot_spans = getattr(agent_observability, "_ROOT_SPANS", None)if root_spans is not None:root_spans.clear()team_manager._observability_active = False+ team_manager._runtime_managed_observability = Falsedef test_trajectory_processor_is_shared_across_runtimes(monkeypatch):@@ -282,3 +286,83 @@ def test_shared_observability_demand_does_not_shutdown_external_provider(monkeypobservability_runtime.release_observability_demand("agent")assert shutdowns == []+++def test_unified_agent_path_attaches_trajectory_processor(monkeypatch):+ attaches = []+ monkeypatch.setattr(+ agent_observability,+ "_get_unified_runtime",+ lambda: type("R", (), {"is_unified_active": staticmethod(lambda: True)})(),+ )+ monkeypatch.setattr(+ "jiuwenswarm.agents.harness.observability_runtime.ensure_trajectory_span_processor_attached",+ lambda: attaches.append("agent") or True,+ )++ agent_observability.sync_agent_observability()++ assert attaches == ["agent"]+ assert agent_observability._agent_observability_active is True+ assert agent_observability._runtime_managed_agent_observability is True+++def test_unified_team_path_attaches_trajectory_processor(monkeypatch):+ attaches = []+ monkeypatch.setattr(+ team_manager,+ "_get_unified_runtime",+ lambda: type("R", (), {"is_unified_active": staticmethod(lambda: True)})(),+ )+ monkeypatch.setattr(+ "jiuwenswarm.agents.harness.observability_runtime.ensure_trajectory_span_processor_attached",+ lambda: attaches.append("team") or True,+ )++ team_manager.sync_team_observability()++ assert attaches == ["team"]+ assert team_manager._observability_active is True+ assert team_manager._runtime_managed_observability is True+++def test_ensure_trajectory_attaches_via_init_observability(monkeypatch):+ processor = object()+ calls = []+ config = object()+ monkeypatch.setattr(+ observability_runtime, "_TRAJECTORY_SPAN_PROCESSOR", processor+ )+ monkeypatch.setattr(observability_runtime, "_TRAJECTORY_UNAVAILABLE", False)++ import openjiuwen.agent_teams.observability.setup as obs_setup++ monkeypatch.setattr(obs_setup, "is_initialized", lambda: True)+ monkeypatch.setattr(obs_setup, "get_config", lambda: config)+ monkeypatch.setattr(+ obs_setup,+ "init_observability",+ lambda cfg, **kwargs: calls.append((cfg, kwargs)),+ )++ assert observability_runtime.ensure_trajectory_span_processor_attached() is True+ assert calls == [(config, {"additional_span_processors": (processor,)})]+++def test_acquire_reattaches_trajectory_when_runtime_already_active(monkeypatch):+ attaches = []+ monkeypatch.setattr(observability, "is_initialized", lambda: True)+ monkeypatch.setattr(+ observability_runtime,+ "ensure_trajectory_span_processor_attached",+ lambda: attaches.append(True) or True,+ )+ observability_runtime._ACTIVE_RUNTIMES.add("agent")++ result = observability_runtime.acquire_observability_demand(+ "agent",+ observability_config=object(),+ )++ assert result is True+ assert attaches == [True]diff --git a/tests/unit_tests/telemetry/test_runtime.py b/tests/unit_tests/telemetry/test_runtime.pyindex 08f4dc3e8c..d42bb51dd8 100644--- a/tests/unit_tests/telemetry/test_runtime.py+++ b/tests/unit_tests/telemetry/test_runtime.py@@ -314,6 +314,11 @@ async def test_agentserver_injects_provider_and_registers_callbacks(monkeypatch: pytest.MonkeyPatch,) -> None:env = _install_runtime_fakes(monkeypatch)+ trajectory_processor = Mock(name="trajectory_span_processor")+ monkeypatch.setattr(+ "jiuwenswarm.agents.harness.observability_runtime.get_trajectory_span_processor",+ Mock(return_value=trajectory_processor),+ )runtime = TelemetryRuntime()state = await runtime.start(@@ -328,6 +333,7 @@ async def test_agentserver_injects_provider_and_registers_callbacks(assert kwargs == {"tracer_provider_override": env.tracer,"owns_provider": False,+ "additional_span_processors": (trajectory_processor,),}assert env.callbacks.register_calls == 1assert runtime.component_status()["agentcore"].active is True