fix(opencode): gate step-cap assistant message behind maxStepsMessage config#32546
Open
kevinfaveri wants to merge 3 commits into
Open
fix(opencode): gate step-cap assistant message behind maxStepsMessage config#32546kevinfaveri wants to merge 3 commits into
kevinfaveri wants to merge 3 commits into
Conversation
Contributor
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
… STEPS REACHED message
a693931 to
8f659dd
Compare
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Fixes #32548
Type of change
What does this PR do?
When an agent hits its step cap, the prompt loop appends an assistant-role message with the "MAXIMUM STEPS REACHED" text. This ends the request on an assistant turn, which counts as a response prefill. Claude models with thinking enabled reject prefills with HTTP 400.
From Anthropic's extended thinking docs, Feature compatibility: "You can't pre-fill responses when thinking is enabled."
I ran into this with bounded subagents in opencode-fusion. Any agent hitting the step cap on a thinking-enabled Claude model gets the same 400.
The fix adds a
maxStepsMessageboolean to agent config. Defaults totrue, so existing behavior is unchanged. When set tofalse, the trailing assistant message is not appended.Three files:
packages/core/src/v1/config/agent.ts(schema + KNOWN_KEYS)packages/opencode/src/agent/agent.ts(runtime field + mapping, defaultstrue)packages/opencode/src/session/prompt.ts(gate:isLastStep && agent.maxStepsMessage !== false)Important: this relates to many open issues like #13768 and #27920. However, those issues are more broad and don't involve a specific plugin usage (which can happen in scenarios with other plugins or local harness setup using structured outputs or max tools being very limited).
I choose to simply add a possibility that agents can be configured in any way the user want WHEN max steps are reached, avoiding taking any opinion on how it should be handled globally or not (e.g. don't affect the primary model at all). However, if you force your primary model to always call an agent, you could use this new feature to enforce removal of trailling message to fix the above issues OR alternatively you can set all built in agents opencode has to false on this new property so that it don't do message trailling that is what is problematic.
Note: Since plugins can access and set the config for specific agents they can create / dispatch, the idea is that I will use this so that opencode-fusion detects if its a claude 4.6+ model and then disable trailling message on the panel and/or judge.
Note 2, to reinforce: this PR is focused specifically on the edge case of when it reaches max steps, it appends a trailling message that is problematic with thinking on models.
How did you verify your code works?
Config test in
test/agent/agent.test.ts: default resolves totrue, explicitfalseresolves tofalse. Prompt loop tests intest/session/prompt.test.ts: default appends the message,maxStepsMessage: falseomits it. Full suites pass locally.turbo typecheckpasses all 23 packages. Build compiles on bun 1.3.14.Checked with my own https://github.com/kevinfaveri/opencode-fusion plugin by setting editing its code to, when setting the unbounded agent that I use for panels and judge to set this maxStepsMessage to false. After this is merged, I will follow up with an updated version of opencode-fusion and edit the Readme.MD there to account for the new setting.
It is very easy to validate locally, by the way, if you want to double check: just set all your agents (built in like build/plan to steps: 1 and set the max steps message to false, which will make it work. Omit (current behavior) or set to true and it will fail loudly). Attached issue has example export et al.
Screenshots / recordings
No UI change.
Checklist