fix: ACP 模式下 extended thinking + tool_use 触发连续 user 消息导致 400 (CC-1215)

This commit is contained in:
claude-code-best
2026-05-22 21:24:11 +08:00
parent f91060836f
commit b1c4f40f90
2 changed files with 102 additions and 4 deletions

View File

@@ -5829,11 +5829,15 @@ export function ensureToolResultPairing(
)
} else {
// Content is empty after stripping orphaned tool_results. We still
// need a user message here to maintain role alternation — otherwise
// the assistant placeholder we just pushed would be immediately
// followed by the NEXT assistant message, which the API rejects with
// a role-alternation 400 (not the duplicate-id 400 we handle).
// need a user message here to maintain role alternation — unless the
// previous result entry is already a user message, in which case
// inserting another user placeholder creates consecutive-user messages
// that Anthropic rejects with a misleading "tool_use without
// tool_result" 400 (CC-1215).
i++
if (result.at(-1)?.type === 'user') {
continue
}
result.push(
createUserMessage({
content: NO_CONTENT_MESSAGE,