fix(chat): 修复动作执行异常时 is_replying 状态未重置的问题

在 `execute_action` 方法中引入 `try...finally` 结构,以确保无论动作执行成功与否,`is_replying` 状态最终都能被可靠地重置为 `False`。

此更改解决了在动作执行期间发生意外错误时,聊天流可能被永久锁定在“正在回复”状态的问题,从而提高了系统的健壮性。
This commit is contained in:
tt-P607
2025-10-25 03:29:14 +08:00
parent 718d787a04
commit b72090f024

View File

@@ -165,6 +165,7 @@ class ChatterActionManager:
执行结果
"""
chat_stream = None
try:
logger.debug(f"🎯 [ActionManager] execute_action接收到 target_message: {target_message}")
# 通过chat_id获取chat_stream
@@ -180,6 +181,9 @@ class ChatterActionManager:
"error": "chat_stream not found",
}
# 设置正在回复的状态
chat_stream.context_manager.context.is_replying = True
if action_name == "no_action":
return {"action_type": "no_action", "success": True, "reply_text": "", "command": ""}
@@ -205,7 +209,7 @@ class ChatterActionManager:
action_build_into_prompt=False,
action_prompt_display=reason,
action_done=True,
thinking_id=thinking_id,
thinking_id=thinking_id or "",
action_data={"reason": reason},
action_name="no_reply",
)
@@ -298,6 +302,10 @@ class ChatterActionManager:
"loop_info": None,
"error": str(e),
}
finally:
# 确保重置正在回复的状态
if chat_stream:
chat_stream.context_manager.context.is_replying = False
async def _record_action_to_message(self, chat_stream, action_name, target_message, action_data):
"""