Skip to content

opencode_env: run setup before the agent, skip verify on non-zero agent exit - #1023

Open
sergiopaniego wants to merge 3 commits into
huggingface:mainfrom
sergiopaniego:opencode-harness-usability-fixes
Open

opencode_env: run setup before the agent, skip verify on non-zero agent exit#1023
sergiopaniego wants to merge 3 commits into
huggingface:mainfrom
sergiopaniego:opencode-harness-usability-fixes

Conversation

@sergiopaniego

@sergiopaniego sergiopaniego commented Jul 30, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Two usability fixes to opencode_env's run_rollout, from review on #999.

  • Setup no longer races the agent. run_rollout ran the setup commands after create(), which had already started the agent, so setup and the agent raced over the workspace. create() now takes start_agent (default True, so the loop-owning training path that calls create() directly is unchanged). The server passes start_agent=False, runs setup, then calls session.start_agent(), giving the correct setup then agent then verify order.
  • A failed agent is no longer scored. A non-zero agent_exit_code is now treated like a timeout (sets result.error), so verify and reward are skipped for a crashed agent.

The same fix for pi_env is on #999.

AI-assisted.


Note

Medium Risk
Changes rollout ordering and reward gating for the MCP server path; default create() behavior is preserved but scoring semantics change when the agent crashes.

Overview
run_rollout now runs setup before the OpenCode agent starts, instead of racing the agent over the workspace. OpenCodeSessionFactory.create() gains a start_agent flag (default True so direct training callers are unchanged); the MCP server uses start_agent=False, runs per-command setup, then calls session.start_agent().

Failed agent runs are no longer scored. A non-zero agent_exit_code sets result.error (like timeouts), so verify and reward are skipped for a crashed agent.

The agent launch shell command adds set -o pipefail so failures in the opencode run | tee pipeline surface as a non-zero exit. Factory lifecycle tests accept the new start_agent parameter on mocked _create_once.

Reviewed by Cursor Bugbot for commit 988f672. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI review requested due to automatic review settings July 30, 2026 10:23

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Comment thread envs/opencode_env/server/opencode_environment.py
run_rollout ran setup after create() had already started the agent, so setup
raced the agent over the workspace. create() now takes start_agent (default
True, so the loop-owning training path is unchanged), the server passes
start_agent=False, runs setup, then calls session.start_agent(), giving the
correct setup then agent then verify order. A non-zero agent exit is now
treated like a timeout, so a crashed agent no longer runs verify or earns a
reward.

AI-assisted.
Copilot AI review requested due to automatic review settings July 30, 2026 10:43
@sergiopaniego
sergiopaniego force-pushed the opencode-harness-usability-fixes branch from 9975794 to e7aadc8 Compare July 30, 2026 10:43

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e7aadc8. Configure here.

_emit(f"setup FAILED at [{i}]: exit={cr.exit_code}")
break

# Block until the agent is done (or setup already failed).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Timeouts ignore sequential setup cost

Medium Severity

Deferring the agent until after setup makes wall-clock time setup + agent instead of overlapping them, but sandbox lifetime stays agent_timeout_s + 300 and the MCP tool cap stays 900s. With default agent_timeout_s=600 and SETUP_TIMEOUT_S=300, longer setups can kill the sandbox or trip the tool timeout before the agent finishes.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e7aadc8. Configure here.

Without it the run pipeline reports tee's exit code (0), so a non-zero
opencode exit is masked and the failed-agent guard never fires. Matches
the pi runtime, which already sets pipefail.
Copilot AI review requested due to automatic review settings July 30, 2026 11:04

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 31, 2026 07:25

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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