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(rails): stop ask_user option cards re-popping forever (#1976)
stevenchenhanwen200647894322d918
diff --git a/jiuwenswarm/agents/harness/common/rails/interrupt/interrupt_helpers.py b/jiuwenswarm/agents/harness/common/rails/interrupt/interrupt_helpers.pyindex c45737181d..aae78de99a 100644--- a/jiuwenswarm/agents/harness/common/rails/interrupt/interrupt_helpers.py+++ b/jiuwenswarm/agents/harness/common/rails/interrupt/interrupt_helpers.py@@ -290,6 +290,21 @@ def build_permission_rail()perm_ctx = TOOL_PERMISSION_CONTEXT.get()++ # issue #1976: ask_user has its own dedicated interrupt rail. The+ # permission rail intercepts *every* tool, so on resume it grabs the+ # ask_user answer (keyed by tool_call_id) as its own user_input,+ # fails to parse it as a ConfirmPayload, and re-raises a permission+ # interrupt that swallows the answer — the option card then re-pops+ # forever. Bypass the permission rail for ask_user so the ask_user+ # rail's answer reaches the model. The digital-avatar scene below+ # intentionally blocks interactive tools, so exclude it here.+ if inp.normalized_tool_name == "ask_user" and (+ perm_ctx is None+ or getattr(perm_ctx, "scene", None) != "group_digital_avatar"+ ):+ return ("approve",)+if perm_ctx is None:return Nonediff --git a/tests/unit_tests/agentserver/test_interrupt_helpers.py b/tests/unit_tests/agentserver/test_interrupt_helpers.pyindex 28b89b83ef..99e75b92be 100644--- a/tests/unit_tests/agentserver/test_interrupt_helpers.py+++ b/tests/unit_tests/agentserver/test_interrupt_helpers.py@@ -1,8 +1,10 @@+import asynciofrom types import SimpleNamespaceimport pytestfrom jiuwenswarm.agents.harness.common.rails.interrupt.interrupt_helpers import (+ build_permission_rail,convert_interactions_to_ask_user_question,)@@ -109,3 +111,58 @@ def test_legacy_skill_evolution_approval_metadata_is_classified():assert result is not Noneassert result["source"] == "evolution_interrupt"assert result["approval_kind"] == "evolve"+++def _scene_hook_input(normalized_tool_name: str, user_input):+ from openjiuwen.harness.security.host import PermissionSceneHookInput++ return PermissionSceneHookInput(+ ctx=SimpleNamespace(session=None),+ tool_call=SimpleNamespace(id="call_1", name=normalized_tool_name, arguments={}),+ user_input=user_input,+ normalized_tool_name=normalized_tool_name,+ tool_args={},+ engine=None,+ )+++def _permission_scene_hook():+ rail = build_permission_rail({"permissions": {"enabled": True}})+ assert rail is not None+ hook = rail._host.permission_scene_hook+ assert hook is not None+ return hook+++def test_scene_hook_approves_ask_user_on_resume():+ """Regression for issue #1976.++ The permission rail intercepts every tool. On resume it would otherwise+ grab the ask_user answer as its own user_input and re-raise a permission+ interrupt, making the option card re-pop forever. The scene hook must+ approve ask_user so its answer reaches the model.+ """+ hook = _permission_scene_hook()+ resume_answer = {"answers": {"__free_text__": "数据处理"}, "original_request": "..."}++ outcome = asyncio.run(hook(_scene_hook_input("ask_user", resume_answer)))++ assert outcome == ("approve",)+++def test_scene_hook_approves_ask_user_on_first_pass():+ hook = _permission_scene_hook()++ outcome = asyncio.run(hook(_scene_hook_input("ask_user", None)))++ assert outcome == ("approve",)+++def test_scene_hook_leaves_other_tools_to_engine():+ """Non-interactive tools must still fall through to the tiered engine+ (returns ``None``) when no owner-scope context is set."""+ hook = _permission_scene_hook()++ outcome = asyncio.run(hook(_scene_hook_input("bash", None)))++ assert outcome is None