Skip to content

feat(swe): support replayable rebench and SWEmer episode sessions - #4304

Merged
yaoyu-33 merged 10 commits into
mainfrom
ananthsub/swe-training-typed-sessions
Nov 13, 2026
Merged

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

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What changes

swe_rebench, swemer_v1, swemer_v2 support 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>.yaml now pairs OpenCode agent sessions with single_agent_turn. The original resources-only configuration is preserved as configs/<server>_legacy_agent.yaml. Existing configs/<server>_opencode.yaml relay pairings and configs/<server>_example.yaml golden-patch examples import that legacy configuration; their behavior is preserved. Golden-patch commands, README instructions, and config tests use the new paths.

Compatibility

  • Config migration: use <server>.yaml for the session pairing (formerly <server>_single_agent_turn.yaml). Existing resources-only or golden-patch callers of <server>.yaml must switch to <server>_legacy_agent.yaml. The _opencode.yaml legacy training entrypoint remains available.
  • A grading command that exceeds its time budget receives reward 0, evaluation_completed=true, and no sample mask or verification retry. This applies to both session and relay verification.
  • Provider/sandbox execution failures and other inconclusive grading outcomes use bounded fresh-sandbox retries. If still incomplete, they receive mask_sample=true and failure_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.
  • Unavailable patch capture is masked. A completed git command failure retains empty-patch grading. A completed incorrect patch remains an unmasked zero.
  • Relay verification without a seeded session returns masked session_lost. Re-seeding stops the previous sandbox first; a failed stop refuses replacement and retains ownership for cleanup retry.
  • Disk logs are opt-in through verification_log_dir (the supplied YAML sets it to null). When enabled, output uses instance-<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 31303637417df3eee636611d4ede458f3713a41a, including public main dfed8a3b2:

  • 609 selected tests passed using pytest -q -o addopts=--import-mode=importlib over resources_servers/swe_rebench/tests, resources_servers/swemer_v1/tests, resources_servers/swemer_v2/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, and tests/unit_tests/tooling/test_agent_environment_repository_configs.py.
  • All 12 configs (canonical session, legacy resources-only, example, and OpenCode relay for each server) resolve through Gym's production parser. Checks cover canonical taskset routing, allowed agents, episode/sandbox lifetime, and preservation of the legacy/golden-patch paths.
  • A real Git probe confirms pristine-file capture with spaces, Unicode, and percent signs in repository paths; log-directory instance IDs remain URL-escaped.
  • pre-commit run --all-files passed, including guardwords and import-linter. Workstation source trees were checked against the final commit trees. Commits include DCO sign-off.
  • Both PR branches merge cleanly with the above main revision and with each other. Main's scanner baseline is unchanged.
  • Real-model rollout evidence remains outstanding for the original session/verifier changes. This follow-up only renames configuration entrypoints and updates references; it preserves the previous config contents and does not claim a new model rollout.

No separate issue is needed: this completes the environment-server integration already proposed in this PR. SWE-Next is introduced separately in #5112.

@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 a 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]>
Use TaskSandboxSessions in denovo_swe, scale_swe, swemer_v1, swemer_v2,
swe_next, and swe_rebench, 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]>
@ananthsub
ananthsub force-pushed the ananthsub/swe-typed-sessions branch from e8a8665 to 652d384 Compare October 9, 2026 17:13
@ananthsub
ananthsub force-pushed the ananthsub/swe-training-typed-sessions branch from 76dac0f to 7987525 Compare October 9, 2026 17:13
@yaoyu-33 yaoyu-33 added the complexity:medium Single-domain change with interacting parts or a moderate 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
Base automatically changed from ananthsub/swe-typed-sessions to main November 5, 2026 02:37

@yaoyu-33 yaoyu-33 left a comment

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.

Team review, walked against the benchmark review checklist.

This moves swe_rebench, swemer_v1, swemer_v2 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. #4303 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_log)

if result.error_type is not None or result.return_code 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.

resources_servers/swe_rebench/verification.py:297

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 all three servers reached the parser and was a completed, scored 0 (swe_rebench.yaml notes some timeouts come from CPU starvation, so the split matters).

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_v1, swemer_v2.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 93d7412. 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}

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.

resources_servers/swe_rebench/app.py:462

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_v1, swemer_v2.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread resources_servers/swe_rebench/app.py Outdated

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

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.

resources_servers/swe_rebench/app.py:374

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_v1, swemer_v2.

Suggested change
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
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 93d7412. 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.

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.

resources_servers/swe_rebench/tests/test_sessions.py:1

Nothing runs the episode-session path yet: every config for swe_rebench, swemer_v1, swemer_v2 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

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.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Merged public main 6b67b2c and took main's repaired baseline. Verified this PR has no .secrets.baseline diff against that main revision.

Comment thread tests/helpers/swe_resource_sessions.py Outdated
sandbox = MagicMock()
sandbox.exec = AsyncMock(
return_value=SandboxExecResult(
return_code=0 if error_type else 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.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 93d7412. 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.

@init-nikhil

Copy link
Copy Markdown
Member

/ok to test 93d7412

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 12, 2026 22:56
@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test 3130363

yaoyu-33
yaoyu-33 previously approved these changes Nov 13, 2026

@yaoyu-33 yaoyu-33 left a comment

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.

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. The shell/URL quoting collision is fixed; a real Git probe covered spaces, Unicode, and percent signs in repository paths. Workstation validation passed: 609 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.

@yaoyu-33 yaoyu-33 added ready-to-merge PR is approved, current, and waiting for final CI or merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Nov 13, 2026
@yaoyu-33
yaoyu-33 enabled auto-merge November 13, 2026 02:00
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 13, 2026 02:01
@init-nikhil

Copy link
Copy Markdown
Member

/ok to test 0801c52

@yaoyu-33 yaoyu-33 left a comment

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.

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.

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

Copy link
Copy Markdown
Contributor

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

Merged via the queue into main with commit f823a60 Nov 13, 2026
73 checks passed
@yaoyu-33
yaoyu-33 deleted the ananthsub/swe-training-typed-sessions branch November 13, 2026 05:21
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:medium Single-domain change with interacting parts or a moderate 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