Skip to content

feat(swe): serve typed resources sessions from SWE-Gym and R2E-Gym - #4302

Merged
yaoyu-33 merged 4 commits into
mainfrom
ananthsub/swe-typed-sessions
Nov 5, 2026
Merged

yaoyu-33 merged 4 commits into
mainfrom
ananthsub/swe-typed-sessions

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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 74b307063d116827bf42537d5d9f533f318e2a16 while 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 canonical TaskId, with conflicting replay inputs rejected. Missing/closed sessions return masked SESSION_LOST, and expired sessions return SESSION_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.
  • CI example-data validation for SWE-Gym, R2E-Gym and SWE-bench passed; pre-commit run --all-files passed. New commit has DCO sign-off.
  • Three production-method negative controls fail on the original 652d384 helper and pass after the fix: canonical outer TaskId, failed expiry cleanup, and verify/close overlap with failed teardown.
  • Independent source review covered lifecycle, cancellation, hidden-test isolation and compatibility.

Real-model smoke on Linux/Docker using current opencode_agent, single_agent_turn and nvidia/nemotron-3.5-super-vl-120b-a12b:

Resources Task Observed verification
SWE-Gym iterative__dvc-1651 Nonempty model patch; 2 tests passed; reward 1; unmasked
R2E-Gym pillow__6e97dd5cecc074a0d8622e4aa5658b4263324760 387-byte model patch; expected test passed; reward 1; unmasked

Both 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.

@ananthsub ananthsub added feature New capabilities, enhancements, or enablement work area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers needs-review PR is ready for code review and waiting on a reviewer labels Oct 9, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 9, 2026 16:50
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]>
@ananthsub
ananthsub force-pushed the ananthsub/swe-typed-sessions branch from e8a8665 to 652d384 Compare October 9, 2026 17:13
@yaoyu-33 yaoyu-33 added the complexity:high Cross-component or shared-contract change with a large review surface label Oct 9, 2026
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Oct 12, 2026
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

💬 The logs show five core-test failures caused by missing dependency manifests for opencode_search; the component-lock check also rejects that module. A separate OpenClaw test fails during cancellation cleanup. I’m comparing these failures with current main before choosing a repair or retry.

Copy link
Copy Markdown
Contributor

💬 The dependency fix has already merged in #5629 as 653846f9, but this PR doesn’t contain it. I’ll prepare and test a staged merge of current main without pushing directly to the author’s branch. The Kilo conformance failure also occurs at current main and has an existing repair in #5088, so I won’t duplicate it.

Copy link
Copy Markdown
Contributor

💬 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.

Copy link
Copy Markdown
Contributor

💬 The nightly container built successfully, and I prepared signed merge candidate e19cf31b against main 1a253ae2. Validation hasn’t started: the image exists in ECR, but its exact validation-cluster mirror isn’t pullable yet. I’m waiting for that transfer before running the checks.

Copy link
Copy Markdown
Contributor

⏳ Sandbox ci-events-agent-write-73f57a69 remains Pending because no eligible node currently has the requested capacity. The original workload and wait are retained to avoid duplicate queued work. This scheduler status does not prove natural turnover will free capacity: if eligible nodes have no finite workload to release it, the pool must scale or the request must be reduced. No retry, cancellation, or relaunch was started. Scheduler: Unschedulable: 0/36 nodes are available: 29 node(s) didn't match Pod's node affinity/selector, 3 Insufficient cpu, 3 Insufficient memory, 4 node(s) had untolerated taint(s). no new claims to deallocate, preemption: 0/36 nodes are available: 3 No preemption victims found for incoming pod, 33 Preemption is not helpful for scheduling. (since 2026-11-05T01:50:43Z).

…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]>
@yaoyu-33

yaoyu-33 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

/ok to test 82c5204

Copy link
Copy Markdown
Contributor

⏳ Sandbox ci-events-agent-write-e45a8433 remains Pending because no eligible node currently has the requested capacity. The original workload and wait are retained to avoid duplicate queued work. This scheduler status does not prove natural turnover will free capacity: if eligible nodes have no finite workload to release it, the pool must scale or the request must be reduced. No retry, cancellation, or relaunch was started. Scheduler: Unschedulable: 0/36 nodes are available: 29 node(s) didn't match Pod's node affinity/selector, 3 Insufficient cpu, 3 Insufficient memory, 4 node(s) had untolerated taint(s). no new claims to deallocate, preemption: 0/36 nodes are available: 3 No preemption victims found for incoming pod, 33 Preemption is not helpful for scheduling. (since 2026-11-05T02:01:57Z).

Copy link
Copy Markdown
Contributor

💬 The author merged main in 82c52048, including the dependency repair from #5629. Its source tree matches my staged candidate, so no separate merge publication is needed. Both component-lock checks now pass; the remaining CI was still running at my last check. I’ll keep watching until GitHub reports the PR merged.

@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41954706395

Copy link
Copy Markdown
Contributor

💬 All core and server test shards and Nemo_CICD_Test passed on 82c52048. The workflow remains red because the non-blocking Kilo model-error probe failed; its logs point to the failure path already covered by repair PR #5088. I found no evidence to justify an infrastructure or flaky-test retry. The PR remains open, so I’ll keep watching for merge.

Merged via the queue into main with commit c0a0697 Nov 5, 2026
68 of 71 checks passed
@yaoyu-33
yaoyu-33 deleted the ananthsub/swe-typed-sessions branch November 5, 2026 02:37

Copy link
Copy Markdown
Contributor

The PR is no longer an open ready-to-merge PR targeting main.

Copy link
Copy Markdown
Contributor

The PR is no longer an open ready-to-merge PR targeting main.

This branch was previously deployed

1 inactive deployment
public — 82c52048 Deployed Nov 5, 2026 by copy-pr-bot[bot] via release / finalize / notify #10226
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers complexity:high Cross-component or shared-contract change with a large review surface feature New capabilities, enhancements, or enablement work ready-to-merge PR is approved, current, and waiting for final CI or merge sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants