Repository navigation
fix(ns_tools): release python_tool sessions in close_resources_session - #5479
Conversation
ns_tools keys a stateful NeMo Skills python session and the rollout's tool timings by the session cookie, and released both only in /verify. Under single_agent_turn_legacy, an episode that never reached /verify (agent failure, skip_verification, cancellation) kept its sandbox python session until the server shut down, because the inherited close_resources_session kept no state. - seed_session binds a typed seed's resources_session_id to the cookie and records its episode and task; the legacy /run seed body keeps no state. - close_resources_session releases the python session and timings by resources_session_id, fences late seeds with ResourcesSessionFence, is idempotent, and raises when cleanup fails so the caller can retry. - A tool call for a closed session gets ResourcesSessionLostError (404); a call that a close overtook releases the python session it recorded. - A /verify for a closed session returns lost_session_verification. - Drop the unreachable random-uuid fallback for a missing session ID. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test c131fde |
Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…the release fails The DELETE that releases a python session passed no retry bound, and Gym's request helper retries refused connections without limit, so a restarting sandbox held close (and the session's fence) forever. It now gives up after three tries, like Skills' own delete, and close fails for the caller to retry. Verify's finally now awaits a release that can raise, so a failed DELETE replaced a scored verify with a 500. Verify logs the failure and keeps the score; the python session stays owned, so close retries the release. The release also runs under the session's fence, so a tool call still running records its python session first. The closed check after a tool call could never fire under that fence and is gone. Tests: an unreachable sandbox, a failed release at verify (both fail on the previous code), and the cancellation test now races a real close against the in-flight POST. The conformance import moves to nemo_gym.server_runtime.testing. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 0542b9e |
Signed-off-by: yaoyu-33 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…ycle - The repo contract test counts a server that implements the state hooks as closing through the inherited close_resources_session. newton_bench, workplace_assistant, tavily_search and indirect_prompt_injection override seed_session but close through the hooks, and failed it. - Export reject_partial_typed_seed from nemo_gym.server_runtime, so servers that override seed_session reuse the shared guard instead of a copy. - The MCP seed wrapper still recognises a request param annotated as Annotated[Request, ...]; keeping Annotated metadata had made it inject a second Request and fail with KeyError. - Name the 409 for a typed seed over a cookie session "cookie-seeded", not "legacy", and document that a served seed_session override declares request before body. - Shared tests now cover the MCP-wrapped seed route, close after verify (checked against the verified episode), and a cookie seed of a verified typed session. - The add-benchmark skill describes the three state hooks as the default for a stateful server. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
The inherited retire_session_state recorded a typed session as closed. The checkpoint participant also calls that hook to undo a restore (delete_restored) and to drop an unclaimed session, and both promise to refuse nothing later; with the fence, a restore that was rolled back and installed again in the same process left its session fenced, so its verify was masked as lost and its continuation's seed got 409. The participant already refuses a retired attempt's requests until it forgets the rollout, so retirement now releases the state and drops the identity without recording a close. A close still fences. Also write down that an exported server using the state hooks carries each session's identity through its checkpoint itself. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test b7d76b5 |
The docs now describe only the typed Environment Server path. The cookie seed still works unchanged; the PR description records that compatibility. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 399220b |
Signed-off-by: yaoyu-33 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 634dd42 |
| """Run the tool before close can acknowledge releasing its Python session.""" | ||
| # Skills records ownership only when execution returns. Close must wait for that record instead of | ||
| # fencing an empty session and relying on a later, unreported best-effort cleanup. | ||
| async with self.session_lock(request.session[SESSION_ID_KEY]): |
There was a problem hiding this comment.
Nit: this lock wraps every tool call, not only stateful_python_code_exec, so the arxiv/wikipedia/coolprop configs also serialize per rollout, and close waits behind them. The Compatibility note only mentions the Python tool. Either scope the lock to DirectPythonTool calls, or widen the note to "all ns_tools tool calls on one rollout run one at a time". simple_agent already runs calls sequentially, so this is mostly documentation.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42739018636 |
Release the lazily created Skills Python session through the shared resources lifecycle, including runs that skip verification. The server now inherits seed, close and checkpoint retirement from #5709 and performs scoring inside its public verification context.
The shared lifecycle in #5709 and MCP support in #5708 are merged into main. The child diff contains only this environment and its related documentation/configuration; shared implementation is reviewed once in the dependency. No separate issue is needed for this focused migration of an existing resources server.
Retains its timing metrics (
retain(metrics)) before delegating, so a retry re-judges with the original totals; the delegated verifier's judge-failure mask is preserved by the #5677 fix now included here.Validation on
b7d76b55d6fec6f5e31cf8e7828bf08406e71624, Python 3.13.14, with this checkout first on PYTHONPATH and NEMO_GYM_EXTRA_ROOTS pointing to it:python -m pytest -o addopts='' -o log_cli=false resources_servers/ns_tools/tests -q --tb=short: 54 passed.ruff check,ruff format --checkandgit diff --checkpassed on the changed files. The private guardwords catalog was unavailable, so that scan was skipped. New commits include DCO sign-off.Real-model smoke on preceding migration revision
af11d42c5c6e7ff3b8aa386876ad3fa95b4f9f3a(shared core4e92d4891) usednvidia/nemotron-3.5-lightning-30b-a3b, Python 3.13.14 and a real Skills IPython backend. Both typed normal and skip-verification cases executed the arithmetic tool and observed 385. Normal verification scored 1.0; the skip case made zero verify calls and returned its configured fixed reward 0.0. Close returned 200; the skip case reduced live backend sessions 1 → 0, and timing/session/identity maps were empty. Loaded source hashes matched that revision. The shared runner separately recorded the Litmus storage-cleanup failure; both NS case receipts passed. This synthetic task validates lifecycle behavior, not benchmark accuracy or the optional LLM judge. Retry and cleanup-failure paths are covered by unit tests only at this head.These targeted checks do not replace the repository CI matrix or approval of the current head.
Compatibility
A tool call after
/verify(withinsession_close_retry_window_seconds) or after close now gets 404failure_kind: session_lost; main silently created a new Python session. Concurrentstateful_python_code_execcalls on one rollout now run one at a time (the session lock covers the whole call). A sandbox DELETE that still fails after 3 bounded attempts now fails/close_sessionand a cookie reseed with 500 and keeps ownership; on main the Skills cleanup logged and dropped the mapping (/verifystill returns its score). A request without a session ID no longer gets a generateduuid4session. This branch includes #5677 and uses its dict-merge form for the delegated verdict.Main refresh validation
Merged main at
acb67734cinto this branch, retaining main's MCP annotation resolution and seed-validation regressions. The diff against main contains only this environment and its related documentation/configuration. No new environment behavior was added by this refresh.On workstation
ws(Python 3.13.14), this environment's complete test directory passed: 54 passed. The nine environment suites passed 904 tests in total. Shared lifecycle, MCP seed/exposure, and process-supervisor tests passed 213 tests. Tests ran in a combined validation checkout with the merged core and the exact environment sources from these nine heads, with the checkout first on PYTHONPATH and NEMO_GYM_EXTRA_ROOTS. Prior real-model smoke evidence above remains historical; no fresh model rollout was run for this merge-only update. New merge commits are DCO signed off.pre-commit run --all-filespassed on the combined checkout, including Ruff, formatting, guardwords, config flags, environment table generation, and import layering. The generated README row matches the row already included in #5485.git diff --checkpassed for each refreshed branch.Cross-environment consistency fixes
Retain the in-flight Python POST across both asyncio and AnyIO cancellation. Cleanup and subsequent execution wait for that bounded request, including after a cancelled close, so DELETE cannot race ahead of allocation. Includes the existing #5677 fix: delegated verifier masks and failure details override stale request fields. Three live HTTP cancellation regressions fail against the preceding head and pass here.
Validation at
634dd42526154a9dae46f489c20f5bc998428608onws, Python 3.13.14: this environment suite 71 passed; the three changed environment suites total 228 passed. Fullpre-commit run --all-filespassed in the combined validation checkout. All 59 tracked files in the three changed environments matched the local final sources by SHA-256. Three independent component reviewers examined the nine environments; a second reviewer challenged the worker/cancellation fixes. The six other environment branches required no additional changes.No fresh NS model rollout was run for this cancellation and verdict-propagation correction. The new failure paths were reproduced with a live aiohttp backend and real Skills client; delegated verdict propagation uses the actual verifier response contract.