fix(cli): send max-step instruction as user message - #13301
Conversation
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
| .filter((part): part is string => part !== undefined && part.length > 0) | ||
| .map(SystemPart.make), | ||
| messages: [...toLLMMessages(context, model), ...(isLastStep ? [Message.assistant(MAX_STEPS_PROMPT)] : [])], | ||
| messages: [...toLLMMessages(context, model), ...(isLastStep ? [Message.user(MAX_STEPS_PROMPT)] : [])], // kilocode_change - avoid provider-incompatible assistant prefill |
There was a problem hiding this comment.
WARNING: Trailing user message can produce consecutive Anthropic user turns
Native Anthropic/Bedrock lowering maps tool results to role: "user" and does not merge a following user message. On the last step after tools this becomes [assistant tool_use, user tool_result, user MAX_STEPS]; with steps: 1 it is [user prompt, user MAX_STEPS]. Anthropic Messages requires alternating roles, so this can 400 the thinking models this PR is trying to unblock.
Suggestion: if the last converted message is already user (or will lower as user, i.e. tool results), append MAX_STEPS_PROMPT onto that message instead of pushing a new one.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
There was a problem hiding this comment.
Addressed in 1663c27. Anthropic, Bedrock, and Gemini lowering now coalesces adjacent user-compatible blocks, including a tool result followed by the max-step instruction, and focused provider tests cover that request shape.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (4 files)
Previous Review Summaries (3 snapshots, latest commit 406c191)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 406c191)Status: No Issues Found | Recommendation: Merge Files Reviewed (4 files)
Previous review (commit 705f6b7)Status: No Issues Found | Recommendation: Merge Files Reviewed (7 files)
Previous review (commit 43c4491)Status: 1 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (5 files)
Reviewed by grok-4.6 · Input: 67.8K · Output: 7.3K · Cached: 213.6K Review guidance: REVIEW.md from base branch |
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
What changed
Send the final max-step summary instruction as a synthetic user message in both session runtimes instead of appending it as assistant output. Add request-shape regression coverage for both paths.
Why
An assistant message at the end of a request is interpreted as response prefill. Providers that do not support assistant prefill, including Anthropic models with thinking enabled, reject the final step instead of letting the agent summarize its work. A user message correctly represents the instruction and keeps the request compatible across providers.