fix: 子智能体工具消息去重改为按 id+type,修复工具状态卡在执行中

后端为同一次工具调用的 tool_call/tool_result/tool_pending 生成相同的 id(= tool_call_id),上一提交的去重逻辑仅按 id 判断,导致 tool_result 被 tool_call 误判为重复而跳过,App.tsx 合并逻辑收不到 tool_result,工具永远停留在 calling 状态。

改为按 id + type 去重:同类型消息不会重复(解决 load_task_messages 并发重复),不同类型消息(tool_call vs tool_result)不会被误伤(修复工具状态卡死)。

同时修复 appendToSubAgentViewMessage 和 appendToSubAgentLayerMessage 两处。
This commit is contained in:
oudecheng 2026-07-07 11:22:48 +08:00
parent bde55cbf14
commit 6df87fe399

View File

@ -387,8 +387,10 @@ export function useChat(): UseChatReturn {
return newStack
}
} else if (message.type === 'tool_call' || message.type === 'tool_result' || message.type === 'tool_pending') {
// 按 id 去重,避免 load_task_messages 并发调用导致重复
const exists = top.messages.some(m => m.id === chatMsg.id)
// 按 id + type 去重,避免 load_task_messages 并发调用导致重复。
// 注意:后端为同一次工具调用的 tool_call/tool_result/tool_pending 生成相同的 id= tool_call_id
// 仅按 id 去重会误伤 tool_result导致工具永远停留在 calling 状态。
const exists = top.messages.some(m => m.id === chatMsg.id && m.type === chatMsg.type)
if (exists) return prev
}
const newStack = [...prev]
@ -464,7 +466,8 @@ export function useChat(): UseChatReturn {
return newStack
}
} else if (message.type === 'tool_call' || message.type === 'tool_result' || message.type === 'tool_pending') {
const exists = layer.messages.some(m => m.id === chatMsg.id)
// 按 id + type 去重(同上,三者共享 id必须加 type 区分)
const exists = layer.messages.some(m => m.id === chatMsg.id && m.type === chatMsg.type)
if (exists) return prev
}
const newStack = [...prev]