Repository navigation
cp: Hermes session hardening and simple agent environment server sessions (#3554, #3784) into r0.7.0 - #4113
Merged
ananthsub merged 3 commits intoOct 6, 2026
Conversation
## 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
force-pushed
the
cherry-pick/r0.7.0-agent-sessions
branch
from
October 6, 2026 17:24
b451fef to
1e6e8c3
Compare
Contributor
ffrujeri
approved these changes
Oct 6, 2026
ananthsub
enabled auto-merge (squash)
October 6, 2026 18:26
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
This PR only cherry-picks two already-merged
mainPRs intor0.7.0. It adds no new code. Each commit is applied withgit cherry-pick -x, so its message records the source commit.mainb846dfaa5e0e63e526This 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.0label, but the automatic cherry-pick workflow could not apply it: it hit a merge conflict innemo_gym/base_responses_api_agent.pyand 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.pythat #3784 extends. With #3554 applied first, the conflict in that file goes away. #3554 has nor0.7.0label; it is included on purpose.Behavior changes from #3554
#3554's own description lists these, and they now apply on
r0.7.0too:developermessages with 422. These changes can change benchmark scores for Hermes on the host path.top_p=1.0,store,service_tier, metadata overrides,max_output_tokens, and amodelthat does not match the configured model.Conflict resolution
environment_servers/single_agent_turn_legacy/tests/test_app.py. feat(simple-agent): run simple agent through environment server sessions #3784 adds twotask_sourcetests next to a test that refactor: name episode requests and sessions without "native" #4070 (already onr0.7.0through cp: tasksets, episode-request naming, and multi-agent environment servers (#3818, #4070, #3929, #4053) intor0.7.0#4107) renamed. The resolution keeps both, and the new tests call the adapter method by its post-refactor: name episode requests and sessions without "native" #4070 name,_episode_request_from_row. The resulting file is identical to the file onmain.Validation
pytest tests/unit_tests -n 8: same failures as unmodifiedr0.7.0and no new ones. The existing failures are local-environment tests intest_opensandbox_compose.py,test_sandbox_stop_retry.py, andtest_slurm_script.py.--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, andtests/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/testsin its own venv fromrequirements.txt: all pass.responses_api_agents/simple_agent/testsandresources_servers/example_single_tool_call/tests: all pass.pre-commit run --fileson 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.