From 1d18934396d5edce6e018d408d8d569d8947e6a1 Mon Sep 17 00:00:00 2001 From: tsumon <47944351+tsumon@users.noreply.github.com> Date: Thu, 24 Sep 2026 23:00:16 +0800 Subject: [PATCH] fix: skip degraded tool record for workflow tools (#7053) When a workflow tool is invoked from an AI chat node, the same execution writes two tool execution records: a detailed one (with details) persisted by ToolWorkflowPostHandler when the inner workflow completes, and a degraded duplicate (meta.input as JSON string, no execution details) saved unconditionally by save_tool_record while processing the ToolMessage. The inner workflow runs synchronously inside the tool call, so the detailed record is always persisted before the ToolMessage is processed. Skip the degraded duplicate for workflow-type tools; other tool types (e.g. custom tools converted to MCP servers) still rely on this record. --- apps/application/flow/tools.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/application/flow/tools.py b/apps/application/flow/tools.py index f1c678a5f8c..6bd534d5cf0 100644 --- a/apps/application/flow/tools.py +++ b/apps/application/flow/tools.py @@ -736,6 +736,11 @@ async def save_tool_record(tool_id, tool_info, tool_result, source_id, source_ty await sync_to_async(close_old_connections)() tool = await sync_to_async(lambda: QuerySet(Tool).filter(id=tool_id).first())() tool_info["icon"] = tool.icon + if tool.tool_type == ToolType.WORKFLOW: + # 工作流工具在内部工作流执行完成时,已由 ToolWorkflowPostHandler 落库一条含 details 的完整执行记录 + # (内部工作流是同步执行的,一定先于 ToolMessage 处理完成);此处再保存会产生一条 meta.input 为 JSON + # 字符串且无执行详情的重复降级记录(#7053),直接跳过。函数库等其他类型工具仍需要这条记录。 + return tool_record = ToolRecord( id=uuid.uuid7(), workspace_id=tool.workspace_id,