mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-19 06:45:50 +00:00
fix: normalizeMessagesForAPI 不再跨 tool_result 边界合并同 ID assistant 消息 (CC-1215)
ACP 模式下 extended thinking + tool_use 同一 turn 时,StreamingToolExecutor 在两个同 message.id 的 AssistantMessage 之间插入 tool_result,导致向后遍历 合并跨越边界,产生重复 tool_use ID → 孤立 tool_result → 连续 user 消息 → 400。 修改向后遍历停止条件:遇到非 assistant 消息(含 tool_result)即停止,不再跳过。
This commit is contained in:
@@ -2541,21 +2541,26 @@ export function normalizeMessagesForAPI(
|
||||
}
|
||||
|
||||
// Find a previous assistant message with the same message ID and merge.
|
||||
// Walk backwards, skipping tool results and different-ID assistants,
|
||||
// since concurrent agents (teammates) can interleave streaming content
|
||||
// blocks from multiple API responses with different message IDs.
|
||||
// Walk backwards, skipping different-ID assistants, since concurrent
|
||||
// agents (teammates) can interleave streaming content blocks from
|
||||
// multiple API responses with different message IDs.
|
||||
//
|
||||
// Do NOT skip tool_result messages — when claude.ts yields separate
|
||||
// AssistantMessages for thinking and tool_use blocks (same message.id),
|
||||
// a StreamingToolExecutor tool_result can land between them. Merging
|
||||
// across that boundary produces duplicate tool_use IDs that downstream
|
||||
// ensureToolResultPairing strips, leaving orphaned tool_results and
|
||||
// ultimately consecutive user messages → API 400 (CC-1215).
|
||||
for (let i = result.length - 1; i >= 0; i--) {
|
||||
const msg = result[i]!
|
||||
|
||||
if (msg.type !== 'assistant' && !isToolResultMessage(msg)) {
|
||||
if (msg.type !== 'assistant') {
|
||||
break
|
||||
}
|
||||
|
||||
if (msg.type === 'assistant') {
|
||||
if (msg.message.id === normalizedMessage.message.id) {
|
||||
result[i] = mergeAssistantMessages(msg, normalizedMessage)
|
||||
return
|
||||
}
|
||||
if (msg.message.id === normalizedMessage.message.id) {
|
||||
result[i] = mergeAssistantMessages(msg, normalizedMessage)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user