Skip to content

llm.ts: V2 runner dropped V1's 'last step' signal — AI never warned to finalize work #30866

@LifetimeVip

Description

@LifetimeVip

Description

File: packages/core/src/session/runner/llm.ts:256

V1 (packages/opencode/src/session/prompt.ts:1349-1350,1461) sends max-steps.txt (which says "CRITICAL - MAXIMUM STEPS REACHED. Do NOT make any tool calls. Respond with text only.") as an assistant message on the last step:

const maxSteps = agent.steps ?? Infinity
const isLastStep = step >= maxSteps
// L1461:
messages: [...modelMsgs, ...(isLastStep ? [{ role: "assistant", content: MAX_STEPS }] : [])],

V2 has no equivalent. The AI is never told "this is your last turn." On step 24 (the actual last step), the AI creates tool calls that will never be settled — the session terminates right after. This compounds with bug #3 (hard MAX_STEPS cutoff) to waste the final turn entirely.

Fix: Before the last iteration, inject the max-steps.txt content as a system message.

OpenCode version

v1.16.0 (commit 3cf1cef)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions