Skip to content

feat: add sandboxed Hermes for SWE-bench Pro - #3542

Merged
yaoyu-33 merged 26 commits into
NVIDIA-NeMo:mainfrom
elisam0:jnolan/hermes-sandboxed-pro
Sep 28, 2026
Merged

yaoyu-33 merged 26 commits into
NVIDIA-NeMo:mainfrom
elisam0:jnolan/hermes-sandboxed-pro

Conversation

@j-nolan

@j-nolan j-nolan commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Adds sandboxed Hermes support for SWE-bench Pro, using opencode_sandboxed_agent as the reference.

The existing SWE-bench Pro resources server creates the task container. The Hermes agent attaches to it and runs Hermes inside, with model calls routed through Gym's model server. The resources server then extracts the patch and grades it in a fresh verification container.

Both this approach and anyswe use sandboxes. In anyswe, the agent adapter manages task setup, execution, and grading. Here, those responsibilities are split: Hermes solves the task, while the benchmark resources server owns the environment and verification.

Includes a portable Hermes runtime for glibc and musl task images, plus Apptainer support for attaching to an existing sandbox.

Validation: focused agent, resources-server, and sandbox tests on the rebased branch; pre-commit checks; real-model SWE-bench Pro rollouts before this rebase.

Suggested labels: feature, area:agent (maintainer access required).

Use Pro passed-test grading for incomplete test reports and retain patch scores at the Hermes turn budget. Match evals-v2 tool defaults and agent timeout. Rebuild old runtimes using copied packages and an explicit matching host Python for uv.

Signed-off-by: James Nolan <[email protected]>
Bundle checksum-pinned static ripgrep, preserve the task image PATH through login-shell initialization, and pass the configured context length to the main and summary model. Retain the latest persisted tool call when an in-flight tool is interrupted.

Signed-off-by: James Nolan <[email protected]>
Enable the pinned harness session store so its pre-tool message snapshot exists. Checkpoint on tool start as well as between iterations, preserving the latest actual tool call when a hard kill prevents the final result write. Serialize concurrent checkpoint writers.

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

copy-pr-bot Bot commented Sep 18, 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.

@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Sep 18, 2026
@bxyu-nvidia

Copy link
Copy Markdown
Contributor

/ok to test 326a472

Use Hermes's text_response exit reason to distinguish a natural final answer
from a forced budget summary. Keep summary and wall-time stops incomplete.
Add four regressions, including the shared-budget completed-summary case.

Quote the README image template for Hydra and correct the review guide's
shared-library scope. Leave deferred runtime startup, Environment Server
routing and auxiliary usage work unchanged.

Validation: 755 focused tests passed, 18 optional telemetry tests skipped;
39 model/proxy compatibility tests passed; all tracked-file pre-commit
hooks passed. The new natural-completion regression fails before the fix.

Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33 yaoyu-33 removed needs-review PR is ready for code review and waiting on a reviewer community-request Issue reported or requested by someone from the community labels Sep 23, 2026
@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test 39f9e2a

@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Sep 24, 2026
@yaoyu-33 yaoyu-33 removed the community-request Issue reported or requested by someone from the community label Sep 24, 2026
@yaoyu-33
yaoyu-33 added this pull request to the merge queue Sep 28, 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/36474788170

Merged via the queue into NVIDIA-NeMo:main with commit 99828ca Sep 28, 2026
44 checks passed
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Sep 28, 2026
ananthsub added a commit to ananthsub/Gym that referenced this pull request Sep 29, 2026
## What does this PR do?

Adds typed session support to SWE-bench Pro while preserving its legacy
request shapes, and makes the single-agent-turn Environment Server
verify through each Resources Server's own verify body.

SWE-bench Pro sessions:

