Repository navigation
Conversation
ananthsub
force-pushed
the
ananthsub/session-state-mgmt-sessions
branch
from
October 5, 2026 21:35
399e05a to
04a97ce
Compare
The example seeded only an Agent's legacy body, so a typed Environment Server seed returned 422. It now accepts a typed seed, reading initial_count from task_data and keying the counter by resources_session_id, and closes through close_resources_session. A closed session cannot be recreated by a late seed or tool call. The legacy /run path is unchanged. Signed-off-by: Ananth Subramaniam <[email protected]>
…nvironment Server Adds a config that fronts Simple Agent with single_agent_turn_legacy and grants it direct HTTP access to the counter tools, and checks the server with the shared session contract check. Both needed Simple Agent sessions and nemo_gym.testing from #3784. Signed-off-by: Ananth Subramaniam <[email protected]>
…e Environment Server sessions The tutorial told servers to overwrite state on a repeated seed. A repeated seed for the same session is a retry of the same episode, so it must keep the session. The tutorial now also shows the example's typed seed and close. Signed-off-by: Ananth Subramaniam <[email protected]>
ananthsub
force-pushed
the
ananthsub/session-state-mgmt-sessions
branch
from
October 5, 2026 22:42
04a97ce to
d1ae09b
Compare
Contributor
zyzhou5
reviewed
Oct 6, 2026
zyzhou5
left a comment
Contributor
There was a problem hiding this comment.
Overall LGTM. The only thing is that I found the naming of single_agent_turn to be a bit confusing especially when we aim to distinguish between legacy path and the new path.
yaoyu-33
reviewed
Nov 3, 2026
yaoyu-33
left a comment
Contributor
There was a problem hiding this comment.
Reviewed head d1ae09b39c8108d385322b93173f33955c49a886 against main at c6cad9e52.
Already on main
- This example already serves typed sessions, but only through the NOOA subclass.
NOOAStatefulCounterResourcesServerinnooa_app.py(#3846) has a typed seed with an identity check, a close that records the closed ID inClosedResourcesSessionRecords, and a409for tool calls on a session that isn't open. It is wired byexample_session_state_mgmt_nooa.yaml(single_agent_turn+nooa_agent). - The base
app.pyis still legacy-only. It now declarescheckpoint_mode = "exported"with export, restore and retire hooks. - The contract helpers have grown since this PR opened (#4679, #4692):
ResourcesSessionFence,ResourcesSeedRejectedError(422),ResourcesSessionConflictError(409),ResourcesSessionLostError(404) andlost_session_verification.check_resources_session_contractnow also checks conflicting seeds and closes, and optionally the masked verify after close.
What this PR still adds
- A typed seed and close on the base server, so any Environment Server and agent can use it without the NOOA subclass.
example_session_state_mgmt_single_agent_turn.yaml, which runs the example assingle_agent_turn_legacy+simple_agentover direct HTTP. Main has no config like it.- The tutorial fix.
stateful-environment.mdxonmainstill recommends overwriting the counter on a repeated seed, which contradicts the idempotent-seed rule. - Conformance and lifecycle tests for the base server.
Contract gaps. I ran this PR's app.py, with its imports moved to main's paths, through main's check_resources_session_contract:
- No conflict check. A seed with the same
resources_session_idand another episode returns200, because ofsetdefault. The close doesn't compareepisode_ideither. The PR's owntest_follows_the_session_contract(keeps_state=True) fails onmainat that step. Record(episode_id, task_id)per session and raiseResourcesSessionConflictError, asexample_single_tool_call/app.pydoes. - Unbounded closed set. Closed IDs live in a
setthat is never pruned.ResourcesSessionFence(session_close_retry_window_seconds)bounds it and also serializes seed and close. - Malformed
task_datareturns500.StatefulCounterSeedSessionRequest.model_validate(body.task_data)raises a bareValidationError, so the Environment Server reruns the whole episode. Wrap it inResourcesSeedRejectedError(422). - Lost sessions.
- A tool call after close gets
409rather thanResourcesSessionLostError(404). - A tool call for a never-seeded session still creates a counter via
setdefault(..., 0). /verifyafter close returnsreward 0.0unmasked; it should returnlost_session_verification(...).- Passing
verify_body=to the conformance check covers the verify case.
- A tool call after close gets
- Cookie bound before the closed check. The typed seed sets
request.session[SESSION_ID_KEY]before raising for a closed ID, so a refused reply can carry that session's cookie. Bind it after the checks pass. - Two implementations after rebase.
nooa_app.pyoverrides seed, close and the tools with its own records. Consider moving one fence-based typed seed and close intoapp.pyand lettingnooa_app.pyinherit it, rather than keeping both.
Needs a rebase.
app.pyandtests/test_app.pyconflict withmain.- The imports use modules that no longer exist:
nemo_gym.base_resources_server,nemo_gym.server_utilsandnemo_gym.episode_typesare nownemo_gym.server_runtime,nemo_gym.clientandnemo_gym.core. ray_enabled = Falsewas dropped onmain(#4470), and the rebase should keepmain's checkpoint hooks.- The tutorial merges cleanly, but its snippet should show the fence and the conflict checks once they're in.
7 tasks done
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 does this PR do?
Lets the example session-state Resources Server serve Environment Server sessions, and runs it through one. It seeded only an Agent's legacy body, so a typed seed from an Environment Server returned 422.
initial_countfromtask_dataand keys the counter byresources_session_id, binding the session cookie to it so the agent's tool calls and verification find the same counter. Seeding the same session again keeps the existing counter.close_resources_sessionreleases the counter. A seed or tool call that arrives after close gets 409, so a closed session cannot be recreated.configs/example_session_state_mgmt_single_agent_turn.yamlfronts Simple Agent withsingle_agent_turn_legacyand grants it direct HTTP access to the counter tools. The existing configs, including the nooa one, still run through/run.nemo_gym.testing.session_conformance.check_resources_session_contract.This example makes a strong end-to-end check of session plumbing: its counter starts at the task's
initial_count, so a reward of1.0needs the seed, the agent's tool calls, and verification to reach the same Resources session.Issue
No issue is linked; this is part of the Environment Server work and builds on #3784, now on
main.Validation
pytest resources_servers/example_session_state_mgmt/tests -q: 3 passed. They cover the shared contract check and a lifecycle test that seeds through the typed route, counts from the seeded value with the seed's cookie, closes, and checks that a late tool call and a late seed both get 409.pytest tests/unit_tests/test_session_contract_repo.py tests/unit_tests/test_task_data.py -q: 365 passed.gym env resolveon the new config resolves tosingle_agent_turn_legacyfronting the session agent.cd fern && npm run check: 0 errors, 1 existing warning.pre-commit runon the changed files.Rollouts
gpt-5.6-solthrough the new config on this branch, on the example dataset aftergym dataset collate: all five tasks scored1.0, and every count included the seeded start (for example 3 seeded + 1 + 2 = 6). Earlier, with no tool grant, the same tasks scored0.0because tool calls landed in fresh sessions; Simple Agent now fails such episodes instead.Compatibility
No change to the legacy
/runpath, its request or result shapes, or existing configs.