From d8642deec6ec53530da94046ab41f2f69185ae68 Mon Sep 17 00:00:00 2001 From: "kiloconnect[bot]" <240665456+kiloconnect[bot]@users.noreply.github.com> Date: Wed, 6 May 2026 14:59:51 +0000 Subject: [PATCH] fix(cli): persist defaulted finish reason so loop break check sees it The loop reloads messages from storage at the top of each iteration via filterCompactedEffect, so an in-memory mutation on handle.message does not propagate. Persist the defaulted finish via updateMessage so the next iteration's break check actually observes it. --- packages/opencode/src/session/prompt.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index 967db90dcb0..5d79e000645 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -1603,11 +1603,16 @@ NOTE: At any point in time through this workflow you should feel free to ask the // 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" + // a finishReason, the loop-exit check at the top of the next iteration + // sees a falsy `finish` (loaded from storage via filterCompactedEffect) + // and keeps stepping forever. Default to "unknown" and persist so the + // regular break condition fires when there are no tool calls — the + // tool-call path is unaffected because `!hasToolCalls` keeps the break + // gated when the assistant did emit tool calls. + if (!handle.message.finish) { + handle.message.finish = "unknown" + yield* sessions.updateMessage(handle.message) + } // kilocode_change end if (structured !== undefined) {