Skip to content

feat(stirrup_agent): stop runs once the task has ended and add an option to keep the recorded history - #6672

Merged
ffrujeri merged 111 commits into
mainfrom
yifuw/stirrup-task-end-stop-recorded-history
Nov 30, 2026
Merged

ffrujeri merged 111 commits into
mainfrom
yifuw/stirrup-task-end-stop-recorded-history

Conversation

@yfw

@yfw yfw commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

#6161, #6162 and #5010 are merged, and this PR targets main with only the Stirrup layer (13 files).

It makes two changes to the Stirrup agent server.

A rollout stop ends a Stirrup run

Before this PR, POST /rollouts/{rollout_id}/stop did not end a Stirrup run in flight. So single_agent_turn refused Stirrup with end_on_task_state, and OfficeEnv's sandboxed episodes had no Stirrup config. Now:

  • stirrup_agent returns its sandbox session for a rollout stop (_rollout_sandbox_session) and joins ROLLOUT_STOP_AGENT_TYPES. The stop ends the runner as the time limit does.
  • The response of a stopped run carries the ng_rollout_stop marker (report_rollout_stop) in place of stop_reason: wall_time. A stop once the task has ended (completed: true) answers status: completed.
  • When the supervisor ends the runner, the runner reports Stirrup's live conversation. It holds the turns that answered and, while a turn's tool calls run, that turn's reply, whose calls have no answers. Before, the runner reported the history as of the turn's start. On OfficeEnv, the call that ended the task waits for its answer until the run is over. So that call stays the run's last output item, as it does for Pi.
  • A compaction summary is not a turn. The runner watches Stirrup's step and keeps a reply only when its request is the list that step got. So a summary reply never enters the output, even when it calls tools. A run cut during a compaction ends with the turn that just ran, answered.
  • A stop can end the runner before it writes anything: during the seed, before the activation, or while the runner starts and has no SIGTERM handler yet. The activation then answers with an empty stopped run (no output items, the stop's marker and status) in place of HTTP 500. A runner that crashed, or a deadline with no stop, still fails the activation.
  • resources_servers/officeenv_sandbox/configs/officeenv_sandbox_stirrup.yaml runs Stirrup on OfficeEnv's cli rows. It has no MCP transports, sets end_on_task_state, and caps the admitted episodes at Stirrup's concurrency, as the other harness configs do. It also pins its agent and environment servers to 127.0.0.1, as feat(officeenv): run OfficeEnv episodes in a sandbox, for Gym's sandboxed harnesses #5010 now does for every harness.

Main's finish-accepted flag (#6808)

Main's #6808 flags a finish that the tool accepted but that a wall-clock stop left out of the saved history (finish_accepted_unreported). With this PR, a stopped run keeps that turn's reply, but not the finish's answer. So the flag still holds, and the CritPt grader still keeps such an episode unscored (f98ecc8407). The empty stopped report also carries finish_accepted: false. The CritPt README now says the same (3dd747cd63).

An option that keeps the recorded history

Training on recorded tokens needs one unbroken history per episode. One config option keeps Stirrup's default and lets a training config turn it off:

Option Default Off for training
context_summarization_cutoff 0.7 (Stirrup's) null: Stirrup never replaces the history with a summary, so an episode at the context limit ends there.

The agent server passes it to the sandbox runner, and the runner passes it to Stirrup's agent. It accepts values above 0 and at most 1, because Stirrup compares it with a fraction of the context window. A percent such as 70 fails at load.

An earlier head of this PR also added recover_from_context_overflow, as Daniele's draft #5835 does. This PR drops it, because it adds no behavior. Main's context_overflow_recovery (#5226) is off by default, and with it off, the Gym client never reports an overflow to Stirrup. So Stirrup drops no turn whatever recover_from_context_overflow says. With context_overflow_recovery on and the option false, the episode ends at the first overflow, as it does with context_overflow_recovery off. A training config keeps context_overflow_recovery and truncation_recovery off, their defaults. The Stirrup README lists these settings and the two rewrites that stay.

Tests and docs

  • New stirrup_agent tests cover:
    • the stop marker and the completed status,
    • the runner's report of the running turn, at the time limit and on a stop,
    • a run cut after a compaction summary, and in the first and second summary attempts,
    • a stop during the seed, after the seed, and while the runner starts, and a deadline with no stop during the start,
    • a full session that a stop ends once its task has ended,
    • the summarization cutoff in the runner payload, in Stirrup's agent, and its bound.
  • tests/unit_tests/benchmarks/test_officeenv_sandbox_configs.py now covers the Stirrup config. The server's own tests/test_configs.py also covers it, but that file skips without OfficeEnv, and CI does not install OfficeEnv.
  • The Stirrup README describes rollout stops and the history settings.

No issue: this PR was built on the OfficeEnv stack (#6161, #6162, #5010), which is now merged.

These changes were written by Daniele Molinari (@d-molinari). The two feature commits came from an older snapshot of the stack. They were rebased onto #5010's current head, where the only conflicts were in tests/test_app.py, around tests that #5010's branch does not have. The later commits add the Stirrup config to the core config tests and describe the changes in the Stirrup README. They also fix what the reviews found: the compaction reply, the stop before the run, the unused overflow option and the cutoff bound.

Related PRs

Validation

All runs were local, on CPU, at head a2f2577eff105026f2110e1c24e4104d9fbe6f61.

  • uv lock --check passes for the root, resources_servers/officeenv_sandbox and responses_api_agents/stirrup_agent.
  • pre-commit run --all-files: every hook passed, and no file changed.
  • gym env test +entrypoint=responses_api_agents/stirrup_agent +should_validate_data=true: 242 passed.
  • gym env test +entrypoint=resources_servers/officeenv_sandbox +should_validate_data=true, with OfficeEnv 1.14.2 installed in the server's venv: 156 passed, its config and app tests included.
  • pytest tests/unit_tests/benchmarks/test_officeenv_sandbox_configs.py tests/unit_tests/config/test_global_config.py tests/unit_tests/orchestration/test_single_agent_turn_task_end_stop.py tests/unit_tests/agents/test_sandbox_session.py tests/unit_tests/agents/test_agent_sessions.py tests/unit_tests/server_runtime/test_sandbox_lending.py: 459 passed.
  • The new tests fail on the code they fix:
  • DCO: every commit has a Signed-off-by line.

Rollouts

The runs used head 110ca88761. Since then, this PR's own Stirrup code changed only the stopped-report fields above (f98ecc8407), and its config now pins the agent and environment servers to 127.0.0.1. The merges since then also brought main's changes to shared agent code, such as the sandbox session and the task-end stop in single_agent_turn. The runs did not cover those.

Real-model smoke: the 9 OfficeEnv sandbox pilot tasks in the cli exposure, Stirrup in OpenSandbox sandboxes, and a hosted Nemotron model behind Gym's model server.

  • As configured, 9 of 9 runs got reward 1.0 and ended with Stirrup's own finish tool, so the task-end stop did not fire. Stirrup cannot run without a finish tool, so with its default finish tool most runs end on finish. The task-end stop ends a run that calls user complete-task, before its next model call. Pi's config sets finish_tool_names: [], so for Pi the stop is the normal end.
  • With one prompt line that asks the model to run user complete-task before finish, 9 of 9 runs ended on that call: status completed, ng_rollout_stop {"reason":"task_ended","completed":true}, no stop_reason, the call as the last output item with no answer, and no model call after it. Reward 1.0 on all 9.
  • A rollout stop sent before the runner started answered HTTP 200 with no output items, no model call, status incomplete and the stop marker.
  • With context_summarization_cutoff: 0.02 and a 150 s runner deadline, 8 of 8 runs were cut by the deadline, 4 of them during a summary request. Each run ended with its completed turns, every call answered, and no summary reply in the output.

Compatibility and benchmark impact

  • context_summarization_cutoff defaults to Stirrup's own default, so existing configs keep their behavior.
  • A Stirrup run can end at its time limit while a turn's tool calls run. Its response now ends with that turn's reply, a function_call with no output. Before, the response ended with the last completed turn. A verifier that reads the output items sees this extra reply.
  • A rollout stop now ends a Stirrup run. Before, it answered 501. single_agent_turn with end_on_task_state now accepts stirrup_agent.
  • The OfficeEnv Stirrup config is new, so no existing benchmark result changes.

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: the Stirrup README and the OfficeEnv sandbox README.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header. N/A: the one new file is a YAML config, and the configs beside it carry no SPDX header.
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

🤖 Generated with Claude Code

d-molinari and others added 30 commits November 20, 2026 11:19
…r servers that sandboxed code calls

A resources server that lends a sandbox is reached by code the model controls, so the session key that every
caller can compute from the server's class and name must not sign its cookies and MCP tokens, and its endpoint
should look like an ordinary one.

- SimpleServer.get_session_secret() signs session cookies and MCP session tokens (default: the session middleware
  key, so nothing changes). Session routing reads cookies and tokens with it. Its docstring states what an
  override must keep: one secret in every worker, and a secret that changes ends every open session.
- SimpleServer.get_session_cookie_name() names the session cookie (default: the same key).
- mcp_server_name: the name the MCP endpoint lists itself under; verify-time normalization strips its namespace.
- mcp_bearer_token: tokens ride as Authorization: Bearer, tools/list needs one and lists only the session's tools,
  a tool outside the grant is an unknown tool, and errors name no framework.
- Both options are refused without expose_tools_over_mcp, and a name outside MCP's tool-name alphabet is refused.
  A single_agent_turn pairing refuses to grant two MCP endpoints listed under one name.

Signed-off-by: Daniele Molinari <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er tokens without a secret

Review fixes for the MCP endpoint options.

- mcp_server_name is also checked against the name pattern of an MCP grant (MCP_TOOL_ACCESS_NAME_PATTERN in
  tool_access, which MCPToolAccess uses), so a name that an Environment Server cannot grant, one that starts with
  '_' or '-', is refused at config instead of failing every episode before the agent seed. The grant contract is
  unchanged. A dot stays refused: Pi's MCP adapter and Codex refuse server names outside [A-Za-z0-9_-].
- seed_mcp_servers keys each entry by the seed metadata's server_name, else the server's name, and refuses two
  servers listed under one name. URLs, headers and routing still use the server's reference. The sandboxed
  OpenCode agent's required-server list uses the same keys; the sandboxed Pi agent reads them as given.
- An MCP endpoint with mcp_bearer_token refuses to start while get_session_secret() is the public session
  middleware key, since code that reads one bearer token could sign another session's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
Review asked to keep the MCP changes on the agent-session path. The only callers of
seed_mcp_servers, the sandboxed Pi and OpenCode agents, run on the agent-owned /run path
that #5222 deprecates, and OfficeEnv's Pi preset gets the advertised name and headers
through its MCPToolAccess grant. The seeder keys its entries by server name again, and
the aliasing's tests go with it. It no longer refuses two servers under one name, a
refusal that came after the primary server may have started a task sandbox and before
OpenCode's cleanup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…e alike

Review found that distinct endpoint names can still hide a tool in opencode_agent.
OpenCode keys each MCP tool <grant>_<tool>, writing characters outside [a-zA-Z0-9_-]
as '_', and a later tool under a key already taken replaces the earlier one without a
word: `company` serving `files_list` and `company_files` serving `list` both register
`company_files_list`. The agent's seed now refuses two MCP grants whose tools could
share a key, which the grant names decide: equal once written as OpenCode writes them,
or one the other followed by '_'. single_agent_turn's README and check, and the
mcp_server_name field, describe tool naming as each harness's own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
Review asked for per-run session secrets in server_runtime, as episode_token_secret()
does (#5346), instead of each server overriding get_session_secret().
run_session_secret(name) makes one secret per server for the run and keeps it in the
environment, so the workers uvicorn starts after the main process built the server
inherit it. get_session_secret() returns it when the server sets
signs_sessions_with_run_secret or its config sets mcp_bearer_token, so bearer tokens work
from YAML alone and with any number of workers; otherwise it is the public key, as before.
The session_secret property resolves it once per server (a cached_property, so it holds
for a server built without its model_post_init too), and the session middleware, session
routing and the MCP endpoint all read it there, so an override that answers differently
from call to call cannot split them. Exposure still refuses bearer tokens signed with the
public key, which only an override can now produce.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…he episode on the task state

A resources server whose task ends through its state, rather than through one tool's call, can now have its
episode end right after the step that ended the task. OfficeEnv's task ends when its user app's task row leaves
pending, which several operations reach, depending on how a row exposes its apps.

- single_agent_turn: max_episode_steps drives the agent one step per activation, up to that many steps, and
  end_on_task_state reads the resources session's task state between steps (GET /task_state, ResourcesTaskState
  in nemo_gym.server_runtime). Each step's failure report is kept. The server checks at startup that its agent keeps
  a session, runs the tools it calls and stops after one step. Driven episodes take part in checkpoints as restarts
  (BaseEnvironmentServer.checkpoint_mode_in_effect).
- simple_agent: with x-ng-agent-episode-step-limit, a step stopped by its own one-step limit counts as completed
  unless it is the episode's last, and the session keeps one invocation for the episode, as the agent's own loop
  does, instead of one per step that repeats the whole history.
- OfficeEnv: GET /task_state answers ResourcesTaskState; close_tools_on_task_end refuses the calls a step makes after
  the one that ended its task; its rows route by taskset to single_agent_turn with the step loop on, and the config
  allows only the simple agent. A retired attempt no longer keeps its episode, so its replacement can seed the same
  session ID. The server runs OfficeEnv 1.14.0 (1.13.0 at least), with its example rows emitted again.

Signed-off-by: Daniele Molinari <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and keep a simple_agent subclass in step

CI on the step loop found two things:
- agentic_turn_simulation_agent overrides simple_agent's _create_episode, which now takes
  step_limit_owned_by_caller. The override accepts it; only an agent session sets it, and this agent
  refuses those.
- The core coverage gate counts single_agent_turn's and simple_agent's app.py, but the step loop's tests
  ran in the server suite only. They move to the core suite unchanged, and simple_agent's step limit and
  invocation folding get core tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…s from the module that defines it

Tests under tests/ import from the defining module, not a package's public API, and
test_the_librarys_tests_import_from_the_module_that_defines_each_name failed on the two files this PR moved
into the core suite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…tep limit, counted by its index

With x-ng-agent-episode-step-limit, the agent takes one step (one model call and the tool calls it makes) whatever
its max_steps says, so a pairing no longer needs max_steps: 1, which composition drops when --agent-type
simple_agent replaces the environment's agent. Requests without the header run as before.

- The step is the activation's index (x-ng-agent-activation), which such a caller sends with every step, not the
  count of requests, so a step resent after a dropped connection is not counted as the next one.
- The session keeps the model server's cookies from step to step, so the episode keeps one model server session.
- A step that raises ends the episode's folded invocation as failed (or incomplete when cancelled), not with the
  completed status of the step before.
- The step keywords go to _create_episode only with the header, so an override that predates them keeps working;
  agentic_turn_simulation_agent's override no longer needs to accept one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…vation, and keep what the steps did

- STEP_DRIVEN_AGENT_TYPES (nemo_gym.config, beside AGENT_SESSION_AGENT_TYPES) lists the agent types that take one
  step per activation that names the episode's step limit: simple_agent. The startup check refuses any other type,
  such as hermes_agent or browsecomp_agent, which keep a session but run their own loop in an activation; a unit
  test keeps the list in step with the agent apps. The check no longer reads max_steps, and reads execute_tools as
  the agent's config does, so a string "false" is false.
- A failure after a step completed keeps the completed steps, their output and summed usage, as its partial
  response, unless it already carries one; a failure before the first reply has none.
- An episode that runs out of steps with every step calling a tool says so in its reply's metadata
  (ng_termination_reason: max_episode_steps). Its status stays the last step's: incomplete_details names only the
  model's own cutoffs, and an incomplete reply would read as malformed to rollout recovery.
- The task state is not read after the last step, which ends the episode either way.
- GET /task_state answering 404 with failure_kind session_lost ends the episode, which goes on to /verify and its
  masked lost-session result, as when a tool call finds the session gone. Other failed reads fail the episode as
  before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…ct sets its participant and its episodes

A server whose class declares exported but whose instance runs as restart_only installs a restart_only participant,
and its episodes begin as restarts; an unknown mode in effect stops the server at setup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…sion-less agents run too

single_agent_turn's /run takes only episode requests, so flat rows (training corpora, rows routed by their agent)
failed. single_agent_turn_legacy takes flat rows and taskset episodes, and runs the same step loop: OfficeEnv keeps
max_episode_steps 50, end_on_task_state, direct HTTP tools and the example taskset's route, and the simple agent no
longer sets max_steps: 1. Composition's fallback relays an agent without agent sessions through legacy_agent to its
own /run, so allowed_agents also admits simple_agent_with_compaction; the relay takes flat rows, not the taskset's
episodes.

The test that restated the YAML (skipped in CI with OfficeEnv absent) gives way to core tests that resolve the
config with a model and build its environment server: as shipped, with simple_agent.yaml added as --agent-type
simple_agent does, and with the compaction agent's config, where the server becomes a legacy_agent relay. The config
comment and README say what --agent-type and allowed_agents do, and that rollout_recovery.target_level: sibling
applies to the whole training run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
The Seed/Verify Protocol Extensions table lists GET /task_state, its reply, and what a 404 or 5xx does to the
episode. The agent integration page describes x-ng-agent-episode-step-limit beside x-ng-agent-activation.

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

With end_on_task_state and no max_episode_steps, single_agent_turn now ends an
agent that runs its own loop (a sandboxed harness) at its task's end, as the
step loop ends a step-driven one:

- Before the agent runs it reads GET /task_state?watch=true; while the agent
  runs it reads again, each read waiting up to 30 s (wait_s).
- Once the task has ended it stops the run with POST /rollouts/{id}/stop
  {"reason": "task_ended", "completed": true}, waits for the activation to
  answer (at most 120 s), then posts /task_state/release.
- The resources server holds its answer to the call that ended the task until
  that release, so the harness never reads it while its run could go on, and
  no model call follows the call that ended the task.
- The server refuses at startup an agent type outside ROLLOUT_STOP_AGENT_TYPES
  (the agents whose runs the stop route can end; a unit test keeps the list in
  step with the apps).

Core: RolloutStopRequest.completed; such a stop answers as completed
(report_rollout_stop) and says so in ng_rollout_stop. Docker uploads take a
bound of their own, so a stop's marker never waits for the exec slot a running
harness holds (uploads_independent_of_execs).

OfficeEnv: GET /task_state takes watch and wait_s (at most 60 s); POST
/task_state/release; task_end_hold_seconds (180) bounds the hold.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
report_rollout_stop now reads SandboxSession.expire_completed (a run stopped once
its task has ended answers as completed), so the stand-in that Cline's session
tests use carries it too, as the real session does.

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

Main's session contract (#5691) has every 409 a resources server answers raise
ResourcesSessionConflictError, and tests/unit_tests/test_session_contract_repo.py
checks it. With close_tools_on_task_end, the OfficeEnv server refused a call after the
task ended with a plain HTTPException(409); it now raises the named error. The status
and the detail are the same, so callers see no change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…ment and setup, and releases all within a deadline

What the OfficeEnv sandboxed server needs from core's lent sandboxes, so it builds on them instead of a copy:

- lend() takes a per-sandbox image, more environment variables and a setup that runs against the started sandbox,
  its files delivered, before it is lent (start_with_setup); a setup that fails stops the sandbox.
- The start runs to its end once begun, within start_timeout_s (30 minutes by default), even while the request that
  asked for it is cancelled: a create cut in flight leaves a sandbox whose id the provider never returned. A lend
  cancelled meanwhile lends nothing and stops what it started, and says so in the log.
- release_all(timeout_s=...) refuses new lends (503) from its start, waits for those still starting, stops everything
  within the deadline, and returns and logs the sessions whose sandbox may still run, for a reaper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…oxed harnesses

resources_servers/officeenv_sandbox's OfficeEnvSandboxResourcesServer subclasses the OfficeEnv server and lends each
episode session a sandbox through LentSandboxes (an operate descriptor: the harness uses it, only the server stops
it), stopped before the episode is graded.

- The harness reaches the apps as the row's exposure says: MCP tools, a command per app (cli), or endpoints it finds
  over MCP and calls with curl (api_search).
- File content stays out of the conversation through OfficeEnv's workspace mode: downloads land in the workspace,
  uploads and attachments name a workspace file, and a file API moves bytes directly.
- The sandbox sees an ordinary company API. Only Gym's servers on this node (any of the node's own addresses) and
  trusted_networks reach seeding, closing, verification, metrics, the reverify mode, the app catalog, the task state
  and the tool routes, which answer others 404 before reading a body; sessions are signed with a per-process secret.
- Seeds take turns, and a seed is admitted again before it lends; a close or a retire stops the sandbox, a failed
  seed's stop is tried again at its session's close, and shutdown stops everything within the run's grace.
- A sandbox provider failure fails the call (502) and masks the episode's reward.
- Configs for Pi (Docker and OpenSandbox), Codex CLI, mini-SWE, OpenCode, OpenClaw and Terminus 2; nine sandbox tasks
  (OfficeEnv 1.14.0), the first five as example rows with Pi's rollouts of them; images and a README.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…er returned the sandbox's id

When start_timeout_s cuts a provider's create in flight, the sandbox's id is unknown, so the lend's stop cannot reach
what the create left. The lend now logs that cut at ERROR with the resources session, the task (id and taskset), the
provider, the image and the labels, so a reaper can find the sandbox. A start cut after the create returned stops its
sandbox as before and asks for no reaper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…so harness configs compose in one run

Every harness config defined `oe` and `single_agent_turn_legacy`, so two of them could not run together. Now:

- the episodes' resources server is officeenv_sandbox_resources_server;
- each config adds officeenv_sandbox_<harness>_agent (`_inherit_from` Gym's instance of the harness, as benchmarks do)
  and officeenv_sandbox_<harness>_environment_server (`_inherit_from: single_agent_turn_legacy`);
- Pi, Codex and OpenCode, which name MCP tools their own way, run on their own copy of the episodes' server
  (officeenv_sandbox_<harness>_resources_server, `_copy` with its mcp_tool_prefix); the other harnesses run on the
  shared one. A copy takes the shared server's settings from the merged config, so one override reaches every harness.

The interpolations, the documented overrides, the probe script and the README follow (a table of the names; the
OpenSandbox config is listed after the other harness configs, since a later one pulls the episodes' config in again).
A core test resolves each config alone and all six together with a model config, and replaces the server test that
restated their YAML; it needs no OfficeEnv, so it runs in CI. The OpenCode and OpenClaw configs and the README no
longer say those harnesses refuse MCP tool grants.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…box's start; host_relay needs trusted_workstation

- sandbox_config.start_timeout_s (1800 s by default, a finite number above 0) is passed to LentSandboxes, which fails
  the seed at that limit and logs a create it cut for a reaper. The README says when to raise it: creates on a busy
  OpenSandbox cell have taken up to 2,430 s.
- host_relay forwards sandbox connections from the host's loopback, which the caller check takes for Gym's own
  servers, so code in a sandbox could call the routes kept for Gym for any session. Config validation now refuses
  host_relay unless sandbox_config.trusted_workstation is true, which a config sets only on a single-user workstation;
  its description and the README state the risk.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…v server's instances under names of their own

It composes resources_servers/officeenv/configs/officeenv.yaml and copies (`_copy`) its three instances as
officeenv_sandboxless_resources_server, officeenv_sandbox_simple_agent and officeenv_sandbox_environment_server, each
copy pointing at the other copies, while the OfficeEnv server's instances keep their names. The copied agent declares
no dataset, so the example rows and their taskset stay with the OfficeEnv server's instances, and rows that name
officeenv_sandbox_simple_agent (flat rows, agent_ref) route to the copied environment server.

A `_copy` takes its source as written, before the source's own `_inherit_from` applies, so the environment server is
copied as the instance of the server type officeenv_environment_server inherits, with that server's own settings for
it on top. The core test checks each copy against its source, references aside, alone and beside the Pi and Codex
configs, so a change to the source's server type fails it rather than leaving the copy behind.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…legacy, which the OfficeEnv server now runs

officeenv_environment_server inherits single_agent_turn_legacy now, so the copy takes that instance, then the server's
own settings for it under that type, with its references still pointing at the other copies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…under its own name, so none is left idle

Each harness config now adds officeenv_sandbox_<harness>_resources_server with `_inherit_from:
officeenv_sandbox_resources_server`, OpenClaw, mini-SWE and Terminus 2 included, and no harness names the episodes'
server. `_inherit_from` reads it from the merged config and takes it out of the run, so a run of one or several
harness configs starts no idle episodes' server, while the episodes config alone still runs it under its own name.
Settings on the episodes' server, the OpenSandbox config's included, reach every harness's server. The OpenSandbox
config still goes after the other harness configs (the first harness config listed pulls the episodes' config in),
and the README now says why. The core test checks that no episodes' server starts or is named beside the harnesses',
alone and with all six, and that the episodes config runs on its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…ed create left

Main's OpenSandbox provider now deletes the sandbox of a create its caller gave up on (#4799), so
a start that LentSandboxes' start_timeout_s cuts before the provider returned the sandbox's id no
longer needs a reaper there. The ERROR log, LentSandboxes' docstring and the officeenv_sandbox
README now say so, and keep the reaper for providers without that cleanup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
…ery exposure

- The sandboxed server holds the call that ends a watched episode's task, on
  every way in (tools, commands, endpoints, the file API), until the
  environment server releases it; the episode's lock is let go first. Only
  Gym's node reaches GET /task_state and POST /task_state/release.
- Pi supports POST /rollouts/{rollout_id}/stop (_rollout_sandbox_session): a
  run stopped as completed answers so, marked in ng_rollout_stop, and is not
  reported as a wall-time timeout.
- The Pi config sets end_on_task_state on its environment server and drops
  finish_tool_names (now []): the stop ends the run on cli and api_search rows
  too, which offer no finish tool. Its comment no longer asks cli rows to drop
  the MCP transport, which they run with as it is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
1.14.2 is the OfficeEnv release N4's training runs grade with. 1.14.1 and
1.14.2 are patch releases; neither changes the API these servers use. The
READMEs' install lines name it, and the example rows are emitted again by it
(officeenv emit for resources_servers/officeenv, sandbox/prepare_rows.py for
officeenv_sandbox), which changed only their version stamp. The example
rollouts stay the ones collected against 1.14.0.

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

Main's session contract (#5691) has every 409 a resources server answers raise
ResourcesSessionConflictError, and tests/unit_tests/test_session_contract_repo.py
checks it. The sandboxed server refused a tool call once verification began, and a
file API call once the episode's files closed, with plain HTTPException(409)s; both
now raise the named error. The status and the detail are the same, so callers see no
change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
Main's opencode_search (#6211) lends through LentSandboxes and expects a seed cancelled
while its sandbox starts to stop that sandbox at once, as LentSandboxes did before this
branch; the shielded start made it wait for the start's end. The shield is now opt-in.
Without start_timeout_s a cancel cuts the start as it cuts any await, as on main, and the
lend stops the sandbox it began. With it, the start runs to its end within that limit,
which the OfficeEnv sandbox server sets (sandbox_config.start_timeout_s, 1,800 s by
default). START_TIMEOUT_S goes, since no default limit remains.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
Main's lock upgrade (#6528) moved the root lock, and `uv sync --locked` refused the
sandboxed server's older lock, so neither its suite nor a run could start it. `uv lock`
with uv 0.13.4 takes the root lock's versions (e2b 2.50.0, protobuf-py 0.1.1, pyqwest
0.10.0), keeps the tzdata OfficeEnv pins (2026.6), and passes scripts/component_locks.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
yaoyu-33 and others added 5 commits November 30, 2026 08:33
#5010 now has the task-end fixes from #6162, binds the sandboxless OfficeEnv services to loopback in the mixed
preset, reports Pi's task-end stops after classifying the invocation, and adds a license header. The merge had no
conflict. Stirrup needs no matching change: its agent and environment servers are already on 127.0.0.1, its
resources server keeps the node's address for the sandbox, and it already applies report_rollout_stop last, after
report_outcome.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3b5f326

yfw and others added 3 commits November 30, 2026 10:26
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
#5010 merges main a6f6362, which brings #6808's finish-accepted report into the Stirrup runner and agent. Two
conflicts, both where this layer and #6808 changed the same lines: the response metadata in app.py, which now
keeps this layer's stop_reason swap and #6808's finish_accepted_unreported flag, and the runner tests, which keep
both sides' tests. The next commit adjusts #6808's test and the empty stopped report to this layer's stop report.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
…op report

#6808 assumed that a stopped run reports the history as of the start of the running turn, so a finish that the
tool accepted during that turn was missing from the output. With this layer, a stopped run reports the running
turn's reply, so the finish call is in the output, but its answer is not. The CritPt grader accepts a finish only
with its answer, so finish_accepted_unreported still applies, and graders still keep such an episode unscored.

The runner comments now say that the answer is missing, not the turn. #6808's test checks that the finish call
has no answer. The empty report for a run that a stop ended before any output carries finish_accepted: false, as
the runner's report does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f98ecc8

…g turn's reply

With the Stirrup layer, a run stopped while other calls of the finishing response still run keeps that turn's
reply in its saved history, but can lose the finish's answer. The README said it could lose the whole turn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3dd747c

Base automatically changed from dmolinari/officeenv-sandbox-integration to main November 30, 2026 19:03
#5010 merged into main as bc5383b (a squash), so this PR now targets main. Main's copy of every #5010 file
equals #5010's final head 23f7116, and main's other new commits touch none of this layer's 13 files. The three
add/add conflicts (the OfficeEnv sandbox README and its two config tests) take this layer's version, which is
#5010's final file plus this layer's changes. The PR's diff against main is the same 13 files and lines as this
layer's diff against 23f7116.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
@yfw

yfw commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a2f2577

@yaoyu-33 yaoyu-33 added ready-to-merge PR is approved, current, and waiting for final CI or merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Nov 30, 2026

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

Thanks. The environment server ends the episode from the resources server's task state, a real deadline still reads as wall_time, and the recorded history keeps the running turn's sampled reply. One note inline. LGTM.

"The generic default rejects only empty output; long-horizon benchmarks can require a "
"more complete summary.",
)
context_summarization_cutoff: float | None = Field(

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.

Draft #6972 adds this same context_summarization_cutoff field (without le=1). Could one PR own it? The description's note about #5835 could then be updated, since that draft is closed.

@ffrujeri
ffrujeri enabled auto-merge November 30, 2026 23:00
@ffrujeri
ffrujeri added this pull request to the merge queue Nov 30, 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/46532680159

Merged via the queue into main with commit 3036ba5 Nov 30, 2026
82 of 86 checks passed
@ffrujeri
ffrujeri deleted the yifuw/stirrup-task-end-stop-recorded-history branch November 30, 2026 23:19
d-molinari added a commit that referenced this pull request Dec 2, 2026
…rn back as the model wrote it

Training on recorded tokens (token capture) needs each model call of an episode to continue the previous one as the
model wrote it. context_summarization_cutoff (#6672) keeps the history from being summarized; one rewrite still had
no switch: the adapter strips a tool-call block the provider's parser left in an assistant turn's text from the
history sent back (stirrup_utils._strip_unparsed_tool_blocks), so the next call matches no recorded call.

strip_unparsed_tool_blocks (default true, as today) is now an option of the agent server. The server passes it in the
runner payload's client settings, and the model client passes it to the history serializer. The README lists it with
the client options and names it beside the rewrites that stay.

Tests: the payload carries the switch, and an assistant turn with an unparsed block goes back to the model as written
only when stripping is off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
d-molinari added a commit that referenced this pull request Dec 2, 2026
…rn back as the model wrote it

Training on recorded tokens (token capture) needs each model call of an episode to continue the previous one as the
model wrote it. context_summarization_cutoff (#6672) keeps the history from being summarized; one rewrite still had
no switch: the adapter strips a tool-call block the provider's parser left in an assistant turn's text from the
history sent back (stirrup_utils._strip_unparsed_tool_blocks), so the next call matches no recorded call.

strip_unparsed_tool_blocks (default true, as today) is now an option of the agent server. The server passes it in the
runner payload's client settings, and the model client passes it to the history serializer. The README lists it with
the client options and names it beside the rewrites that stay.

Tests: the payload carries the switch, and an assistant turn with an unparsed block goes back to the model as written
only when stripping is off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
d-molinari added a commit that referenced this pull request Dec 4, 2026
…rn back as the model wrote it

Training on recorded tokens (token capture) needs each model call of an episode to continue the previous one as the
model wrote it. context_summarization_cutoff (#6672) keeps the history from being summarized; one rewrite still had
no switch: the adapter strips a tool-call block the provider's parser left in an assistant turn's text from the
history sent back (stirrup_utils._strip_unparsed_tool_blocks), so the next call matches no recorded call.

strip_unparsed_tool_blocks (default true, as today) is now an option of the agent server. The server passes it in the
runner payload's client settings, and the model client passes it to the history serializer. The README lists it with
the client options and names it beside the rewrites that stay.

Tests: the payload carries the switch, and an assistant turn with an unparsed block goes back to the model as written
only when stripping is off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
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 ready-to-merge PR is approved, current, and waiting for final CI or merge 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.

5 participants