Repository navigation
opencode: configurable output-token cap and a clear error at the cap - #885
Merged
Merged
Conversation
opencode caps each model request at 32,000 output tokens unless told otherwise, and the bridge's model entry declares no limit. Reasoning models at high effort spend most of that on reasoning, the last step ends with reason "length", and the turn failed with the uninformative "opencode exited with code 0 without completing". Add an optional max_output_tokens to the agent-config. When set, the bridge puts limit.output on the generated model entry and sets OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX for the CLI, since opencode uses the smaller of the two. Unset keeps today's behaviour. When a turn doesn't complete and its last step stopped for "length", fail with error_code output_token_limit and a message giving the step's reasoning and text token counts. Error events still take precedence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The opencode agent's max_output_tokens setting had no caller: prompt_agent sends a fixed set of agent-config fields, and negotiation drops the rest, so a task could not raise opencode's output-token cap. Add max_output_tokens to prompt_agent and always_on the way max_thinking_tokens is plumbed: a user-scoped step field, round-tripped through to_dict/from_dict, replaced by a run's agent_max_output_tokens override, and sent in the agent config. Only agents whose card accepts the field receive it. The opencode cap error now points at the prompt_agent step's field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale
approved these changes
Nov 23, 2026
Keeps both new _build_config keyword args: max_output_tokens from this branch and armed from main's clock fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
opencode caps each model request at 32,000 output tokens, reasoning included. Reasoning models at high effort (e.g. muse-spark-1.3 at xhigh) hit that cap mid-answer: the last step ends with reason "length" and the run fails with the uninformative "opencode exited with code 0 without completing".
This adds a
max_output_tokensfield onprompt_agentandalways_onsteps, plus a run overrideagent_max_output_tokens, that reaches the opencode agent's config. There it sets both the model'slimit.outputandOPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX, because opencode uses the smaller of the two. Unset keeps today's behaviour, and agents whose card doesn't accept the field never receive it. A turn whose last step stopped at the cap now fails withoutput_token_limitand its reasoning/text token counts. Retry behaviour is unchanged.Validation: new tests plus the opencode suite pass (170). The only failures in the task-step, bundle and task suites (
computer_exec_test.py, macOSbase64flags) also fail on main. Setting the env var alone to 64000 was verified on a copy of an affected prod task (3/3 runs completed); no real opencode run with this branch yet.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no actionable defects were established.Summary
Adds
max_output_tokenstoprompt_agentandalways_on, with anagent_max_output_tokensrun override.No actionable issues were found. Tests were inspected, not run. The full PR was reviewed because the previous and current commits have different merge bases with the target.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A["Step setting or run override"] --> B["Agent Card filters fields"] B --> C["OpenCodeConfig.max_output_tokens"] C --> D["Model limit.output"] C --> E["OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX"] F["Last step ends with length"] --> G["output_token_limit and token counts"]Reviews (2) · Last reviewed commit: "Merge origin/main into pratyush/opencode..." · Reviewed by Greptile