Skip to content

fix(opencode): keep sandbox-reported errors over export errors - #6175

Merged
yaoyu-33 merged 2 commits into
mainfrom
ananthsub/opencode-timeout-error-precedence
Nov 16, 2026
Merged

yaoyu-33 merged 2 commits into
mainfrom
ananthsub/opencode-timeout-error-precedence

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What changed

The OpenCode sandboxed agent now keeps the sandbox's error type when the session export also holds an error.

When the sandbox stops an OpenCode run at its deadline, the exec result reports error_type="timeout". The session export can hold an error on its last assistant message as well: the model request that the stop aborted. The agent copied that export error into opencode_error_type whenever it had no run error of its own, so the result named the export error instead of timeout. Rules that match opencode_error_type == "timeout", such as masking rollouts that ran out of time, then missed those rollouts, and so did Gym's own rollout health timeout report, which reads the same opencode_error_type signal.

A sandbox-reported error now outranks the export's terminal error. In practice that error is the exec timeout: an out-of-memory kill raises at exec, and the agent rejects every other sandbox error type before it reads the export. When the sandbox reports no error type, the export error still classifies the failure, as before.

Sandbox provider

The original fix also changed the OpenSandbox provider to report a server-side command timeout as a timeout. This PR leaves the provider alone:

  • On the background exec path, the provider already enforces the command deadline itself. It interrupts the command and returns exit code 124 with error_type="timeout", and it moves the server's own timer past that deadline as a backstop.
  • The foreground path still reports a server-side timeout kill as exit -1 with no error type, which the OpenCode agent routes as an unclassified command outcome rather than a timeout. The shipped OpenSandbox config enables background exec, so the OpenCode runs this fix targets do not take that path. Classifying foreground kills would need its own change to the provider.

Issue

No issue is linked. This restores behavior that NT4 training recipes rely on to mask rollouts that hit the agent deadline.

Validation

The new agent tests run a full OpenCode request in which the last assistant message in the session export carries an error. One case has the sandbox report a timeout and checks that the result's error type is timeout. The other case has the sandbox report a plain failure with no error type and checks that the export's error name is still used. The timeout case fails without this change.

Commands run:

PYTHONPATH=$PWD .venv/bin/python -m pytest responses_api_agents/opencode_sandboxed_agent/tests -n 16
pre-commit run --files responses_api_agents/opencode_sandboxed_agent/app.py responses_api_agents/opencode_sandboxed_agent/tests/test_app.py

Rollout evidence

The smoke rollout ran from this branch at 355ff7e. It covers the timeout path end to end, but not the precedence branch itself; the agent tests cover that branch.

Setup:

  • Gym servers ran on a local workstation.
  • Sandboxes ran on a remote OpenSandbox deployment with background_exec: true, the path where Gym interrupts a command at its own deadline. Each sandbox used the python:3.12 image, and the pinned OpenCode version was installed at run time.
  • The model was openai/openai/eccn-gpt-6-luna on the NVIDIA inference API. The remote sandboxes cannot reach the workstation, so OpenCode called the inference API directly through an opencode_config.provider override, not through Gym's model server.
  • Grading used the mcqa resources server, with sandbox_timeout: 240 and execution_failure_reward_zero: true.

What the rollouts showed:

  • Three tasks asked the model to write a file and then run sleep 400 && cat on it. In each one, the model made both bash calls and Gym interrupted the run at 240 seconds. Each rollout reported opencode_exit_code 124, opencode_error_type == "timeout" and opencode_failed true. The export was found, and the reward was 0.
  • A control task finished normally. It reported no error type and was graded with reward 1.

What the smoke did not reproduce: none of the timed-out exports had an error on its last assistant message. In every timed-out run, the deadline landed while a bash tool call was still running, and the interrupted process wrote nothing more to the session. Three more runs tried to place the deadline inside a long model response, but each response finished before the deadline. So no rollout reached the case where the export error and the sandbox timeout disagree. The agent tests above cover that case and fail without this change.

Compatibility

opencode_error_type changes only for runs where the sandbox reported an error type and the export also held an error. Those runs now report timeout instead of the export's error name.

When the sandbox kills an OpenCode run at its deadline, the exec result
carries error_type="timeout", but the session export often holds an error
on its last assistant message as well (the request the kill aborted). The
agent recorded the export error whenever it had no run error of its own,
so opencode_error_type came out as the export's error name and rules that
match opencode_error_type == "timeout" missed those rollouts.

A sandbox-reported error now outranks the export's terminal error. Without
one, the export error still classifies the failure as before.

Co-authored-by: Jiaqi Zeng <[email protected]>
Signed-off-by: Ananth Subramaniam <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

Only the exec timeout reaches this branch: an out-of-memory kill raises at exec and every other sandbox error type is rejected before the export is read.

Co-authored-by: Jiaqi Zeng <[email protected]>
Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub marked this pull request as ready for review November 16, 2026 17:06
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 16, 2026 17:07
@ananthsub
ananthsub requested review from yaoyu-33 and yfw November 16, 2026 17:09

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

SHIP

LGTM. No concerns found.

I checked the error-precedence change and regression cases, including sandbox error guards and downstream verification and timeout-health handling. Sandbox timeouts keep priority, while failures without a sandbox error still use the export error.

I did not execute tests or reproduce the reported smoke rollouts in this read-only review.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added bug Something isn't working area:agent Agent harnesses and Responses API agent behavior needs-review PR is ready for code review and waiting on a reviewer labels Nov 16, 2026
@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43952114923

Merged via the queue into main with commit fc109f3 Nov 16, 2026
69 of 71 checks passed
@yaoyu-33
yaoyu-33 deleted the ananthsub/opencode-timeout-error-precedence branch November 16, 2026 20:53
bg51717 added a commit to bg51717/Gym that referenced this pull request Nov 17, 2026
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 bug Something isn't working 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