diff --git a/web/src/hooks/useChat.ts b/web/src/hooks/useChat.ts index 703dbe6..12468d6 100644 --- a/web/src/hooks/useChat.ts +++ b/web/src/hooks/useChat.ts @@ -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]