Repository navigation
feat(agents): opencode stops a task at its max_turns - #706
Open
canersoz-scaleai wants to merge 2 commits into
Open
canersoz-scaleai wants to merge 2 commits into
canersoz-scaleai wants to merge 2 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>
| project_id: str | None = None | ||
| task_id: str | None = None | ||
| timeout_seconds: int = Field(default=1800, gt=0) | ||
| # Tool calls a turn may make; see run_opencode. |
Collaborator
Author
There was a problem hiding this comment.
let's remove this comment, not necessary
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>
| project_id: str | None = None | ||
| task_id: str | None = None | ||
| timeout_seconds: int = Field(default=1800, gt=0) | ||
| # Steps, model requests, a turn may make; see run_opencode. |
Collaborator
Author
There was a problem hiding this comment.
the line of code is self explanatory. Remove the comment
This branch has not been deployed
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. Not run against the realopencode-aibinary.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; the previous final-answer cutoff is addressed.Summary
OpenCode now accepts
max_turnsthrough its Agent Card and passes it to the bridge.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Task supplies max_turns] --> B[Start OpenCode CLI] B --> C[Read finished model step] C --> D{Needs a step past the limit?} D -->|Yes| E[Kill CLI and fail task] D -->|No| F{Answer finished?} F -->|Yes| G[Return answer] F -->|No| CReviews (2) · Last reviewed commit: "fix(agents): opencode's max_turns counts..." · Reviewed by Greptile