Repository navigation
feat(swe): serve typed resources sessions from SWE-Gym and R2E-Gym - #4302
Conversation
Add resources_servers/swebench/task_sandbox_sessions.py, a shared helper for SWE resources servers whose seed starts one task sandbox, and use it in swe_gym and r2e_gym. An Environment Server can now seed a typed session, hand the agent the task sandbox through sandbox_access, verify, and close. The legacy seed body and response are unchanged. Signed-off-by: Ananth Subramaniam <[email protected]>
e8a8665 to
652d384
Compare
| except Exception: | ||
| # The provider ends the sandbox at its ttl_s; keep no reference to it here. | ||
| LOG.exception("Failed to stop the task sandbox of abandoned session %s", session_id) | ||
| self._session_id_to_sandbox.pop(session_id, None) |
There was a problem hiding this comment.
Could we retain the sandbox handle and allow cleanup to retry when this stop fails? Dropping it and marking the session closed prevents later close/shutdown from retrying (reproduced). Apptainer, Enroot and OpenShell do not enforce TTL, so the sandbox can remain running.
There was a problem hiding this comment.
Fixed in fb5525f. A failed stop now keeps the handle for expiry, close, a failed seed's cleanup, verify teardown and shutdown: the handle is dropped only after _stop() succeeds (_stop_task_sandbox, expiry). Covered by test_expiry_failed_stop_retains_owner_until_explicit_close. d8e7774 also retries a stuck expired session once per EXPIRY_RETRY_INTERVAL_S instead of on every request.
| raise ValueError("resources_session_id is already bound to another episode or task") | ||
| return await self._task_sandbox_response(session_id, record) | ||
| row_task_id = _row_task_id(body.task_data) | ||
| if row_task_id is not None and row_task_id != body.task_id.task_id: |
There was a problem hiding this comment.
Could we preserve the caller-assigned TaskId instead of deriving it again here? For a supported row shaped as {responses_create_params, task_data: {instance_id: ...}}, materialization assigns the row-index ID (e.g. 0). This comparison then rejects it against the nested instance_id before the sandbox starts.
There was a problem hiding this comment.
Fixed in fb5525f. The caller's TaskId is no longer re-derived from task_data: a replayed seed must equal the whole seed request, otherwise 409 (seed), and the task is parsed from task_data alone (L241). A row with outer TaskId 0 and a nested instance_id now seeds, replays and verifies; see test_caller_assigned_task_id_is_independent_of_nested_task_data and test_envelope_task_id_is_independent_but_rebinding_and_wrong_task_are_rejected.
| await _stop(sandbox) | ||
| except BaseException as error: | ||
| record = self._task_sessions.get(session_id) | ||
| if record is not None and record.closed_episode_id is None: |
There was a problem hiding this comment.
Could verify's release and close coordinate cleanup ownership under the session lock? Verify removes the handle before awaiting stop; a concurrent close can see no sandbox and mark the session closed. If stop then fails, this condition prevents restoring the handle, so later close/shutdown cannot retry cleanup.
There was a problem hiding this comment.
Fixed in fb5525f. Verify, including the task-sandbox stop, now runs under the same session lock as close (verify, close), and the handle is dropped only after a successful stop, so a failed stop leaves the session unfenced and retryable. Covered by test_close_waits_for_failed_verification_stop_and_keeps_retry_ownership.
|
💬 The logs show five core-test failures caused by missing dependency manifests for |
|
💬 The dependency fix has already merged in #5629 as |
|
💬 The merge with current main staged without conflicts. I haven’t run its tests yet: the nightly CI run for the same dependency recipe is still queued. I’ll validate the staged merge once that run produces a usable container. |
|
💬 The nightly container built successfully, and I prepared signed merge candidate |
|
⏳ Sandbox |
…essions Picks up the opencode_search component lock files (#5629) so the component-lock checks pass on this branch. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 82c5204 |
|
⏳ Sandbox |
|
💬 The author merged main in |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41954706395 |
|
💬 All core and server test shards and |
|
The PR is no longer an open ready-to-merge PR targeting main. |
|
The PR is no longer an open ready-to-merge PR targeting main. |
SWE-Gym and R2E-Gym now expose resources-owned task sandboxes through typed sessions, so an Environment Server can seed the task, lend sandbox access to an agent, verify the patch, and close the session. The shared implementation is in
resources_servers/swebench/sandbox_sessions.py; #4277 consumes it for SWE-bench.The update merges main at
74b307063d116827bf42537d5d9f533f318e2a16while preserving the author's history. Seed, verify, expiry and close coordinate ownership; failed task/verifier teardown retains the handle for retry. Typed retries reuse the captured patch or verdict. Task identity comes from the caller's canonicalTaskId, with conflicting replay inputs rejected. Missing/closed sessions return maskedSESSION_LOST, and expired sessions returnSESSION_EXPIRED. Legacy seed and seedless golden-patch verification remain supported.No separate issue is needed: this addresses the existing lifecycle and identity review feedback on this PR. The follow-up branches #4303 and #4304 still need to incorporate the updated parent.
Validation at
fb5525f87dbd56d6070e38b68c8405823cbbc8fb:pytest resources_servers/swe_gym/tests resources_servers/r2e_gym/tests resources_servers/swebench/tests/test_sandbox_sessions.py tests/unit_tests/test_session_contract_repo.py tests/unit_tests/server_runtime/test_resources_sessions.py tests/unit_tests/data/test_task_materialization.py --import-mode=importlib -q: 235 passed on Python 3.13.14.pre-commit run --all-filespassed. New commit has DCO sign-off.652d384helper and pass after the fix: canonical outer TaskId, failed expiry cleanup, and verify/close overlap with failed teardown.Real-model smoke on Linux/Docker using current
opencode_agent,single_agent_turnandnvidia/nemotron-3.5-super-vl-120b-a12b:iterative__dvc-1651pillow__6e97dd5cecc074a0d8622e4aa5658b4263324760Both rollouts used outer TaskId
caller-row-0, distinct from the benchmark instance ID, and left no task containers. Changed runtime files were hash-checked against the committed source. These are representative plumbing/verification smokes, not a full benchmark or a solve-rate comparison. Existing grading rules and anti-cheating behavior are preserved; provider-failure paths are covered by deterministic tests rather than live fault injection.