fix(cli): prevent infinite loop on empty tool-calls (#7756)

When the model returns finish_reason "tool-calls" but emits zero tool call
parts, the prompt loop spins indefinitely. Detect this degenerate case in the
processor after the stream completes: if finish is "tool-calls" but no tool
parts exist, convert finish to "stop" so the loop's exit checks terminate
normally.
This commit is contained in:
Alex Alecu
2026-03-27 12:02:57 +02:00
parent a84edc3267
commit 05a82b37b8
@@ -443,6 +443,13 @@ export namespace SessionProcessor {
})
}
}
// kilocode_change start — guard empty tool-calls (#7756)
const empty = input.assistantMessage.finish === "tool-calls" && !p.some((part) => part.type === "tool")
if (empty) {
log.warn("empty tool-calls", { messageID: input.assistantMessage.id })
input.assistantMessage.finish = "stop"
}
// kilocode_change end
input.assistantMessage.time.completed = Date.now()
await Session.updateMessage(input.assistantMessage)
if (needsCompaction) return "compact"