Skip to content

feat(opencode_agent,officeenv_sandbox): stop Codex's, OpenCode's and Terminus 2's runs once their task has ended - #6974

Open
d-molinari wants to merge 4 commits into
mainfrom
dmolinari/officeenv-training-harness-stops
Open

d-molinari wants to merge 4 commits into
mainfrom
dmolinari/officeenv-training-harness-stops

Conversation

@d-molinari

@d-molinari d-molinari commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Stops the runs of the harnesses that OfficeEnv's sandboxed episodes train with that still went on after the call that ended their task: Codex, OpenCode and Terminus 2. Pi's runs stop since #5010, and Stirrup's since #6672, which landed Stirrup's stop and its OfficeEnv config. Without the stop, the later tool calls were refused, so the grade held, but a training run trained on those turns.

  • OpenCode (opencode_agent) can now be stopped in flight (POST /rollouts/{rollout_id}/stop) and joins ROLLOUT_STOP_AGENT_TYPES. It already ran under Gym's process supervisor, which ends it as at its time limit. The agent now returns its sandbox session for a stop and marks the reply with report_rollout_stop, so a stop for a task that ended answers completed.
    • The reply is built from what OpenCode saved, as for a timeout. As at the time limit (fix(opencode_agent): report unknown usage when a step was stopped #6960), the step the stop cut short has no stored usage, so the reply has none and a model_call_usage_unavailable gap names it.
    • A stop before OpenCode saved anything, or before its launch, answers with no output. With partial-rollout checkpoints, a launch that a checkpoint stopped is not relaunched after a rollout stop.
  • OfficeEnv configs (resources_servers/officeenv_sandbox/configs): end_on_task_state for Codex and OpenCode; Terminus 2 moves from the deprecated terminus_2_sandboxed_agent to terminus_2_agent, with the stop and a cap at its concurrency. OpenClaw's config is unchanged: its agent cannot be stopped yet, and close_tools_on_task_end keeps what it calls after the end out of the grade.

Validation

  • tests/unit_tests/benchmarks/test_officeenv_sandbox_configs.py checks that every harness config but OpenClaw's stops its runs and caps its episodes, starts each stopping environment server (its startup check refuses an agent it cannot stop), and fails on a harness config it does not list. test_rollout_stop_agent_types_match_the_agent_apps covers OpenCode.
  • New OpenCode tests: stopped while it runs (completed and plain), a stop that cuts a step short, a stop before launch, and stops that reach a launch a checkpoint stopped.
  • On main 64d738eca2: core tests (OfficeEnv sandbox configs, global config, task-end stop, agent sessions) 369 passed; opencode_agent 1284, stirrup_agent 242, single_agent_turn 336, single_agent_turn_legacy 54 and officeenv_sandbox 160 passed (the last with OfficeEnv 1.14.2 and data validation); pre-commit on the changed files: clean.
  • CI's non-blocking OpenCode conformance probe times out in main's own test_pinned_cli_reports_whether_required_plugin_initialized, which this PR does not change. The probe fails the same way on other PRs run the same day.

Rollouts

gpt-5.5, OfficeEnv 1.14.2, Docker sandboxes, the harness configs composed in one run, OfficeEnv's five sandbox example tasks for each: Pi on its example rows (MCP tools), the others on the same tasks with the apps as commands (sandbox/prepare_rows.py --exposure cli). These ran on 11-30, before the rebase onto main. Stirrup's row is left out: it measured this PR's earlier Stirrup stop, which #6672 replaced.

Harness Reward 1.0 Stopped as completed Reply ends at the task-ending call
Pi 5/5 5/5 5/5
Codex CLI 5/5 5/5 5/5
OpenCode 5/5 5/5 5/5
Terminus 2 5/5 5/5 1/5 *

* Terminus 2's reply leaves out the turn that was running when it was stopped (as at its deadline), which in 4 of 5 runs held the task-ending command. Each of those made exactly one model call more than its reply shows, so none followed that command. No sandbox was left after shutdown, and no held call waited out its timeout.

A training smoke on 12-02 ran this PR (on main bd90a1b45d, before this rebase) for two GRPO steps of OfficeEnv tasks, with Pi, Stirrup, OpenCode and Codex CLI in one run: 256 trained rollouts. Every rollout that completed its task stopped at the call that ended it, with no model call after it: Pi 64 of 64, Stirrup 52 of 56, OpenCode 69 of 72 and Codex CLI 62 of 64 (the others never completed their task). No stop or release failed, no sandbox was left, and no token capture was dropped.

Compatibility and benchmark impact

  • A stop request to OpenCode, which answered 501, now stops the run; nothing changes for a run that is not stopped.
  • OfficeEnv's Codex, OpenCode and Terminus 2 configs now end runs at the task's end, so their rollouts no longer carry turns after it. The Terminus 2 config now caps its episodes at the agent's concurrency (32).
  • Benchmark results: none.
  • feat(stirrup_agent,pi_agent): Stirrup's view_image and strip_unparsed_tool_blocks, Pi's plain prompt and MCP discovery deadline #6972 (open) gives Stirrup a view_image tool. This PR's resources_servers/officeenv_sandbox/README.md says Gym's Stirrup has no tool that shows the model an image; whichever of the two merges second updates that sentence.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (run on the changed files).
  • New source files include the required Apache-2.0 SPDX header. (N/A: no new files.)
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 30, 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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added risk:high Autobot PR risk: high feature New capabilities, enhancements, or enablement work area:agent Agent harnesses and Responses API agent behavior labels Nov 30, 2026
@d-molinari

Copy link
Copy Markdown
Contributor Author

/ok to test b522543

@d-molinari
d-molinari force-pushed the dmolinari/officeenv-training-harness-stops branch from b522543 to 00e07c5 Compare December 2, 2026 05:41
@d-molinari d-molinari changed the title feat(stirrup_agent,opencode_agent,officeenv_sandbox): stop each training harness's run once its task has ended feat(opencode_agent,officeenv_sandbox): stop Codex's, OpenCode's and Terminus 2's runs once their task has ended Dec 2, 2026
@d-molinari

Copy link
Copy Markdown
Contributor Author

/ok to test 00e07c5

@d-molinari

Copy link
Copy Markdown
Contributor Author

/ok to test 160e277

@nemo-pr-automation
nemo-pr-automation Bot requested review from a team December 2, 2026 22:25
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Dec 2, 2026
@ko3n1g

ko3n1g commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

/review

@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.

HOLD

I found one BLOCKER that silently drops captured trajectory data and one RISK that loses rollout stops during checkpoint fallback. The inline comments include the repairs and acceptance checks.

I reviewed all 15 changed files and connected callers with three delegated reviews covering capture, checkpoint handling and OfficeEnv configuration.

Validation used gym:a4bf4964cd81600018ada0c0397157c78b4b1021, the default branch's CI image. CPU probes reproduced both defects. Positive controls preserved ordinary stopped output, interrupted-step usage handling and genuine empty prelaunch stops. Configuration probes confirmed task-end stopping and borrowed-sandbox ownership for the Terminus migration. These probes used fake providers and did not execute a real model or OpenCode process.

I relied on successful CI results for Nemo_CICD_Test, Lint check, all four core shards, all eight server shards and Unit tests / Sandbox tests. Session routing end-to-end and Changed server tests were skipped. The optional OpenCode and mini-SWE conformance jobs failed; I have not established attribution. I did not rerun the CI suites or the model rollouts described in the PR.

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

raise RuntimeError(format_error_message(str(error), stderr=self.stderr)) from error
raise
if self._launch_failed() and not (directory / "export.json").exists():
if self.session.expired:

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.

BLOCKER: Keep failed database transfers distinct from empty stops.

A stopped launch does not prove that its conversation is absent. _download_database() returns False both when the database is absent and when downloading an existing database or write-ahead log raises. snapshot() then leaves no export, so this new branch returns EMPTY_EXPORT. The response builder treats that as a confirmed empty run and suppresses observation_capture_failed.

I reproduced this through public seed, responses, stop and close methods with a populated SQLite store. The successful-transfer control returns reasoning, a tool call, its result and an assistant message. Failing either the database transfer or only its write-ahead-log transfer instead returns status: completed, output: [], error: null, with no capture-failure gap. The base raises NothingCapturedError for the failed-transfer case. This silently discards trajectory data for stopped runs affected by a provider download failure.

Could _download_database() return False only after a successful listing confirms absence, and propagate transfer failures through the existing capture-error path? Keep genuine no-database and no-root stopped runs valid.

Acceptance: fail database and write-ahead-log downloads after a public task-end stop and assert a capture failure rather than successful empty output. Keep successful populated capture and completed/plain prelaunch empty-stop controls passing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in d405c4a545: _download_database() now returns False only after a successful listing shows no database. A failed copy of the database or its write-ahead log raises through the capture-error path, so the stopped run fails with observation_capture_failed instead of answering as an empty completed run. New tests fail each copy after a public task-end stop; they fail against the previous sandbox.py. The populated-capture, no-root-session and pre-launch empty-stop controls still pass.

kept: _StoppedLaunch | None = None
if state.launch_count > 0:
stopped = state.session.cleanup
if await self._stopped_by_rollout(state, timeout=close_timeout):

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.

RISK: Retain rollout stops while a checkpoint holds a stopped launch.

After an unconfirmed checkpoint pause, run_with_checkpoint_pauses() collects the stopped launch before waiting at the checkpoint boundary. A public stop delivered there reaches SandboxSession.expire(), which returns False because cleanup exists, without recording the reason or writing a marker. This check therefore misses the stop and prepares launch 2.

I reproduced the actual checkpoint boundary with completed, reason-only and empty-body public stops: each returns stopped: false and reaches replacement-launch preparation. An independent probe also reaches the second adapter execute(). This lets checkpointed OpenCode continue after a task-end or budget stop. The environment caller still waits for the activation when stopped is false. The added checkpoint tests assign expiry fields directly, so they miss this public transition.

Could we retain the stop for the whole activation across checkpoint fallback and rearm, then return the stopped launch's output with its reason/completed metadata? Preserve normal fallback without a stop, post-completion no-ops and borrowed-sandbox ownership.

Acceptance: request the stop through stop_rollout() after cleanup exists but before checkpoint release; assert no replacement execution and preserved output/stop metadata. Cover all three stop forms and a stop arriving during relaunch preparation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 9553910ee9: the agent keeps the first stop for the whole checkpointed activation and answers stopped: true while a checkpoint holds the stopped launch. _run_launches checks for that stop before and after preparing the relaunch, and also when a stop that arrives while the relaunch stages its files keeps the relaunch from starting. In each case the run ends with the stopped launch's output and the stop's reason and completed metadata. New checkpoint tests send completed, reason-only and empty-body stops at the real checkpoint boundary, plus stops before and after the session is rearmed and while the relaunch stages. None of them starts a replacement launch, and 9 of the 11 fail before the fix. Not covered: the kept stop is not saved in a checkpoint, so after a crash and restore the replacement attempt would have to be stopped again.

Tests at the fixed head (before a no-conflict rebase onto main 98458af5c9): opencode_agent 1318 passed, plus the 4 test_pinned_cli_reports_whether_required_plugin_initialized cases that fail on main too (an OpenCode CLI timeout); OfficeEnv sandbox config tests 25 passed; pre-commit clean.

d-molinari and others added 4 commits December 3, 2026 23:14
…d}/stop)

