Repository navigation
feat(agents): opencode stops a task at its max_turns - #706
Merged
canersoz-scaleai merged 4 commits intoNov 16, 2026
Merged
canersoz-scaleai merged 4 commits into
canersoz-scaleai merged 4 commits into
Conversation
OpenCodeConfig had no max_turns, so prompt_agent's negotiation dropped the field and an OpenCode task ran without a step cap. The CLI has no limit it enforces: its agent `steps` only asks the model to stop. The bridge now counts the task's finished tool calls as the CLI prints them, kills the CLI once max_turns have finished, and fails the task with Claude Code's and codex's "Reached maximum number of turns (N)". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A turn is one model request, an OpenCode step, as Claude Code's --max-turns counts them; a step's parallel tool calls are one turn, which counting tool calls charged as several. The limit is now decided at a step's end: the turn fails once more steps than max_turns finished, or the last one it allows asked for another. Before, a turn that answered right after its last allowed tool call passed or failed depending on whether its final step_finish came in the same stdout read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale
approved these changes
Nov 16, 2026
canersoz-scaleai
enabled auto-merge (squash)
November 16, 2026 23:15
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.
What and why
A task's
max_turnsnever reached the OpenCode agent:OpenCodeConfighad no such field, soprompt_agent's negotiation dropped it and OpenCode ran uncapped. OpenCode v1's ownstepslimit can't stand in: it only asks the model to stop and still sends every tool, which upstream confirmed and won't fix in v1 (anomalyco/opencode#54806, #55921). We pin v1 (1.17.18).OpenCodeConfignow takesmax_turns, and the bridge counts the task's steps (OpenCode's model requests, from itsstep_finishevents) as Claude Code's--max-turnscounts turns. Once the last allowed step asks for another, the bridge kills the CLI and fails the task withReached maximum number of turns (N), the message Claude Code and codex use. Parallel tool calls in one step count as one turn. The limit is decided when a step ends, so how the CLI's output splits across reads can't change the outcome.How it was tested
pytest tst/unit/agents/opencode: 137 passed, 7 skipped (existing Linux/GNU-tar-only skips);ruff checkclean. The new tests cover the limit under four ways of splitting stdout into reads, parallel tool calls, negotiation against the real card, and a real subprocess that must be killed.End to end with the real
opencode-ai1.17.18 CLI: I ran AgentEnvHub locally (hub backend, Temporal, workflow and activity workers) against the dev database, with this PR's OpenCode agent built and registered as a test agent and run in a local Docker sandbox. The prompt forced one shell command per step (echo 17, add 5, double it, reply with the result).max_turns: 2: the run failed withReached maximum number of turns (2). Its trajectory has two steps, both ending intool-calls, and no third step started; noopencodeprocess was left in the container.max_turns: 10: the same prompt completed with44after four steps, the last ending instop.The local hub and workers ran the release scaleapi pins (0.9.1357) with this PR's
agents/opencode/folder in place, since the agent folder is its own build context.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no new actionable issue was established.Summary
OpenCode now accepts
max_turnsand counts finished model steps. When the last allowed step requires another, the bridge kills the CLI and fails the task with the shared limit message.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A["Task configuration: max_turns"] --> B["Run OpenCode"] B --> C["Read step_finish events"] C --> D{"Allowed steps exhausted<br/>and another step needed?"} D -- No --> E["Continue or return answer"] D -- Yes --> F["Kill CLI and child processes"] F --> G["Fail task with turn-limit message"]Reviews (7) · Last reviewed commit: "Merge branch 'main' into canersoz/openco..." · Reviewed by Greptile