- The Resources Server owns task sandbox setup, verification, and
cleanup.
- The typed sessions build on the SWE-bench Pro lifecycle from NVIDIA-NeMo#3542.
`/close_session` closes a typed session when given a
`ResourcesCloseSessionRequest`, and closes the cookie session when given
an empty body, as `hermes_sandboxed_agent` sends.
- A repeated verify of a typed session fails once its task sandbox has
been consumed, instead of grading an empty patch and returning a
normal-looking reward.

Verification contract:

- `single_agent_turn` now sends `/verify` the flat body an Agent's
`/run` sends: the task's `task_data` fields, `responses_create_params`,
and the agent's `response`. The request carries the Resources session
cookie from seeding, which identifies the episode.
- `SingleAgentTurnVerificationInput` and
`SingleAgentTurnResourcesVerifyRequest` are removed, so no Resources
Server depends on an Environment Server's protocol. This changes
`single_agent_turn` code merged in NVIDIA-NeMo#3717.
- SWE-bench Pro accepts one verify model, `SWEBenchProVerifyRequest`,
and finds its sandbox through the session.
- `ResourcesVerifyRequest[T]` stays for Resources Servers paired with
their own Environment Server, whose payload type they define.
- Records from `single_agent_turn` now carry the same echoed task fields
as records from an Agent's `/run`, and reverification sends the body
live grading sends.

## Single-agent-turn interaction flow

This diagram describes SWE-bench Pro under the built-in
single-agent-turn Environment Server. Other Environment Servers may use
different lifecycle and result contracts.

```mermaid
sequenceDiagram
    participant E as EnvironmentServer
    participant R as SWEProResources
    participant S as TaskSandbox

    E->>R: Seed with task data and caller ID
    R->>S: Start and prepare sandbox
    R-->>E: SandboxAccess and session cookie
    E->>R: Verify with task fields and the Agent response, under the session cookie
    R->>S: Extract patch and run evaluator
    R-->>E: Verification result
    E->>R: Close session
```

## Stack position

