Skip to content

cp: Hermes session hardening and simple agent environment server sessions (#3554, #3784) into r0.7.0 - #4113

Merged
ananthsub merged 3 commits into
NVIDIA-NeMo:r0.7.0from
ananthsub:cherry-pick/r0.7.0-agent-sessions
Oct 6, 2026
Merged

ananthsub merged 3 commits into
NVIDIA-NeMo:r0.7.0from
ananthsub:cherry-pick/r0.7.0-agent-sessions

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What

This PR only cherry-picks two already-merged main PRs into r0.7.0. It adds no new code. Each commit is applied with git cherry-pick -x, so its message records the source commit.

Original PR Commit on main Change
#3554 b846dfaa5 fix(hermes): harden sandbox sessions
#3784 e0e63e526 feat(simple-agent): run simple agent through environment server sessions

This branch is based on the current r0.7.0, which already includes #4107 (#3818, #4070, #3929, #4053) and #4078.

Why

#3784 has the r0.7.0 label, but the automatic cherry-pick workflow could not apply it: it hit a merge conflict in nemo_gym/base_responses_api_agent.py and reported success anyway, so nothing was opened.

#3554 is included because #3784 builds on it. #3554 added the agent session handling (seed and close retries, session locks, close receipts) in nemo_gym/base_responses_api_agent.py that #3784 extends. With #3554 applied first, the conflict in that file goes away. #3554 has no r0.7.0 label; it is included on purpose.

Behavior changes from #3554

#3554's own description lists these, and they now apply on r0.7.0 too:

  • Hermes host execution now combines the config system prompt, request instructions, and input system message instead of letting the config prompt replace the dataset prompt. It honors the request temperature, including zero, and rejects developer messages with 422. These changes can change benchmark scores for Hermes on the host path.
  • Hermes rejects unsupported non-default controls with a permanent 422, including top_p=1.0, store, service_tier, metadata overrides, max_output_tokens, and a model that does not match the configured model.

Conflict resolution

Validation

  • pytest tests/unit_tests -n 8: same failures as unmodified r0.7.0 and no new ones. The existing failures are local-environment tests in test_opensandbox_compose.py, test_sandbox_stop_retry.py, and test_slurm_script.py.
  • fix(hermes): harden sandbox sessions #3554's focused suite, each path run separately with --import-mode=importlib: environment_servers/single_agent_turn/tests, environment_servers/single_agent_turn_legacy/tests, environment_servers/legacy_agent/tests, responses_api_agents/hermes_sandboxed_agent/tests, resources_servers/swebench_pro/tests, and tests/unit_tests/test_{episode_types,environment_server,rollout_outcomes,failure_kinds,agent_session_retries,agent_sessions,base_responses_api_agent,process_supervisor,local_provider}.py: all pass.
  • responses_api_agents/hermes_agent/tests in its own venv from requirements.txt: all pass.
  • responses_api_agents/simple_agent/tests and resources_servers/example_single_tool_call/tests: all pass.
  • pre-commit run --files on all files changed by the two commits: pass.

Rollout evidence

N/A for the cherry-pick itself. Both changes are applied unchanged from main, except for the one test-file conflict described above. #3554 includes a real-model Hermes with SWE-bench Pro lifecycle smoke rollout.

@copy-pr-bot

copy-pr-bot Bot commented Oct 6, 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.

yaoyu-33 and others added 2 commits October 6, 2026 10:22
## Expected
Harden Hermes sandbox sessions. Data/CLI changes are separate in NVIDIA-NeMo#3818.
Implements
[MB-1694](https://linear.app/nvidia/issue/MB-1694/runbook-onboard-sandboxed-harnesses-to-native-environmentserver).

## Added
- Shared base-agent seed/close retry handling, immutable seed binding,
cookie checks, session locks, and close receipts.
- Confirmed sandbox process cleanup, launch fencing, internal deadlines,
and owned-sandbox teardown. Close confirms cleanup before cancelling
borrowed-sandbox execution.
- Wall-time stops checkpoint partial results; stale PID signaling is
guarded by the remote receipt. Failed setup retains cleanup-only state
through a shared API.
- SWE-Pro keeps its existing scoring and completion rules.
Patch-extraction exceptions remain visible in the task's `error` field
without masking the sample.
- Identical activation retries join or replay the original run. Provider
failures remain retryable and skip verification.
- One request validator and prompt/settings builder for host and sandbox
execution.

## Concerns
- Sandbox prompt composition is unchanged: config system prompt, request
instructions, then input system message. Host execution now combines
these prompts instead of letting config replace the dataset prompt, and
honors request temperature, including zero. `developer` messages now
return 422. These host-path changes can change benchmark scores.
- Unsupported non-default controls return 422, including `top_p=1.0`,
`store`, `service_tier`, and metadata overrides. `model` must match the
configured model. `max_output_tokens` is rejected because Hermes does
not enforce a total-response budget; config `max_tokens` remains per
model call. These 422s are permanent episode errors.
- One activation per session, one agent worker, Linux exec-capable
sandbox. Close retries must finish within the retention window. Final
usage aggregation remains TODO.
- Separate follow-up found during smoke: the iteration-limit summary
sends `function.call_id` / `function.response_item_id` in tool history,
which Gym rejects with 422. The run returns `incomplete`; its existing
patch remains gradable. This update does not fix that summary path.
- Simple Agent (NVIDIA-NeMo#3784) is not modified here. The SWE-Pro recipe still
uses prepared flat rows through `single_agent_turn_legacy` and the
EnvironmentServer session lifecycle.

## Validation
Latest review follow-up: `e378cd45c` (includes the merge-queue assertion
fix in `4df61bf18`).

- Removed the redundant session-lock lookup guard and unused
thinking-setting diagnostics. Close-requested stops now report
`cancelled`, not `wall_time`; deadline behavior and scoring are
unchanged.
- Five targeted regression cases failed on the previous code. Final
focused suite: **563 passed on Linux**; **548 passed, 15 platform skips
on macOS**, Python 3.13.14.
- `pre-commit run --all-files`, `git diff --check`, and **18 Fern link
tests** passed. `cd fern && npm run check`: **0 errors, 1 warning**.
Cleanup docs now identify close ordering, not `setsid()` alone, as the
guarantee.
- Real-model Hermes × SWE-Pro smoke with
`nvidia/nemotron-3-super-120b-a12b` and a 15-second runner limit: 3
model calls, `incomplete` / `stop_reason=wall_time`, reward **0**,
`mask_sample=false`, `evaluation_completed=true`, 18 verifier tests.
Agent close preceded verification; no owned containers/network remained.
Runtime file hashes matched the local revision. This is a lifecycle
smoke, not an accuracy baseline.

<details>
<summary>Latest focused test command</summary>

```bash
python -m pytest \
  environment_servers/single_agent_turn/tests environment_servers/single_agent_turn_legacy/tests \
  environment_servers/legacy_agent/tests tests/unit_tests/test_episode_types.py \
  tests/unit_tests/test_environment_server.py tests/unit_tests/test_rollout_outcomes.py \
  tests/unit_tests/test_failure_kinds.py responses_api_agents/hermes_agent/tests \
  responses_api_agents/hermes_sandboxed_agent/tests resources_servers/swebench_pro/tests \
  tests/unit_tests/test_agent_session_retries.py tests/unit_tests/test_agent_sessions.py \
  tests/unit_tests/test_base_responses_api_agent.py tests/unit_tests/test_process_supervisor.py \
  tests/unit_tests/test_local_provider.py \
  --import-mode=importlib -q -o addopts='' -o log_cli=false --tb=short -rs
```

</details>

Scoring revert: `f06ef8dba888fcffaf86eae265fb63f3411db5f6`.

- `python -m pytest resources_servers/swebench_pro/tests
environment_servers/single_agent_turn/tests
environment_servers/single_agent_turn_legacy/tests
--import-mode=importlib -q -o addopts='' -o log_cli=false --tb=short`:
**135 passed**. Four failure-policy regression cases failed before the
revert, then passed; extraction errors retain the original exception
message.
- `pre-commit run --all-files` and `git diff --check` passed.
- Real-model SWE-Pro HTTP smoke with
`nvidia/nemotron-3-super-120b-a12b`, a 15-second agent limit, and an
invalid Git base injected only in the smoke driver: reward **0**,
`mask_sample=false`, `evaluation_completed=true`, and the actual
extraction exception in `error`. The agent closed before verification;
all owned containers/network were cleaned up. This checks failure
reporting, not benchmark accuracy.
- No documentation change needed: this restores the existing verifier
contract rather than adding an API.

Earlier review-fix validation at
`95a2b6481fa0225fc5a363443d9a536e98cd304f`:

- macOS/Python 3.13.14: **494 passed, 13 platform skips**.
- Linux/Python 3.13.14: **422 passed** across Hermes, shared sessions,
process supervision, SWE-Pro, and Environment Server tests. Final
verifier tests: **49 passed**; final supervisor/runner recheck: **40
passed**.
- Real-process regressions cover provider-group cancellation, lost spawn
handles, detached children, timeout checkpoints (including an
uncooperative worker), stale-PID protection, partial setup, and cleanup
retries.
- Two real-model SWE-Pro HTTP smokes with
`nvidia/nemotron-3-super-120b-a12b`: both reached verification after
agent close, returned valid reward 0, and left no owned containers or
networks. One stopped on model-output truncation; the forced 15-second
wall-time run returned `incomplete` / `stop_reason=wall_time`. Both had
no patch; these are lifecycle checks, **not accuracy baselines**.
Partial-work preservation is separately covered by deterministic
subprocess tests.
- `pre-commit run --all-files` and diff checks passed; Fern: 0 errors, 1
warning. The test import conflict with main was removed without
rebasing.
- Full repository CI is not claimed. The inherited DCO mismatch in
`07ca331ca1e12d234f1a3a60bb12e1651e496786` remains; the new commit is
signed off.

<details>
<summary>Current focused command</summary>

```bash
python -m pytest responses_api_agents/hermes_agent/tests \
  responses_api_agents/hermes_sandboxed_agent/tests \
  tests/unit_tests/test_process_supervisor.py tests/unit_tests/test_local_provider.py \
  tests/unit_tests/test_sandbox_stop_retry.py tests/unit_tests/test_base_responses_api_agent.py \
  tests/unit_tests/test_agent_sessions.py tests/unit_tests/test_agent_session_retries.py \
  tests/unit_tests/test_environment_server.py resources_servers/swebench_pro/tests \
  environment_servers/single_agent_turn/tests \
  --import-mode=importlib -q -o addopts='' -o log_cli=false --tb=short
python -m pre_commit run --all-files
cd fern && npm run check
```
</details>

<details>
<summary>Previous validation at d5f13f5 (historical)</summary>

Head: `d5f13f54cf762c7e687dd2d50d2583efe2c9b717`.

- macOS/Python 3.13.14: **487 passed, 8 skipped** (Linux-only checks).
- Linux/Python 3.13.14: **292 passed**, including Hermes, sessions,
process cleanup, and EnvironmentServer tests. Uploaded source and test
hashes match this commit.
- New regressions failed against the old code: ignored controls and
host/sandbox prompt/settings drift. Also test matching model names, zero
temperature, unchanged input, validation once per request, and rejection
of future non-default schema controls.
- `pre-commit run --all-files`, diff checks, and Fern passed (0 errors,
1 warning). New commit is DCO-signed.
- Fresh real-model public SWE-Pro HTTP smoke using
`nvidia/nemotron-3-super-120b-a12b`: **reward 1.0**, **18/18 verifier
tests passed**, 11,273-byte patch. Verified prompt ordering and
temperature at the Model Server, agent close before verification,
Resources close, and no remaining owned containers/network. Inspected
the patch and verifier results. Agent reached the 20-turn smoke limit
and returned `incomplete`, with the separate summary-call 422 described
above.
- This is one functional smoke, not an accuracy/baseline comparison.
Reused isolated dependency environments; full repository CI is not
claimed. The inherited DCO author/sign-off mismatch in
`07ca331ca1e12d234f1a3a60bb12e1651e496786` is unchanged.

<details>
<summary>Focused commands</summary>

```bash
python -m pytest responses_api_agents/hermes_agent/tests \
  tests/unit_tests/test_agent_session_retries.py \
  tests/unit_tests/test_agent_sessions.py tests/unit_tests/test_base_responses_api_agent.py \
  tests/unit_tests/test_process_supervisor.py tests/unit_tests/test_local_provider.py \
  responses_api_agents/hermes_sandboxed_agent/tests \
  environment_servers/single_agent_turn/tests environment_servers/single_agent_turn_legacy/tests \
  resources_servers/swebench_pro/tests tests/unit_tests/test_resources_sessions.py \
  tests/unit_tests/test_environment_server.py \
  --import-mode=importlib -q -o addopts='' -o log_cli=false --tb=short -rs
# Linux subset:
python -m pytest tests/unit_tests/test_process_supervisor.py tests/unit_tests/test_local_provider.py \
  tests/unit_tests/test_agent_session_retries.py responses_api_agents/hermes_agent/tests \
  environment_servers/single_agent_turn/tests \
  --import-mode=importlib -q -o addopts='' -o log_cli=false --tb=short -rs
python -m pre_commit run --all-files
cd fern && npm run check
```
</details>

</details>

---------

Signed-off-by: Ananth Subramaniam <[email protected]>
Signed-off-by: Marta Stepniewska-Dziubinska <[email protected]>
Signed-off-by: Adil Asif <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Co-authored-by: Ananth Subramaniam <[email protected]>
Co-authored-by: Marta Stepniewska-Dziubinska <[email protected]>
Co-authored-by: Adil Asif <[email protected]>
(cherry picked from commit b846dfa)
Signed-off-by: Ananth Subramaniam <[email protected]>
…ons (NVIDIA-NeMo#3784)

Lets Simple Agent run inside an Environment Server episode through agent
sessions, gives the example single-tool-call Resources Server typed
sessions, and adds a config that runs the example through the
single-agent-turn Environment Server end to end. `/run` is unchanged.

Simple Agent sessions:

- Simple Agent implements only the base agent's session hooks,
`_seed_agent_session_state` and `_close_agent_session_state`. The base
agent's shared bookkeeping from
[NVIDIA-NeMo#3554](NVIDIA-NeMo#3554) handles the rest:
idempotent seed, binding a session to its seed, the session cookie,
retries, and close receipts. The cookie key is one constant,
`AGENT_SESSION_COOKIE_KEY`, in `nemo_gym.base_responses_api_agent`.
- During the session, Simple Agent calls tools through the direct HTTP
tool access the Environment Server grants, which carries the Resources
session cookie. It accepts at most one direct HTTP grant and rejects
sandbox access and required MCP access, which it does not support. A
session without a grant never falls back to the configured Resources
Server, which has no session for the episode: a tool call there fails
the activation.
- When observability is on, the session returns its agent invocation
record at close, where the Environment Server stores it as the episode's
agent observations.
- Sessions live in the worker's memory, so seeding one requires
`num_workers: 1`. `/run` keeps no session and still supports several
workers.
- `resources_server` is optional in the Simple Agent config, because a
session gets its tools from the Environment Server. `/run` and
`/aggregate_metrics` still require it.

Example single-tool-call Resources Server:

- Implements typed, idempotent seed and close by `resources_session_id`.
Close overrides the `close_resources_session` hook; the example no
longer registers its own `/close_session` route, which the base route
takes precedence over.
- `configs/example_single_tool_call_single_agent_turn.yaml` fronts
Simple Agent with `single_agent_turn_legacy` and grants it direct HTTP
access to the example's tools. The existing config, which the quickstart
and training docs use, still runs through `/run`.

`single_agent_turn_legacy` accepts a `task_source` that names its
Resources Server, its agent, or itself. Collation sets `task_source` to
the instance that declares the dataset, usually the agent, so the
adapter rejected collated rows before.

The `close_resources_session` docstring states what a close override
must do: succeed for a session that is already closed or was never
seeded, keep a later seed from recreating a closed session, and raise
when releasing fails so the caller can retry. It also notes that the
default seed does not tie the session cookie to `resources_session_id`.

Contract checks:

-
`nemo_gym.testing.session_conformance.check_resources_session_contract`
is an integration test of a server's session lifecycle: it seeds,
re-seeds and closes a session through the server's real routes and
middleware, in process, and checks the close rules, so it also catches a
shadowed route. The base default and the example run it; a migrated
server calls it from its own tests. `nemo_gym.testing` holds helpers
that tests import.
- `tests/unit_tests/test_session_contract_repo.py` reads every agent and
Resources Server's source, since servers run in their own environments.
It fails when an agent overrides the public seed or close instead of the
hooks, when an agent implements the seed hook without the close hook,
when a Resources Server registers its own `/close_session`, or when a
typed seed has no `close_resources_session`.

No issue is linked; this is part of the Environment Server work.

- `pytest responses_api_agents/simple_agent/tests -q`: 26 passed. A seed
after close now returns 409 from the base bookkeeping instead of a 500.
A session tool call without a grant fails and reaches no Resources
Server; that test fails without the fix.
- `pytest resources_servers/example_single_tool_call/tests -q`: 5
passed, including the session contract check.
- `pytest environment_servers/single_agent_turn/tests
environment_servers/single_agent_turn_legacy/tests -q`: 30 and 12
passed, including `task_source` naming the agent or the Resources
Server, and rejecting another instance.
- `pytest resources_servers/swebench_pro/tests -q`: 96 passed. `pytest
responses_api_agents/hermes_agent/tests -q` (its own venv): 219 passed.
- `pytest tests/unit_tests/test_session_contract_repo.py
tests/unit_tests/test_base_resources_server.py
tests/unit_tests/test_agent_sessions.py
tests/unit_tests/test_agent_session_retries.py
tests/unit_tests/test_base_responses_api_agent.py -q`: all passed. The
repo-wide checks and the contract check each fail when the example
registers its own `/close_session` again; the repo-wide agent check
fails when Simple Agent overrides `close_agent_session`.
- `pytest tests/unit_tests -q`: all passed except tests that need
packages this environment lacks (`opensandbox`, `tenacity`, `mlflow`,
`wandb`) and a Slurm test that calls the system pip.
- `pre-commit run` on the changed files.

`gym dataset collate` on the new config stamped `task_source` with the
agent's name, and the five collated `example_single_tool_call` tasks ran
with `gpt-5.6-sol` through `single_agent_turn_legacy` with no failures.
Three called `get_weather` and scored `1.0`; the other two prompts are
ambiguous ("get the weather for 3 cities in the us", "how's the
outside?"), and the model asked which city was meant, so they scored
`0.0` as the verifier intends.

A stateful check, run locally with `example_session_state_mgmt` given a
typed seed and close (that change is a separate PR) and a
`single_agent_turn` config like the one here: its counter starts at the
task's `initial_count`, so a reward of `1.0` needs the seed, the agent's
tool calls, and verification to reach the same Resources session. With
the direct HTTP grant, all five collated tasks scored `1.0` (for example
3 seeded + 1 + 2 = 6), which confirms the grant's cookie reaches the
seeded session without forwarding cookies on the agent seed request.
With no grant, the earlier code scored `0.0` on all five because tool
calls landed in fresh sessions; with the fix, those episodes fail with
"Model called tool 'increment_counter', but this agent session has no
direct HTTP tool access".

`/run`, its request and result shapes, and existing Simple Agent
configurations are unchanged. `resources_server` becomes optional in the
Simple Agent config, and configurations that set it behave as before.

---------

Signed-off-by: Ananth Subramaniam <[email protected]>
(cherry picked from commit e0e63e5)
Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the cherry-pick/r0.7.0-agent-sessions branch from b451fef to 1e6e8c3 Compare October 6, 2026 17:24
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 6, 2026 17:25
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 6, 2026 18:25
@ananthsub
ananthsub enabled auto-merge (squash) October 6, 2026 18:26
@ananthsub
ananthsub merged commit 6e461ff into NVIDIA-NeMo:r0.7.0 Oct 6, 2026
42 checks passed
ananthsub pushed a commit that referenced this pull request Oct 7, 2026
## What

This PR manually cherry-picks the already-merged
[#3800](#3800) into `r0.7.0`. It
adds no new runtime behavior. The commit was applied with `git
cherry-pick -x`, so its message records source commit `804c12a7d`.

The current release branch already contains the shared taskset,
multi-agent, metrics, and session dependencies through
[#4107](#4107) and
[#4113](#4113).

## Why

#3800 has the `r0.7.0` label, but the automatic cherry-pick workflow
could not apply it and reported "3-way merge impossible". A manual
backport is therefore required.

## Conflict resolution

The runtime, configs, tests, and example artifacts applied unchanged.
The only conflict was `.github/workflows/config/.secrets.baseline`:

- Kept the current `r0.7.0` baseline entries.
- Added only #3800's six reviewed findings for
`resources_servers/nemo_user_sim/data/example_rollouts.jsonl`.
- Did not copy the unrelated
`resources_servers/deepswe_external1/data/review_smoke.json` baseline
block from the `main` snapshot because that file is not part of #3800 or
this release-branch diff.

All files under `environment_servers/nemo_user_sim` and
`resources_servers/nemo_user_sim` are byte-identical to source commit
`804c12a7d`.

## Validation

- Isolated `resources_servers/nemo_user_sim` suite: **22 passed**, 1
warning.
- Isolated `environment_servers/nemo_user_sim` suite: **26 passed**.
- `git diff --exit-code 804c12a -- environment_servers/nemo_user_sim
resources_servers/nemo_user_sim` — passed.
- `pre-commit run --all-files` — passed.
- `git diff --check origin/r0.7.0...HEAD` — passed.

## Rollout evidence

N/A for this manual cherry-pick: runtime code and artifacts are
unchanged from #3800. The source PR includes five inspected live
rollouts and their compact committed evidence.

Signed-off-by: Felipe Vieira Frujeri <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 037946b7 Deployed Oct 6, 2026 by copy-pr-bot[bot] via release / finalize / notify #4451
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.

3 participants