OpenCode runs under Gym's process supervisor, which ends it as at its time limit when a rollout stop
arrives. The agent now returns its sandbox session for such a stop, so an environment server can stop a
run in flight: with single_agent_turn's end_on_task_state, once the episode's task has ended.

- `_rollout_sandbox_session` returns the session; `opencode_agent` joins ROLLOUT_STOP_AGENT_TYPES.
- The reply is built from what OpenCode saved, as for a timeout, and goes through `report_rollout_stop`:
  a stop for a task that ended answers as completed, with `ng_rollout_stop`.
- As at the time limit, a step the stop cut short (at a task's end, the step whose tool call ended it)
  has no stored usage, so the reply has none and a `model_call_usage_unavailable` gap names its message.
- A stop before OpenCode saved anything, or before its launch, answers with no output instead of failing
  the activation (`classify_opencode_run(rollout_stopped=...)`).
- With partial-rollout checkpoints, a launch a checkpoint stopped is not relaunched after a rollout stop,
  which the relaunch would forget: its output is the reply, as at its time limit.
- Tests: stops while OpenCode runs (completed and plain), a stop that cuts a step short, a stop before the
  launch, and stops that reach a launch a checkpoint stopped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…s once their task has ended

Codex, OpenCode and Terminus 2 called the model on after the call that ended their task, until their
timeout, with every later tool and file API call refused (close_tools_on_task_end); a training run trained
on those turns.

- Codex and OpenCode: end_on_task_state on their environment servers, as Pi's.
- Terminus 2: the config moves from the deprecated terminus_2_sandboxed_agent (its legacy /run path)
  to terminus_2_agent, whose runs Gym can stop in flight, with end_on_task_state and an admission cap
  that follows its concurrency. The 127.0.0.1 pins stay.
- OpenClaw: unchanged. Its agent cannot stop a run in flight yet, so its run goes on after the task's
  end, and close_tools_on_task_end keeps what it calls then from the grade.
- tests/unit_tests/benchmarks/test_officeenv_sandbox_configs.py, which CI runs without OfficeEnv,
  checks that every harness config but OpenClaw's stops its runs and that each caps its episodes,
  starts each stopping environment server, whose startup check refuses an agent it cannot stop, and
  fails on a harness config it does not list. The server's test_configs.py checks every config's stop.
- The READMEs and the config comments describe the harnesses as they are now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…nversation cannot be copied

A copy of the session database or of its write-ahead log that failed counted as a store with nothing in it, so
a run that a rollout stop ended answered as an empty run: completed, with no output and no capture gap, and the
conversation it had saved was lost.

- `_download_database` answers that there is no database only when the store's listing names none. A copy that
  fails raises "OpenCode transcript capture failed", as a failed listing does, and the activation fails with
  `observation_capture_failed`.
- Tests: a task-end stop whose database copy or write-ahead-log copy fails; a stop before OpenCode saved a
  conversation (no root session); the stop before the launch, now through the store's real listing and in its
  plain form too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…nt has stopped the launch

The sandbox session refuses a stop once its launch has ended, and forgets one when a relaunch rearms it. A stop
that came while a checkpoint held a launch it had stopped, or while that launch's relaunch was prepared, was
answered `stopped: false` or forgotten: OpenCode was relaunched and ran on after the task's end or the budget. A
stop that came while the relaunch staged its files kept OpenCode from starting and failed the activation.

- The agent keeps the first stop of a checkpointed activation until the activation ends (`stop_rollout`), and
  answers one that arrives while a launch a checkpoint stopped waits for its relaunch as stopped.
- `_run_launches` looks for the stop before it prepares the relaunch and once it has, and then ends with the
  stopped launch's output, as at its time limit. A relaunch that a stop kept from starting ends the same way.
- The sandbox session holds the stop for the reply and the close (`keep_rollout_stop`): it is rearmed for a
  launch that never starts and the stop is requested before it, so the reply carries `ng_rollout_stop` and a
  task-end stop answers completed.
- Tests drive the real checkpoint boundary with the fake OpenCode and stop through the public route: completed,
  reason-only and empty-body stops while the checkpoint holds the stopped launch, stops before and after the
  relaunch rearms the session and while it stages its files, and a later stop that finds the run ended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
@d-molinari
d-molinari force-pushed the dmolinari/officeenv-training-harness-stops branch from 160e277 to 9553910 Compare December 4, 2026 07:14
@d-molinari

Copy link
Copy Markdown
Contributor Author

/ok to test 9553910

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 risk:high Autobot PR risk: high sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants