Skip to content

feat(resources): answer Environment Server seed and close by default - #3786

Merged
ananthsub merged 2 commits into
mainfrom
ananthsub/resources-session-defaults
Sep 30, 2026
Merged

ananthsub merged 2 commits into
mainfrom
ananthsub/resources-session-defaults

Conversation

@ananthsub

Copy link
Copy Markdown
Contributor

What does this PR do?

Lets any Resources Server take part in an Environment Server episode without writing session code.

The single-agent-turn Environment Server seeds each episode with a typed ResourcesSeedSessionRequest, expects the caller's resources_session_id back, and closes the session through /close_session during cleanup. On main, only Resources Servers that implement both calls themselves can run an episode. For every other server, the base /seed_session returns an empty body that fails validation, so the episode fails before verification, and /close_session returns 404.

SimpleResourcesServer now answers both calls by default:

  • /seed_session accepts a ResourcesSeedSessionRequest and returns its resources_session_id. An Agent's /run still seeds with its legacy body and still gets the empty response, so existing agents are unaffected.
  • /close_session is registered in the base and calls close_resources_session, which does nothing by default.

A Resources Server with per-rollout state overrides seed_session() and close_resources_session(). The hook is not called close_session because several Gymnasium-based servers (gymnasium, openair_congestion, tales) already define a close_session(session_id) helper for their own state. Registering that name would have exposed those helpers as HTTP routes with the wrong signature.

SWE-bench Pro, the only server on main with its own /close_session, moves its handler onto the hook. The base route is registered first, so a route the server registered itself would never be reached. Its behavior is unchanged: the same handler still accepts both the typed close and the empty cookie-session close that hermes_sandboxed_agent sends.

The Resources Server API guide describes the defaults and when to override them.

Issue

No issue is linked. This fills a gap found while reviewing the Environment Server stack (#3720).

Validation

  • pytest tests/unit_tests/test_base_resources_server.py -q: 14 passed. A new HTTP-level test checks that a server with no session code answers a typed seed with its resources_session_id, a legacy seed with an empty body, and a typed close. It fails on main.
  • pytest resources_servers/swebench_pro/tests -q: 84 passed, including the HTTP test that sends a typed close, an empty cookie close, and a malformed close to /close_session.
  • gym env test for gymnasium (10), grl_sokoban (9), and tales (10), which define their own close_session, and for finance_sec_search (96), which calls super().seed_session(); all pass. example_mcp_weather (6) and example_session_state_mgmt (1) pass.
  • 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

N/A. This adds default responses to two session calls that main's agents do not make, and moves SWE-bench Pro's close handler without changing its behavior, which its HTTP tests cover. No agent on main seeds typed sessions yet, so an end-to-end Environment Server episode needs #3784 or #3720.

Compatibility

  • Legacy /seed_session bodies get the same empty response as before, and servers that override seed_session() are unchanged.
  • A server that registers its own /close_session route after calling super().setup_webserver() is shadowed by the base route and must override close_resources_session() instead. On main that applies only to SWE-bench Pro, which this PR migrates. #3784 also registers one for the example single-tool-call server. Whichever of the two PRs merges second should move that server onto the hook.

SimpleResourcesServer now serves an Environment Server's typed session calls without overrides. /seed_session
accepts a ResourcesSeedSessionRequest and returns the caller's resources_session_id, while an Agent's /run keeps
getting the empty legacy response. /close_session is registered in the base and calls close_resources_session,
which does nothing by default. A Resources Server without per-rollout state can therefore run through
single_agent_turn unchanged; before, its seed reply failed validation and /close_session returned 404.

The hook is named close_resources_session so it does not expose the close_session helpers that Gymnasium-based
servers already define for their own state. SWE-bench Pro moves its close handler onto the hook, since the base
route is registered first and would otherwise shadow a route the server registers itself.

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

Copy link
Copy Markdown
Contributor

@yaoyu-33 yaoyu-33 added area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer labels Sep 29, 2026
Comment thread nemo_gym/base_resources_server.py Resolved
… seeds

With expose_tools_over_mcp on, the seed wrapper added an "mcp" key to every
seed reply. An Environment Server validates the reply as
ResourcesSeedSessionResponse, which forbids extra keys, so a server that keeps
the default seed and opts into MCP failed the seed check. Typed seeds now get
the MCP metadata in resources_tools, which single_agent_turn grants to the
agent; the per-session tool hook sees the task's fields. Legacy seeds keep the
"mcp" key.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub enabled auto-merge September 30, 2026 00:06
@ananthsub
ananthsub added this pull request to the merge queue Sep 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/36649153226

@ananthsub ananthsub linked an issue Sep 30, 2026 that may be closed by this pull request
7 tasks
@ananthsub
ananthsub removed this pull request from the merge queue due to a manual request Sep 30, 2026
@ananthsub
ananthsub added this pull request to the merge queue Sep 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/36650613718

Merged via the queue into main with commit a539e77 Sep 30, 2026
43 checks passed
@ananthsub
ananthsub deleted the ananthsub/resources-session-defaults branch September 30, 2026 00:43

This branch was previously deployed

1 inactive deployment
public — 08fb1c4a Deployed Sep 29, 2026 by copy-pr-bot[bot] via release / finalize / notify #4000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:env-infra Shared environment framework, lifecycle, registry, scaffolding, and validation complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(core): define resources-session identity and close protocol

3 participants