Skip to content

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:解决ask_user未弹窗问题

Chenchong_RD2e41c076ca8b
diff --git a/jiuwenswarm/agents/harness/common/rails/stream_event_rail.py b/jiuwenswarm/agents/harness/common/rails/stream_event_rail.py
index c4324c1123..3fae6d9632 100644
--- a/jiuwenswarm/agents/harness/common/rails/stream_event_rail.py
+++ b/jiuwenswarm/agents/harness/common/rails/stream_event_rail.py
@@ -1283,7 +1283,15 @@ class JiuSwarmStreamEventRail(DeepAgentRail):
_skill_turbo_tic.tool_call.id if _skill_turbo_tic.tool_call else "?",
ctx.inputs.tool_call.id if isinstance(ctx.inputs, ToolCallInputs) else "?",
)
- return # 跳过 _emit_tool_result,由 harness __interaction__ 取代
+ # 主路径必须主动 emit:外层 tool_name 是 skill_acceleration_exec,
+ # _emit_ask_user_question_if_interrupted 不会命中;也不能只依赖
+ # harness __interaction__(同 tool_call_id 二次 HITL 时常哑火)。
+ await self._emit_skill_turbo_ask_user_question(
+ session,
+ outer_tool_call=ctx.inputs.tool_call,
+ skill_turbo_tic=_skill_turbo_tic,
+ )
+ return # 跳过 _emit_tool_result;ask_user 已在上方强制发出
except Exception:
logger.debug(
"[StreamEventRail] skill_turbo HITL rewrite failed",
@@ -1419,6 +1427,61 @@ class JiuSwarmStreamEventRail(DeepAgentRail):
except Exception:
logger.debug("tool_result emit failed", exc_info=True)
+ @staticmethod
+ async def _emit_skill_turbo_ask_user_question(
+ session: Session,
+ *,
+ outer_tool_call: Any,
+ skill_turbo_tic: Any,
+ ) -> None:
+ """Emit chat.ask_user_question for SkillTurbo nested ask_user HITL.
+
+ Questions come from the inner ask_user tool_call; request_id is the
+ outer skill_acceleration_exec tool_call.id so OfficeClaw resume keeps
+ matching harness interrupt keys (e.g. call_c2967...).
+ """
+ inner_tc = getattr(skill_turbo_tic, "tool_call", None)
+ payload = _ask_user_question_payload_from_interrupt(
+ inner_tc or outer_tool_call,
+ skill_turbo_tic,
+ )
+ if not payload:
+ logger.debug(
+ "[StreamEventRail] SkillTurbo HITL ask_user payload unavailable"
+ )
+ return
+ # OfficeClaw resume matches harness interrupt keys on the outer
+ # skill_acceleration_exec id. Emitting with the nested ask_user id is
+ # worse than skipping: the UI would show a question that cannot resume.
+ harness_id = str(getattr(outer_tool_call, "id", "") or "").strip()
+ if not harness_id:
+ logger.warning(
+ "[StreamEventRail] SkillTurbo HITL ask_user skipped: "
+ "outer skill_acceleration_exec tool_call.id unavailable "
+ "(would mismatch harness interrupt key); inner_request_id=%s",
+ payload.get("request_id"),
+ )
+ return
+ payload["request_id"] = harness_id
+ try:
+ await session.write_stream(
+ OutputSchema(
+ type="chat.ask_user_question",
+ index=0,
+ payload=payload,
+ )
+ )
+ logger.info(
+ "[StreamEventRail] SkillTurbo HITL emitted chat.ask_user_question "
+ "request_id=%s",
+ payload.get("request_id"),
+ )
+ except Exception:
+ logger.debug(
+ "[StreamEventRail] SkillTurbo HITL ask_user emit failed",
+ exc_info=True,
+ )
+
@staticmethod
async def _emit_ask_user_question_if_interrupted(
session: Session,
diff --git a/jiuwenswarm/server/app_agentserver.py b/jiuwenswarm/server/app_agentserver.py
index e4a8a4063f..2ecf615d63 100644
--- a/jiuwenswarm/server/app_agentserver.py
+++ b/jiuwenswarm/server/app_agentserver.py
@@ -45,6 +45,8 @@ from jiuwenswarm.common.utils import (
update_config,
migrate_legacy_user_config_if_needed,
)
+# Needed before workspace update_config gate (module top-level uses is_enterprise).
+from jiuwenswarm.common.local_env_config import is_enterprise
migrate_legacy_user_config_if_needed()
diff --git a/tests/unit_tests/agentserver/test_stream_event_rail_todo.py b/tests/unit_tests/agentserver/test_stream_event_rail_todo.py
index 8496fee40a..a305f941e4 100644
--- a/tests/unit_tests/agentserver/test_stream_event_rail_todo.py
+++ b/tests/unit_tests/agentserver/test_stream_event_rail_todo.py
@@ -195,6 +195,113 @@ async def test_ask_user_interrupt_emits_question_event_from_tool_args():
assert output.payload["questions"][0]["question"] == "请选择方案"
+async def test_skill_turbo_hitl_emits_ask_user_with_outer_request_id():
+ """Nested ask_user questions, but resume key is outer skill_acceleration_exec id."""
+ class ToolInterruptException(Exception):
+ def __init__(self):
+ super().__init__()
+ self.request = SimpleNamespace(
+ tool_call_id="skill_turbo-tc-ask_user-54ee111d-0",
+ tool_name="ask_user",
+ tool_args={
+ "questions": [
+ {
+ "question": "需要多少页?",
+ "header": "页数",
+ "options": [{"label": "10页", "description": ""}],
+ }
+ ]
+ },
+ )
+ self.tool_call = SimpleNamespace(
+ id="skill_turbo-tc-ask_user-54ee111d-0",
+ name="ask_user",
+ arguments={
+ "questions": [
+ {
+ "question": "需要多少页?",
+ "header": "页数",
+ "options": [{"label": "10页", "description": ""}],
+ }
+ ]
+ },
+ )
+
+ session = _FakeSession()
+ outer_tc = SimpleNamespace(id="call_c2967f3aec5c412583a203b9", name="skill_acceleration_exec")
+
+ await JiuSwarmStreamEventRail._emit_skill_turbo_ask_user_question(
+ session,
+ outer_tool_call=outer_tc,
+ skill_turbo_tic=ToolInterruptException(),
+ )
+
+ assert len(session.outputs) == 1
+ output = session.outputs[0]
+ assert output.type == "chat.ask_user_question"
+ assert output.payload["request_id"] == "call_c2967f3aec5c412583a203b9"
+ assert output.payload["source"] == "ask_user_interrupt"
+ assert output.payload["questions"][0]["question"] == "需要多少页?"
+
+
+async def test_skill_turbo_hitl_skips_emit_when_outer_tool_call_missing(monkeypatch):
+ """Without outer harness id, do not emit a nested ask_user request_id."""
+ class ToolInterruptException(Exception):
+ def __init__(self):
+ super().__init__()
+ self.request = SimpleNamespace(
+ tool_call_id="skill_turbo-tc-ask_user-54ee111d-0",
+ tool_name="ask_user",
+ tool_args={
+ "questions": [
+ {
+ "question": "需要多少页?",
+ "header": "页数",
+ "options": [{"label": "10页", "description": ""}],
+ }
+ ]
+ },
+ )
+ self.tool_call = SimpleNamespace(
+ id="skill_turbo-tc-ask_user-54ee111d-0",
+ name="ask_user",
+ arguments={
+ "questions": [
+ {
+ "question": "需要多少页?",
+ "header": "页数",
+ "options": [{"label": "10页", "description": ""}],
+ }
+ ]
+ },
+ )
+
+ session = _FakeSession()
+ warnings: list[str] = []
+
+ def _capture_warning(msg, *args, **kwargs):
+ warnings.append(msg % args if args else str(msg))
+
+ monkeypatch.setattr(
+ "jiuwenswarm.agents.harness.common.rails.stream_event_rail.logger.warning",
+ _capture_warning,
+ )
+
+ await JiuSwarmStreamEventRail._emit_skill_turbo_ask_user_question(
+ session,
+ outer_tool_call=None,
+ skill_turbo_tic=ToolInterruptException(),
+ )
+
+ assert session.outputs == []
+ assert any(
+ "outer skill_acceleration_exec tool_call.id unavailable" in message
+ for message in warnings
+ )
+
+
@pytest.mark.asyncio
async def test_ask_user_interrupt_emits_question_event_from_exception_cause():
class ToolInterruptException(Exception):