Repository navigation
feat(swe): support replayable SWEmer and internal episode sessions - #4303
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]>
…ML, and SWE internal v1 Use TaskSandboxSessions in swemer_ultra, swemer_oml, and swe_internal_v1, so an Environment Server can 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
886e260 to
7e97fda
Compare
Refresh the existing PR independently against public main. Preserve published ancestry with a normal-push merge commit. Signed-off-by: Nikhil Deshmudre <[email protected]>
|
/ok to test a3ae5d1 |
Signed-off-by: Nikhil Deshmudre <[email protected]>
|
/ok to test 24c00db |
yaoyu-33
left a comment
There was a problem hiding this comment.
Team review, walked against the benchmark review checklist.
This moves swemer_oml, swemer_ultra, swe_internal_v1 onto the shared SandboxSessionResourcesServer, so they can lend the task sandbox to an agent session and replay a saved verdict, and it masks infrastructure failures that were scored 0 before. The session contract holds in what we checked: typed seed refusals (422/409), replay, close fencing, retried stops, lost-session verify, the lent descriptor's operate scope, ttl_s, and check_resources_session_contract. The new session tests pass locally, as do the swe_gym and r2e_gym suites that share patch_capture.
The main open point is which endings get masked (timeouts above all), plus evidence. #4304 has the same changes on the other three servers and gets the same comments. The branch conflicts with main only on .secrets.baseline. Points are inline. We did not run a real sandbox or model.
|
|
||
| await asyncio.to_thread(_persist) | ||
|
|
||
| if result.error_type is not None or result.return_code is None: |
There was a problem hiding this comment.
resources_servers/swemer_ultra/verification.py:332
A grading run that times out now becomes completed=False, is retried once at the full evaluation_timeout, and is then masked as verifier_error. The candidate patch can cause that timeout itself (an infinite loop or a deadlock in the code under test), so masking it drops a wrong answer from the score and from the training signal. On main a timed-out run in swemer_ultra reached the parser and was a completed, scored 0; in swemer_oml and swe_internal_v1 it was an unmasked incomplete 0.
Could we keep error_type == "timeout" as a graded 0, with no full-length retry, and mask only provider or sandbox errors? If timeouts should be masked, could you show the timeout rate with the golden patch against agent patches, so we know they come from the infrastructure? The same block is in swemer_oml, swe_internal_v1.
There was a problem hiding this comment.
Fixed in c1b0687. A grading exec with error_type="timeout" now returns a completed unresolved verdict: reward 0, no mask, and no full-budget retry. Sandbox/provider errors remain inconclusive. Regression tests exercise the real verifier through both session and relay HTTP paths and assert one attempt, unmasked zero, replay/cleanup; a real sandbox sentinel separately exercises retry and masking.
| "reward": 1.0 if result.resolved else 0.0, | ||
| "evaluation_completed": result.completed, | ||
| **( | ||
| {"mask_sample": True, "failure_kind": VERIFIER_ERROR, "failure_reason": result.error} |
There was a problem hiding this comment.
resources_servers/swemer_oml/app.py:478
This masks every incomplete final attempt, which is wider than the description's "interrupted provider execution or unavailable patch capture": a missing workdir, a held-out test patch that did not apply, a silent grader, a parser failure and the timeouts above all leave the score now. Most of those are row faults and masking them is right, but the aggregate score of the existing relay configs moves, and the description says it does not for an incorrect patch.
Could you update the Compatibility section with these endings and the two relay-path changes (a verify with no seed now returns a masked session_lost instead of an empty-patch 0; a re-seed now fails when stopping the previous sandbox fails), and add before/after mean reward and mask rate from one real run per server? Same in swemer_ultra, swe_internal_v1.
There was a problem hiding this comment.
Updated the Compatibility section to enumerate missing workdirs, failed held-out test application, missing grader output, parser failure, provider failures, missing seeded sessions, and failed re-seed cleanup. Grading-command timeouts now remain unmasked zeros. The requested measured before/after reward and mask rates remain open: the actual validation job failed at startup on an incompatible OpenAI SDK before producing any rollouts. No synthetic counts are presented as model evidence.
|
|
||
| inputs = self._inputs(body, patch) | ||
| log_dir = Path(__file__).parent / "logs" / body.instance_id | ||
| log_dir = (self.config.verification_log_dir or (Path(__file__).parent / "logs")) / uuid4().hex |
There was a problem hiding this comment.
resources_servers/swemer_oml/app.py:419
Each verify now writes a new logs/<uuid>/attempt-N/ directory, by default inside the server's source tree. On main it was one overwritten logs/<instance_id> per task, so a training run now grows this without bound, and since the path has no instance_id and is not in the response, nobody can find the log for a given row. Could we key it by instance (suggestion below), return the path in the verify response, and set verification_log_dir (or turn persistence off) in the YAML? Same in swemer_ultra, swe_internal_v1. Small one: in swemer_oml and swe_internal_v1 the new field sits under the comment that describes evaluation_timeout's budget, so it could move below that field.
| log_dir = (self.config.verification_log_dir or (Path(__file__).parent / "logs")) / uuid4().hex | |
| log_dir = ( | |
| (self.config.verification_log_dir or (Path(__file__).parent / "logs")) | |
| / body.instance_id | |
| / uuid4().hex | |
| ) |
There was a problem hiding this comment.
Fixed in c1b0687. verification_log_dir=None disables persistence and the supplied YAML explicitly sets null. When enabled, logs use instance-//attempt-N, and the response returns verification_log_dir. Prefixing and escaping keep task IDs inside the configured directory. The timeout-budget comment is attached to evaluation_timeout. Tests cover task-keyed paths and disabled persistence. Retention is controlled by the caller's chosen output location.
| @@ -0,0 +1,31 @@ | |||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | |||
There was a problem hiding this comment.
resources_servers/swemer_oml/tests/test_sessions.py:1
Nothing runs the episode-session path yet: every config for swemer_oml, swemer_ultra, swe_internal_v1 still uses the legacy_agent relay with allowed_agents: [opencode_sandboxed_agent], and the evidence is unit tests that mock sandbox start, patch capture and grading. Since this changes the lifecycle and the masking of three training servers, could you add a real-model smoke at this head (at least one server through a single_agent_turn session pairing and one through the existing relay, with reward and mask counts), or keep the PR as a draft until then? Adding that single_agent_turn pairing config here would also give the new path its first caller.
There was a problem hiding this comment.
Added a separate _single_agent_turn.yaml OpenCode session pairing for each server; existing relay pairings remain. All three configs resolve through the production config parser and validate routing and episode/sandbox lifetime. The real-model evidence request remains open: the submitted validation job failed before generation because its runtime SDK lacks PromptCacheOptions. The repository pins OpenAI 2.45.0; a scoped corrected-runtime rerun is being prepared. I will attach actual per-server reward/mask results rather than claim these CPU tests satisfy the smoke request.
| "hashed_secret": "d336924915f720e1704dcabc25c94ca5896be952", | ||
| "is_verified": false, | ||
| "line_number": 25, | ||
| "line_number": 25 |
There was a problem hiding this comment.
.github/workflows/config/.secrets.baseline:2463
Main already repaired this JSON in #6083, and this commit is now the only merge conflict. Could you drop it (or merge main and take main's version), so the PR no longer touches this file?
There was a problem hiding this comment.
Merged public main 6b67b2c and took main's repaired baseline. Verified this PR has no .secrets.baseline diff against that main revision.
| sandbox = MagicMock() | ||
| sandbox.exec = AsyncMock( | ||
| return_value=SandboxExecResult( | ||
| return_code=0 if error_type else None, |
There was a problem hiding this comment.
tests/helpers/swe_resource_sessions.py:183
Nit: SandboxExecResult.return_code is an int, and providers report a timeout or sandbox failure as a sentinel exit code with error_type set, so return_code=None never happens. This case (and return_code=None in the capture_unavailable scenario) tests a shape providers don't produce, and the or result.return_code is None arm in each run_verification is dead. Could we test a real sentinel instead, for example return_code=125, error_type="sandbox", and drop that arm?
There was a problem hiding this comment.
Fixed in c1b0687. Verifier interruption tests now use real provider-shaped results: return_code=125/error_type="sandbox" and return_code=124/error_type="timeout". Unavailable-capture tests use the sandbox sentinel too. Removed the unreachable return_code is None arm from these verifiers.
Signed-off-by: Nikhil Deshmudre <[email protected]>
Signed-off-by: Nikhil Deshmudre <[email protected]>
|
/ok to test c1b0687 |
Signed-off-by: yaoyu-33 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 09c895d |
yaoyu-33
left a comment
There was a problem hiding this comment.
Re-reviewed the session lifecycle, capture/verdict replay, timeout/provider failure handling, and canonical/legacy config routes at this commit. No blocking code issues found. Workstation validation passed: 584 tests, all 12 config variants, and full pre-commit. Real-model rollout evidence remains outstanding as documented in the PR; this review does not claim that smoke coverage.
Signed-off-by: Nikhil Deshmudre <[email protected]>
|
/ok to test 1259bb1 |
yaoyu-33
left a comment
There was a problem hiding this comment.
Reviewed session lifecycle, patch capture, replay, timeout scoring, failure masking, and canonical/legacy configuration routing, including an independent source review. No additional blocking code issues found. Workstation test evidence is author-reported; the requester confirms real-model testing is complete. Core, sandbox, and server tests passed.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43369967095 |
What changes
swemer_oml,swemer_ultra,swe_internal_v1support environment-server episode sessions. The resources server lends its task sandbox to the agent, captures the resulting patch, and grades it in a fresh sandbox. Verification replays its saved result; failed cleanup remains owned so close can retry.Each server's canonical
configs/<server>.yamlnow pairs OpenCode agent sessions withsingle_agent_turn. The original resources-only configuration is preserved asconfigs/<server>_legacy_agent.yaml. Existingconfigs/<server>_opencode.yamlrelay pairings andconfigs/<server>_example.yamlgolden-patch examples import that legacy configuration; their behavior is preserved. Golden-patch commands, README instructions, and config tests use the new paths.Compatibility
<server>.yamlfor the session pairing (formerly<server>_single_agent_turn.yaml). Existing resources-only or golden-patch callers of<server>.yamlmust switch to<server>_legacy_agent.yaml. The_opencode.yamllegacy training entrypoint remains available.evaluation_completed=true, and no sample mask or verification retry. This applies to both session and relay verification.mask_sample=trueandfailure_kind=verifier_error. These include unavailable work directories, held-out test patches that fail to apply, missing grader output, and parser failures; excluding them changes aggregate reward denominators.session_lost. Re-seeding stops the previous sandbox first; a failed stop refuses replacement and retains ownership for cleanup retry.verification_log_dir(the supplied YAML sets it to null). When enabled, output usesinstance-<escaped instance_id>/<unique verification>/attempt-N/test_output.log, and the verification response returns the verification directory. Callers choose the output location and retention policy. Test output also remains in the response.Validation
Validated on the workstation against
09c895d2aa0368437b1f26659fc39de0d72036d4, including public maindfed8a3b2:pytest -q -o addopts=--import-mode=importliboverresources_servers/swe_internal_v1/tests,resources_servers/swemer_oml/tests,resources_servers/swemer_ultra/tests,resources_servers/swebench/tests/test_patch_capture.py,resources_servers/swe_gym/tests,resources_servers/r2e_gym/tests,tests/unit_tests/config/test_global_config.py, andtests/unit_tests/tooling/test_agent_environment_repository_configs.py.pre-commit run --all-filespassed, including guardwords and import-linter. Workstation source trees were checked against the final commit trees. Commits include DCO sign-off.No separate issue is needed: this completes the environment-server integration already proposed in this PR. SWE-Next is introduced separately in #5112.