Skip to content

opencode: configurable output-token cap and a clear error at the cap - #885

Merged
psinghal20 merged 3 commits into
mainfrom
pratyush/opencode-max-output-tokens
Nov 23, 2026
Merged

psinghal20 merged 3 commits into
mainfrom
pratyush/opencode-max-output-tokens

Conversation

@psinghal20

@psinghal20 psinghal20 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

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_tokens field on prompt_agent and always_on steps, plus a run override agent_max_output_tokens, that reaches the opencode agent's config. There it sets both the model's limit.output and OPENCODE_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 with output_token_limit and 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, macOS base64 flags) 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

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable defects were established.

Summary

Adds max_output_tokens to prompt_agent and always_on, with an agent_max_output_tokens run override.

  • Tasks can set OpenCode’s per-request output-token limit.
  • OpenCode reports a named error when a turn ends at its output-token cap.

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"]
Loading

Reviews (2) · Last reviewed commit: "Merge origin/main into pratyush/opencode..." · Reviewed by Greptile

psinghal20 and others added 2 commits November 23, 2026 19:28
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>
@psinghal20
psinghal20 requested a review from a team as a code owner November 23, 2026 14:54
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>
@psinghal20
psinghal20 merged commit a1a39ad into main Nov 23, 2026
60 of 63 checks passed
@psinghal20
psinghal20 deleted the pratyush/opencode-max-output-tokens branch November 23, 2026 17:03
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.

2 participants