Part 1 of 4, based on `main`. Next:
[NVIDIA-NeMo#3720](NVIDIA-NeMo#3720).

No issue is linked because this is one layer of the Environment Server
stack.

## Validation

- `uv run pytest resources_servers/swebench_pro/tests -q` — 84 passed
- `uv run pytest environment_servers/single_agent_turn/tests/test_app.py
-q` — 12 passed, including a check that `/verify` receives the flat body
under the Resources session cookie
- `uv run pytest tests/unit_tests -q` — passes except two tests that
also fail on `main` in the local environment (missing `sandbox` extras
and a pip notice)
- `pre-commit run` on the changed files

## Rollouts

A real Hermes + SWE-bench Pro rollout through `single_agent_turn_legacy`
resolved its task (reward `1.0`, 300 of 300 tests) with the flat verify
body under a typed session, with an empty failure sidecar and no
leftover sandboxes. Its record carries the task fields, as a `/run`
record does.

## Compatibility and benchmark impact

Legacy SWE-bench Pro request bodies remain supported. Existing Resources
Servers verify single-agent-turn episodes without changes.
`SingleAgentTurnVerificationInput` and
`SingleAgentTurnResourcesVerifyRequest` are removed from
`nemo_gym.single_agent_turn_types`; they landed in NVIDIA-NeMo#3717 and had no
users outside this stack.

---------

Signed-off-by: Ananth Subramaniam <[email protected]>
aroshanghias-nvd pushed a commit to aroshanghias-nvd/Gym that referenced this pull request Sep 30, 2026
## What does this PR do?

Runs Hermes in a Resources-owned sandbox when `SandboxAccess` is
supplied, or creates an Agent-owned fallback sandbox otherwise. Both
paths return sandbox-captured model and tool observations during close.

Hermes calls the Model Server directly from the sandbox, so the sandbox
must be able to reach it. The runner points every model client Hermes
builds at the rollout's Model Server URL: the root agent, its
iteration-limit summary, delegated children, and auxiliary clients.
Streaming is turned off because the Model Server answers only whole
responses.

The sandbox installs the Hermes version pinned in `requirements.txt`,
derived at startup from the Hermes installed with the server, so there
is one version pin and the sandbox runs the same Hermes as the host.
Seeding reuses that Hermes when it already imports in the sandbox, for
example because the image bakes it in, and otherwise installs it and
checks the import again. The runner starts with one blocking `exec`, so
it works on any sandbox provider. Close cancels an activation still in
flight, and the runner's shell records its PID and honors a stop marker,
so an interrupted activation, or one that exceeds
`sandbox_runner_timeout_seconds`, stops the runner. Tearing down the
sandbox remains the backstop.

Sessions use MCP tool grants. Each activation adds the granted servers
to that session's Hermes configuration, and the runner fails before the
first model call when a required server does not connect. The sandbox
installs Hermes with its `mcp` extra, which carries the MCP client.
Hermes names MCP tools `mcp_<server>_<tool>`; the response reports them
as `mcp__<server>__<tool>`, the form Gym strips before verification,
while captured model calls keep Hermes' names. Other required grants,
such as direct HTTP, are rejected at seed, and an MCP grant may not
reuse a Hermes toolset name.

## Single-agent-turn interaction flow

This diagram describes Hermes under the built-in single-agent-turn
Environment Server. Other Environment Servers may use different Agent
activation and sandbox ownership rules.

```mermaid
sequenceDiagram
    participant E as EnvironmentServer
    participant A as HermesAgent
    participant S as TaskSandbox
    participant M as ModelServer

    E->>A: Seed with optional SandboxAccess
    A->>S: Borrow or create sandbox
    E->>A: One /v1/responses activation
    A->>S: Run Hermes and tools
    S->>M: Model calls
    A-->>E: Agent response
    E->>A: Close session
    A->>S: Disconnect borrowed or stop owned sandbox
```

## Stack position

Part 1 of 3, based on `main`. Next:
[NVIDIA-NeMo#3721](NVIDIA-NeMo#3721).

No issue is linked because this is one layer of the Environment Server
stack.

## Validation

- `responses_api_agents/hermes_agent/.venv/bin/pytest
responses_api_agents/hermes_agent/tests/ -q` — 72 passed
- The runner tests run the pinned Hermes against a local HTTP model
server and check that the iteration-limit summary and default OpenAI
clients reach it, and that delegated children do not stream.
- Required Direct HTTP tool-grant reproduction now fails seed explicitly
instead of running without the tool.
- A runner test starts the example MCP weather Resources Server with MCP
exposure, grants it to Hermes, and checks that the model's tool call
reaches the seeded Resources session; another checks that an unreachable
required server fails before any model call.
- Non-Hermes real-model smoke: not run because this workspace has no
configured model endpoint or credentials.

## Rollouts

MCP grants: all 5 `example_mcp_weather` tasks with `gpt-5.6-sol` through
`single_agent_turn_legacy` with the MCP tool transport scored reward
`1.0`, with Hermes calling `get_weather` over MCP from its sandbox. That
run also used the Resources Server change that returns MCP access in
`resources_tools` for Environment Server seeds, which is a separate PR.
See the final integration PR for SWE-bench Pro rollout evidence.

## Compatibility and security impact

`reasoning_content` replay on assistant messages comes from NVIDIA-NeMo#3542; this
PR adds tests for it. Sandbox requirements, including Model Server
reachability, and the writable result-file limitation are documented in
the Hermes README. Sandbox mode is suitable for evaluation, not RL
training data, until result transport is isolated from model-written
files.

---------

Signed-off-by: Ananth Subramaniam <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 39f9e2a1 Deployed Sep 24, 2026 by copy-pr-bot[bot] via release / finalize / notify #3636
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 complexity:high Cross-component or shared-contract change with a large review surface feature New capabilities, enhancements, or enablement work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants