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_turbo): 检视修复——stale TIC 防劫持 + marker 校验失败降级
d300296967ac93f1194f4
diff --git a/jiuwenswarm/agents/harness/common/rails/stream_event_rail.py b/jiuwenswarm/agents/harness/common/rails/stream_event_rail.pyindex 0fd2413077..5304dc102b 100644--- a/jiuwenswarm/agents/harness/common/rails/stream_event_rail.py+++ b/jiuwenswarm/agents/harness/common/rails/stream_event_rail.py@@ -1226,6 +1226,7 @@ class JiuSwarmStreamEventRail(DeepAgentRail):get_skill_turbo_hitl_tic,set_skill_turbo_hitl_tic,)+ _tool_name = str(getattr(ctx.inputs, "tool_name", "") or "")_hitl_request_dump: dict[str, Any] | None = None_raw_tool_result = ctx.inputs.tool_resultif (@@ -1237,6 +1238,13 @@ class JiuSwarmStreamEventRail(DeepAgentRail):_skill_turbo_tic = (get_skill_turbo_hitl_tic() if _hitl_request_dump is None else None)+ if _skill_turbo_tic is not None and _tool_name != "skill_acceleration_exec":+ logger.warning(+ "[StreamEventRail] stale skill_turbo TIC dropped for tool=%s",+ _tool_name,+ )+ set_skill_turbo_hitl_tic(None)+ _skill_turbo_tic = Noneif _hitl_request_dump is not None or _skill_turbo_tic is not None:set_skill_turbo_hitl_tic(None)if isinstance(ctx.inputs, ToolCallInputs):@@ -1285,6 +1293,24 @@ class JiuSwarmStreamEventRail(DeepAgentRail):"[StreamEventRail] skill_turbo HITL rewrite failed",exc_info=True,)+ # 降级:原始 marker dict 不可直接透传给模型(无语义 JSON 会让+ # 模型误判失败并回退 skill_tool)。改为可读暂停文案兜底。+ from jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools import (+ _SKILL_TURBO_HITL_RESULT_KEY,+ )+ if (+ isinstance(ctx.inputs, ToolCallInputs)+ and isinstance(ctx.inputs.tool_result, dict)+ and ctx.inputs.tool_result.get(_SKILL_TURBO_HITL_RESULT_KEY)+ ):+ from jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools import (+ _SKILL_TURBO_HITL_PLACEHOLDER,+ )+ ctx.inputs.tool_result = _SKILL_TURBO_HITL_PLACEHOLDER+ ctx.inputs.tool_msg = ToolMessage(+ content=_SKILL_TURBO_HITL_PLACEHOLDER,+ tool_call_id=ctx.inputs.tool_call.id,+ )if (str(getattr(tc, "name", "") or "").strip() == "deepresearch_execute"diff --git a/tests/unit_tests/agentserver/test_skill_turbo_hitl_tie_rewrite_repro.py b/tests/unit_tests/agentserver/test_skill_turbo_hitl_tie_rewrite_repro.pyindex aeb9726ac5..76f0e5e411 100644--- a/tests/unit_tests/agentserver/test_skill_turbo_hitl_tie_rewrite_repro.py+++ b/tests/unit_tests/agentserver/test_skill_turbo_hitl_tie_rewrite_repro.py@@ -32,6 +32,7 @@ from jiuwenswarm.agents.harness.common.rails.stream_event_rail import (from jiuwenswarm.server.runtime.skill_turbo import skill_turbo_toolsfrom jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools import (build_skill_turbo_hitl_result,+ get_skill_turbo_hitl_tic,set_skill_turbo_hitl_tic,)@@ -238,3 +239,84 @@ def test_skill_turbo_hitl_result_marker_is_deepcopy_safe():cloned = copy.deepcopy(marker)assert cloned == markerassert cloned["request"]["message"] == "页数"+++async def test_stale_tic_does_not_hijack_unrelated_tool():+ """验证残留 TIC 不会劫持非 skill_acceleration_exec 工具的 after_tool_call。"""+ rail = JiuSwarmStreamEventRail()+ rail.set_skill_turbo_adapter(SimpleNamespace(_instance=None))+ session = _StreamSession()+ tic = _make_tic()+ set_skill_turbo_hitl_tic(tic)+ try:+ tc = SimpleNamespace(id="call-web-1", name="web_search", arguments={})+ ctx = SimpleNamespace(+ session=session,+ inputs=ToolCallInputs(+ tool_call=tc,+ tool_name="web_search",+ tool_args={},+ tool_result="search results here",+ tool_msg=None,+ ),+ extra={},+ exception=None,+ request_force_finish=lambda *_a, **_kw: None,+ )+ await rail.after_tool_call(ctx)+ assert ctx.inputs.tool_result == "search results here", (+ "unrelated tool_result should not be rewritten by stale TIC"+ )+ assert get_skill_turbo_hitl_tic() is None, (+ "stale TIC should be cleared after being dropped"+ )+ finally:+ set_skill_turbo_hitl_tic(None)+++async def test_marker_validation_failure_degrades_to_readable_placeholder(monkeypatch):+ """验证 marker 校验失败时降级为可读暂停文案,不透传原始 dict。"""+ from openjiuwen.core.single_agent.interrupt.response import (+ ToolCallInterruptRequest,+ )++ def _raise_validation_error(*_args, **_kwargs):+ raise ValueError("simulated schema drift")++ monkeypatch.setattr(ToolCallInterruptRequest, "model_validate", _raise_validation_error)++ rail = JiuSwarmStreamEventRail()+ rail.set_skill_turbo_adapter(SimpleNamespace(_instance=None))+ session = _StreamSession()+ from jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools import (+ _SKILL_TURBO_HITL_PLACEHOLDER,+ _SKILL_TURBO_HITL_RESULT_KEY,+ )++ bad_marker = {_SKILL_TURBO_HITL_RESULT_KEY: True, "request": {"message": "x"}}+ tc = SimpleNamespace(+ id="call-9",+ name="skill_acceleration_exec",+ arguments={"query": "make ppt"},+ )+ ctx = SimpleNamespace(+ session=session,+ inputs=ToolCallInputs(+ tool_call=tc,+ tool_name="skill_acceleration_exec",+ tool_args={"query": "make ppt"},+ tool_result=bad_marker,+ tool_msg=None,+ ),+ extra={},+ exception=None,+ request_force_finish=lambda *_a, **_kw: None,+ )+ set_skill_turbo_hitl_tic(None)+ await rail.after_tool_call(ctx)+ assert ctx.inputs.tool_result == _SKILL_TURBO_HITL_PLACEHOLDER, (+ "marker validation failure should degrade to readable placeholder, "+ f"got {ctx.inputs.tool_result!r}"+ )