Skip to content

feat(opencode): cap the build agent's steps with max_steps - #5716

Open
gwarmstrong wants to merge 4 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/opencode-session-compaction
Open

gwarmstrong wants to merge 4 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/opencode-session-compaction

Conversation

@gwarmstrong

@gwarmstrong gwarmstrong commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

opencode_agent gets max_steps, the step cap of OpenCode's build agent (agent.build.steps). It is unset by default and works in both execution modes. Other agents take their step budget from a top-level max_steps (simple_agent, finance_agent, browsecomp_agent and others), so a benchmark that compares harnesses can set it the same way for OpenCode.

  • max_steps writes agent.build.steps in local runs and in agent sessions. It replaces a value set in opencode_config.agent.build.steps. In a session it joins the request sampling and the replaced prompt on the build agent.
  • The step-limit check behind metadata.harness_step_limit_reached reads the cap from the launched config, so it applies max_steps too.
  • README: drops the sentence saying a session with token capture refuses agent.build.steps. Since fix(token_capture): keep capture chains through OpenCode's step-limit note and tool-name repair #5833, token capture keeps the calls after OpenCode's step-limit note chained, and the paragraph below it already says so.

Narrowed since the first version. This PR used to let sessions set compaction as well. Main's #5719 now admits compaction.auto and agent.build.steps in a session's opencode_config, so that part is gone, along with its tests. compaction.prune: false, which opencode_sandboxed_agent's benchmark profile also sets, needs no change: OpenCode 1.17.11 prunes old tool outputs only when compaction.prune is true (SessionCompaction.prune returns early otherwise).

No issue: a small option for the harness comparisons in #5552.

Validation

At the head (main merged 2026-11-16):

  • gym env test +entrypoint=responses_api_agents/opencode_agent: 1005 passed, 1 skipped, 1 failed. The failure, test_the_plugin_registers_its_hooks_and_acts_on_them, comes from the host's default Node 19: with Node 22 on PATH, tests/test_opencode2_session.py passes (20 passed). It does not touch this change.
  • New test test_max_steps_is_the_step_limit_the_response_reports: with max_steps alone, and with a larger configured agent.build.steps, a prompt that made 3 model calls at a cap of 3 is marked; a cap of 4 over a configured 2 is not. The launched config carries max_steps in each case. The four earlier max_steps tests cover the session and local configs and reject a non-positive cap.
  • pre-commit run on the changed files: clean. DCO sign-off.

Rollouts

Host path at 1d2a3a1, OpenCode 1.17.11, nvidia/nemotron-3-nano-30b-a3b through inference-api. One task: three file writes with separate tool calls, a directory listing, then DONE. The max_steps code has not changed since.

Configuration Tool calls Final answer Root status
defaults write, write, write, bash DONE completed
compaction: {auto: false, prune: false}, max_steps: 400 write, write, write, bash DONE completed
max_steps: 1 none "Maximum steps reached. No actions completed. …" completed

OpenCode accepts the cap and stops at it.

Compatibility

Opt-in only. Existing configs and results are unchanged.

The sandboxed OpenCode agent (opencode_sandboxed_agent) runs OpenCode
1.17.11 with compaction {auto: false, prune: false} and 400 build-agent
steps. A session of opencode_agent accepted only permission and tools in
opencode_config, so the same benchmark kept OpenCode's default
compaction and step limit there, and the two agents were not comparable.

- Session opencode_config also accepts compaction, which OpenCode reads
  for automatic compaction and tool-output pruning.
- max_steps (unset by default) writes agent.build.steps in both
  execution modes. In a session it joins the request sampling and the
  replaced prompt on the build agent rather than overwriting them.

Defaults are unchanged.

Signed-off-by: gwarmstrong <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@gwarmstrong
gwarmstrong requested a review from yaoyu-33 November 6, 2026 00:31
@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:agent Agent harnesses and Responses API agent behavior needs-review PR is ready for code review and waiting on a reviewer labels Nov 7, 2026
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 9, 2026
Main (NVIDIA-NeMo#5719, NVIDIA-NeMo#5833) now lets a session's opencode_config set
compaction.auto and agent.build.steps, through
_session_opencode_config_error. That validator replaces this branch's
permission/tools/compaction allowlist, so a session still refuses
compaction.prune, which rewrites old tool output and breaks the token
prefix. max_steps stays: it sets agent.build.steps in both execution
modes, over any value in opencode_config. The session test now uses
compaction {auto: false} and checks that max_steps replaces a configured
agent.build.steps.

Signed-off-by: gwarmstrong <[email protected]>
@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test e149fcc

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 12, 2026 18:36
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

… reports

Main's NVIDIA-NeMo#5719 already admits compaction.auto and agent.build.steps in a
session's opencode_config, so this PR keeps only max_steps. The new test
covers the step-limit metadata with max_steps alone and over a configured
agent.build.steps. The README no longer says a session with token capture
refuses agent.build.steps: since NVIDIA-NeMo#5833, token capture keeps the calls after
OpenCode's step-limit note chained.

Signed-off-by: gwarmstrong <[email protected]>
@gwarmstrong gwarmstrong changed the title feat(opencode): let agent sessions turn off compaction and cap steps feat(opencode): cap the build agent's steps with max_steps Nov 16, 2026
@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test d51936a

@yaoyu-33 yaoyu-33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the effective sandbox configuration for both OpenCode versions.

else:
config["instructions"] = [f"{state.session.session_dir}/instructions.md"]
if self.config.max_steps is not None:
config.setdefault("agent", {}).setdefault("build", {})["steps"] = self.config.max_steps

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sets the cap in the v1 sandbox launcher. In a v2 session with only max_steps=3, _opencode2_launch still receives the original opencode_config, so the launched config has no step limit and the response has no threshold to report. With nested steps=9, v2 uses 9. Could both launchers use the same effective build settings and cover these two v2 cases?

@github-actions github-actions Bot removed the sla:review-overdue Review response is over the one-business-day SLA label Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants