Skip to content

Forced max-steps summary prompt (CRITICAL - MAXIMUM STEPS REACHED) degenerates reasoning models #67735

Backlog

Description

@jucajuca

Description

Summary

On the final agent step, OpenCode removes all tools and injects the user message CRITICAL - MAXIMUM STEPS REACHED … Tools are disabled until next user input. Respond with text only … Any attempt to use tools is a critical violation. For a reasoning model on a ~63k-token context, this request reliably degenerates into a run-on/emoji-soup completion instead of a summary.

Suggestion: Rewrite the final-step message as a normal instruction, e.g. "You've reached the step limit. Briefly summarize what you did and what's left, in the user's language." Drop the "critical violation" framing.

Repro (observed in production)

Session had 14 tool-call steps since the last user message; step 15 was the forced summary.
Request: prompt_tokens 63,293, completion_tokens 4,373 (text 1,444 + reasoning 2,929).
Output: 5,358-char German run-on, 0 punctuation per 1k chars, unique-word ratio 0.30, repeated-3-gram ratio 0.33; reasoning 10,556 chars with wait ×11 / hmm ×10.
Sandbox replay with the exact context + exact prompt: 1/8 hard degeneration (emoji/symbol soup tail). The same context without that prompt is fine.

Expected: a normal text summary (or an empty/partial one, retried). Actual: degenerate repetition, no usable summary, user aborts.

Suspected cause

The all-caps threat framing (CRITICAL, "override ALL other instructions", "critical violation") plus sudden tool removal is an adversarial/distribution-shift prompt.
The model is asked to summarize a confused 14-step loop without tools, in one shot.
No validation of the final-step output (empty content, no punctuation, repeated n-grams, emoji runs, finish_reason=length with no content).

Environment

OpenCode 2.2.5 (opencode/latest/2.2.5/cli)
Model zai-org/GLM-5.3-Flash via LiteLLM → vLLM (reasoning model, 65,536 max output)
Agent build, default steps (15)

Suggested fixes

Rewrite the final-step message as a normal instruction, e.g. "You've reached the step limit. Briefly summarize what you did and what's left, in the user's language." Drop the "critical violation" framing.
Prefer tool_choice: "none" over removing tools (or expose a dedicated summarize tool) — sudden tool-schema removal is part of the shift.
Validate the final-step response and retry once with a simpler prompt if it's empty/degenerate (low unique-word ratio, no punctuation, repeated lines, emoji/symbol runs).
Document/raise the default steps (15) and make clear that a new user message resets the allowance.
Add an explicit "do not repeat yourself / answer in the user's language" hint.

Related: #28074

Plugins

No response

OpenCode version

2.2.5

Steps to reproduce

No response

Screenshot

No response

Operating System

Ubuntu 24

Terminal

No response

Activity

  1. opencodejr commented on Dec 2, 2026

    @opencodejr
    Contributor

    Thanks. Maintainers will consider rewording the step-limit prompt and checking or retrying a degenerate final summary. I can't promise a change or a timeline.

    In the code I read, two of your suggestions are already how it works. The final step keeps the tool definitions and sends toolChoice: "none". The limit only applies when your agent config sets steps, so check where your 15 comes from (the docs also say that new user input resets the allowance). Until then, a plugin's context hook can rewrite the request messages, so you could replace the prompt text yourself.

  2. added
    area/core
    type/feature
    version/v2
    on Dec 2, 2026
  3. jucajuca commented on Dec 2, 2026

    @jucajuca
    Author

    Thanks for the quick reply. Two things in our reproduction don't match the current description, plus one new data point.

    1. On the final step the tool schemas appear to be dropped, not just toolChoice: "none".

    We replayed the failing session (v2.2.5, same build agent system prompt, 13 tools) and measured rendered prompt size with the same tokenizer:

    • system + context + 13 tool schemas: 68,031 tokens
    • same, no tools: 64,406 tokens
    • same, no tools, without the compaction summary: 63,432 tokens
    • the real failing request (LiteLLM spend log): 63,293 tokens

    63,293 is 1,113 below the no-tools rendering (consistent with OpenCode truncating large tool outputs) and 4,738 below the with-tools rendering — roughly the size of the 13-schema tool block. So at least in this capture the final request looks like it had no tools at all. We can't dump the exact outgoing body from that historical session retroactively, so this is inferential, but the delta lines up with the tool block.

    2. The 15-step cap fired even though no steps was configured.

    ~/.config/opencode/opencode.json had agents with only reviewer and title, neither carrying steps or maxSteps. Counting the session: last user message -> 14 assistant steps with tool calls -> step 15 is the forced text-only one. So an effective default of 15 is being applied somewhere. If that's intended, documenting it would help; if not, that may be the part worth looking at. (I've since set steps: 50 explicitly on all agents as a workaround.)

    3. The degeneration is also decoding-config sensitive (context, not an ask).

    On our route, LiteLLM was injecting frequency_penalty: 0.2 + presence_penalty: 0.1. With those, the replay degenerated 1/8 and structured code generation failed 0/3. After removing just those two penalties, the identical replay had 0/8 hard failures and code passed 3/3. So the prompt is the trigger, but the sampling penalties turned a near-miss into garbage here. Worth keeping in mind when trying to reproduce.

    Suggestion stands: validate the final-step response and retry once if it is empty/degenerate (finish_reason=length with no content, no punctuation, repeated n-grams, emoji/symbol runs). Making the prompt configurable (#28074) would also let affected users work around it without a plugin.

    Environment: opencode v2.2.5, Linux (Ubuntu 24.04), model zai-org/GLM-5.3-Flash via LiteLLM -> vLLM (reasoning model, 65,536 output cap), agent build.

    Related: #28074

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreplatform/linuxtype/featureversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions