mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-24 16:02:55 +08:00
fix(cli): prevent agent loop hang when stream ends without stop_reason
Some Anthropic-compatible providers terminate the response stream with a final message_delta that carries stop_reason: null followed immediately by message_stop. The AI SDK then never sets a finishReason on the assistant message, the prompt loop's break check stays false, and the agent keeps issuing new model calls indefinitely. Default the missing finish to "unknown" so the existing exit condition fires when no tool calls were emitted.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@kilocode/cli": patch
|
||||
---
|
||||
|
||||
Prevent an infinite agent loop when a provider ends the response stream without a terminal stop reason.
|
||||
@@ -1600,6 +1600,16 @@ NOTE: At any point in time through this workflow you should feel free to ask the
|
||||
toolChoice: format.type === "json_schema" ? "required" : undefined,
|
||||
})
|
||||
|
||||
// kilocode_change start - guard against providers that end the stream
|
||||
// without a terminal stop_reason (e.g. an Anthropic-style message_delta
|
||||
// with stop_reason: null followed immediately by message_stop). Without
|
||||
// a finishReason, the loop-exit check below sees a falsy `finish` and
|
||||
// keeps stepping forever. Default to "unknown" so the regular break
|
||||
// condition fires when there are no tool calls, while still allowing
|
||||
// the loop to continue when tool calls were emitted.
|
||||
handle.message.finish = handle.message.finish ?? "unknown"
|
||||
// kilocode_change end
|
||||
|
||||
if (structured !== undefined) {
|
||||
handle.message.structured = structured
|
||||
handle.message.finish = handle.message.finish ?? "stop"
|
||||
|
||||
Reference in New Issue
Block a user