Skip to content

Commit 1fa12f6

Browse files
authored
fix: resolve native tool protocol race condition causing 400 errors (#9363)
1 parent 67b6a8b commit 1fa12f6

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,11 @@ export async function presentAssistantMessage(cline: Task) {
280280
// Track if we've already pushed a tool result for this tool call (native protocol only)
281281
let hasToolResult = false
282282

283-
// Check if we're using native tool protocol (do this once before defining pushToolResult)
284-
const toolProtocol = resolveToolProtocol(cline.apiConfiguration, cline.api.getModel().info)
285-
const isNative = isNativeProtocol(toolProtocol)
283+
// Determine protocol by checking if this tool call has an ID.
284+
// Native protocol tool calls ALWAYS have an ID (set when parsed from tool_call chunks).
285+
// XML protocol tool calls NEVER have an ID (parsed from XML text).
286286
const toolCallId = (block as any).id
287+
const isNative = !!toolCallId
287288

288289
const pushToolResult = (content: ToolResponse) => {
289290
if (isNative && toolCallId) {
@@ -511,9 +512,9 @@ export async function presentAssistantMessage(cline: Task) {
511512
case "apply_diff": {
512513
await checkpointSaveAndMark(cline)
513514

514-
// Check if native protocol is enabled - if so, always use single-file class-based tool
515-
const applyDiffToolProtocol = resolveToolProtocol(cline.apiConfiguration, cline.api.getModel().info)
516-
if (isNativeProtocol(applyDiffToolProtocol)) {
515+
// Check if this tool call came from native protocol by checking for ID
516+
// Native calls always have IDs, XML calls never do
517+
if (isNative) {
517518
await applyDiffToolClass.handle(cline, block as ToolUse<"apply_diff">, {
518519
askApproval,
519520
handleError,

0 commit comments

Comments
 (0)