Skip to content

fix(cli): send max-step instruction as user message - #13301

Merged
chrarnoldus merged 5 commits into
mainfrom
fix/max-steps-user-message
Aug 21, 2026
Merged

fix(cli): send max-step instruction as user message#13301
chrarnoldus merged 5 commits into
mainfrom
fix/max-steps-user-message

Conversation

@chrarnoldus

Copy link
Copy Markdown
Collaborator

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.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
@chrarnoldus chrarnoldus self-assigned this Aug 21, 2026
.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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kilo-code-bot

kilo-code-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • packages/llm/src/protocols/anthropic-messages.ts
  • packages/llm/src/protocols/bedrock-converse.ts
  • packages/llm/src/protocols/gemini.ts
  • packages/llm/src/protocols/shared.ts
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)
  • packages/llm/src/protocols/anthropic-messages.ts
  • packages/llm/src/protocols/bedrock-converse.ts
  • packages/llm/src/protocols/gemini.ts
  • packages/llm/src/protocols/shared.ts

Previous review (commit 705f6b7)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (7 files)
  • packages/llm/src/protocols/anthropic-messages.ts
  • packages/llm/src/protocols/bedrock-converse.ts
  • packages/llm/src/protocols/gemini.ts
  • packages/llm/test/provider/anthropic-messages.test.ts
  • packages/llm/test/provider/bedrock-converse.test.ts
  • packages/llm/test/provider/gemini.test.ts
  • packages/opencode/test/session/prompt.test.ts

Previous review (commit 43c4491)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/core/src/session/runner/llm.ts 212 Trailing user max-step instruction can produce consecutive Anthropic user turns
Files Reviewed (5 files)
  • .changeset/fix-max-steps-prefill.md - 0 issues
  • packages/core/src/session/runner/llm.ts - 1 issue
  • packages/core/test/session-runner.test.ts - 0 issues
  • packages/opencode/src/session/prompt.ts - 0 issues
  • packages/opencode/test/session/prompt.test.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 67.8K · Output: 7.3K · Cached: 213.6K

Review guidance: REVIEW.md from base branch main

chrarnoldus and others added 2 commits August 21, 2026 07:41
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
chrarnoldus and others added 2 commits August 21, 2026 08:44
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
@chrarnoldus
chrarnoldus merged commit f958a5a into main Aug 21, 2026
33 checks passed
@chrarnoldus
chrarnoldus deleted the fix/max-steps-user-message branch August 21, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants