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:多模态模型配置概率传入agentserver异常问题
hanjiahuiff0c944224ec
diff --git a/jiuwenswarm/common/local_env_config.py b/jiuwenswarm/common/local_env_config.pyindex da50fca7ee..b613fba9fd 100644--- a/jiuwenswarm/common/local_env_config.py+++ b/jiuwenswarm/common/local_env_config.py@@ -20,6 +20,8 @@ Tip formula B (effective tip)::active[(sid, aid)] ∪ staged[(sid, aid)] # staged wins on key clashTask seal: when overlay is bound (including ``{}``), readers only see overlay.+Same-request ``set_os_environ`` writes also patch the bound overlay so apply_* /+enterprise merge paths remain visible to ``read_env`` within that seal."""from __future__ import annotations@@ -776,6 +778,44 @@ ENV_CONFIG_DICT: MutableMapping[str, Any] = _ActiveEnvDict()# ---------------------------------------------------------------------------+def _sync_bound_overlay_write(+ name: str,+ value: str | None,+ *,+ ns: EnvNsKey | None = None,+) -> None:+ """Keep the sealed task overlay aligned with in-request tip writes.++ Overlay seal intentionally hides live tip from readers, but writers in the+ same request (e.g. ``apply_vision_model_config_from_yaml`` after enterprise+ model merge) must still be visible to subsequent ``read_env`` calls.++ Only patches when ``ns`` matches the currently bound agent env ns, so an+ explicit cross-ns ``set_os_environ`` cannot leak values into another+ request's overlay.+ """+ overlay = _task_env_overlay.get()+ if overlay is _UNBOUND:+ return+ bound_ns = _agent_env_ns.get()+ if ns is not None and ns != bound_ns:+ logger.warning(+ "set_os_environ 跨 ns 写入不同步当前 overlay: write_ns=%s bound_ns=%s key=%s",+ ns,+ bound_ns,+ name,+ )+ return+ key = canonical_product_env_key(str(name))+ if value is None:+ overlay.pop(key, None)+ legacy = legacy_product_env_key(key)+ if legacy is not None:+ overlay.pop(legacy, None)+ return+ overlay[key] = value++def set_os_environ(name: str,value: Any,@@ -783,18 +823,26 @@ def set_os_environ(service_id: str | None = None,agent_id: str | None = None,) -> None:- """Write Track B active tip only (plaintext). Does not touch ``os.environ``."""+ """Write Track B active tip only (plaintext). Does not touch ``os.environ``.++ When a task overlay is bound for the same env ns, also patch that overlay so+ same-request readers observe the write despite seal-miss semantics.+ """if name in SPAWN_ENV_KEYS:logger.warning("拒绝 set_os_environ 轨道 A 键: %s", name)returnkey = resolve_env_ns(service_id, agent_id)sid, aid = keyactive = _bag(_active_bags, key)+ env_name = str(name)if value is None:- active.pop(str(name), None)- _pop_bare_if_default_default(sid, aid, str(name))+ active.pop(env_name, None)+ _pop_bare_if_default_default(sid, aid, env_name)+ _sync_bound_overlay_write(env_name, None, ns=key)return- active[str(name)] = _plaintext_tip_value(str(name), value)+ plain = _plaintext_tip_value(env_name, value)+ active[env_name] = plain+ _sync_bound_overlay_write(env_name, plain, ns=key)def get_os_environ(diff --git a/tests/unit_tests/common/test_local_env_config.py b/tests/unit_tests/common/test_local_env_config.pyindex 8ff50065c3..cdc76b6dca 100644--- a/tests/unit_tests/common/test_local_env_config.py+++ b/tests/unit_tests/common/test_local_env_config.py@@ -122,6 +122,126 @@ class TestLocalEnvConfig:def test_code_coauthor_header_switch_is_spawn_shared(self):assert "JIUWENSWARM_CODE_COAUTHOR_HEADER_ENABLED" in SPAWN_ENV_KEYS+ def test_set_os_environ_patches_bound_overlay_for_same_request_reads(self):+ """Enterprise vision apply writes tip under seal; readers must see it."""+ from jiuwenswarm.common.local_env_config import (+ bind_agent_env_ns,+ build_effective_env_overlay,+ clear_agent_env_ns,+ replace_active_env,+ reset_agent_env_ns,+ )+ from jiuwenswarm.agents.harness.common.tools.multimodal_config import (+ apply_vision_model_config_from_yaml,+ )++ sid, aid = "overlay-svc", "overlay-agent"+ clear_agent_env_ns(sid, aid)+ replace_active_env({}, service_id=sid, agent_id=aid)+ ns = bind_agent_env_ns(sid, aid)+ overlay = build_effective_env_overlay(None, service_id=sid, agent_id=aid)+ assert "VISION_API_KEY" not in overlay+ ot = bind_task_env_overlay(overlay)+ try:+ apply_vision_model_config_from_yaml(+ {+ "models": {+ "vision": {+ "model_client_config": {+ "api_key": "vk-live",+ "api_base": "http://vision.example/v1",+ "model_name": "Qwen3.7-Plus",+ "client_provider": "OpenAI",+ }+ }+ }+ }+ )+ assert read_env("VISION_API_KEY") == "vk-live"+ assert read_env("VISION_API_BASE") == "http://vision.example/v1"+ assert read_env("VISION_MODEL_NAME") == "Qwen3.7-Plus"+ finally:+ reset_task_env_overlay(ot)+ reset_agent_env_ns(ns)+ clear_agent_env_ns(sid, aid)++ def test_set_os_environ_none_removes_from_bound_overlay(self):+ """Delete path must pop canonical (+ product legacy) keys from seal."""+ from jiuwenswarm.common.local_env_config import (+ bind_agent_env_ns,+ build_effective_env_overlay,+ clear_agent_env_ns,+ read_env_if_set,+ replace_active_env,+ reset_agent_env_ns,+ )++ sid, aid = "overlay-svc", "overlay-agent"+ clear_agent_env_ns(sid, aid)+ replace_active_env(+ {+ "VISION_API_KEY": "stale",+ "JIUWENSWARM_DISABLED_SKILLS": "skill-a",+ },+ service_id=sid,+ agent_id=aid,+ )+ ns = bind_agent_env_ns(sid, aid)+ overlay = build_effective_env_overlay(None, service_id=sid, agent_id=aid)+ overlay["VISION_API_KEY"] = "sealed-old"+ overlay["JIUWENSWARM_DISABLED_SKILLS"] = "sealed-canon"+ overlay["JIUWENCLAW_DISABLED_SKILLS"] = "sealed-legacy"+ ot = bind_task_env_overlay(overlay)+ try:+ set_os_environ("VISION_API_KEY", None)+ assert read_env("VISION_API_KEY") == ""+ assert read_env_if_set("VISION_API_KEY") is None++ set_os_environ("JIUWENSWARM_DISABLED_SKILLS", None)+ assert read_env("JIUWENSWARM_DISABLED_SKILLS") == ""+ assert read_env("JIUWENCLAW_DISABLED_SKILLS") == ""+ assert read_env_if_set("JIUWENSWARM_DISABLED_SKILLS") is None+ finally:+ reset_task_env_overlay(ot)+ reset_agent_env_ns(ns)+ clear_agent_env_ns(sid, aid)++ def test_set_os_environ_cross_ns_does_not_patch_bound_overlay(self):+ """Explicit foreign ns writes tip only; current seal must stay untouched."""+ from jiuwenswarm.common.local_env_config import (+ bind_agent_env_ns,+ build_effective_env_overlay,+ clear_agent_env_ns,+ effective_tip,+ replace_active_env,+ reset_agent_env_ns,+ )++ sid_b, aid_b = "svc-b", "agent-b"+ sid_a, aid_a = "svc-a", "agent-a"+ clear_agent_env_ns(sid_a, aid_a)+ clear_agent_env_ns(sid_b, aid_b)+ replace_active_env({}, service_id=sid_b, agent_id=aid_b)+ replace_active_env({}, service_id=sid_a, agent_id=aid_a)+ ns = bind_agent_env_ns(sid_b, aid_b)+ overlay = build_effective_env_overlay(None, service_id=sid_b, agent_id=aid_b)+ ot = bind_task_env_overlay(overlay)+ try:+ set_os_environ(+ "VISION_API_KEY",+ "key-of-a",+ service_id=sid_a,+ agent_id=aid_a,+ )+ assert "VISION_API_KEY" not in overlay+ assert read_env("VISION_API_KEY") == ""+ assert effective_tip(sid_a, aid_a).get("VISION_API_KEY") == "key-of-a"+ finally:+ reset_task_env_overlay(ot)+ reset_agent_env_ns(ns)+ clear_agent_env_ns(sid_a, aid_a)+ clear_agent_env_ns(sid_b, aid_b)+def test_export_spawn_environ_keeps_process_path_without_tenant_credentials(self):from jiuwenswarm.common.local_env_config import export_spawn_environ