Skip to content

feat(swe): opt-in swe_agents container setup for swe_rebench and swe_internal_v1 - #6173

Merged
yaoyu-33 merged 7 commits into
mainfrom
ananthsub/swe-rebench-legacy-container-setup
Nov 17, 2026
Merged

yaoyu-33 merged 7 commits into
mainfrom
ananthsub/swe-rebench-legacy-container-setup

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What changed

swe_rebench and swe_internal_v1 gain an opt-in sandbox_config.legacy_container_setup flag (default false). When it is true, both the agent sandbox and the eval sandbox get the toolchain setup that the Apptainer swe_agents harness applied to its agent and evaluator containers:

  • Environment variables: _JAVA_OPTIONS (IPv4 preference and the Robolectric Maven mirror URL), GRADLE_USER_HOME, DOTNET_GCHeapHardLimit (8 GiB), and CHROME_BIN and CHROMIUM_BIN, which point at the Chrome wrapper. Explicit sandbox_config.env keys still take precedence.
  • Files: the Maven settings.xml and Gradle init script mirror, plus a Chrome wrapper that runs the image's real Chrome with --no-sandbox --disable-dev-shm-usage. An eval sandbox's verification files take precedence on shared paths. The mirror uses the same paths as the verification files, so each file is installed once.
  • Setup command: after start, the server makes the wrapper executable and copies the Gradle init script to /home/gradle and /home/user. If the wrapper cannot be made executable, the setup fails; the extra Gradle copies are best effort. The server uses AsyncSandbox.start_with_setup, so a failed or timed-out setup stops the sandbox. The eval path then retries on a fresh sandbox.

_JAVA_OPTIONS keeps -Djava.net.preferIPv6Addresses=false to match the harness, though swe_rebench measured no effect from it.

The setup lives in resources_servers/swebench/swe_agents_container_setup.py so that other sandbox SWE servers can reuse it. The code is named after the harness it copies. The config key keeps the name legacy_container_setup because existing training recipes set it. The Apptainer-only steps, rewriting /etc/hosts and creating /var/run/postgresql, are not carried over.

In swe_rebench, overwrite_maven_settings: false also applies to the added files. With that setting, neither sandbox gets settings.xml, so a provider's read-only copy stays in place. swe_internal_v1 has no such option and always ships the Maven settings, as the harness did.

Why

Without the flag, swe_rebench sets only GRADLE_USER_HOME and sends the mirror files to the eval sandbox only, and swe_internal_v1 sets none of it. A training run moved from the Apptainer harness therefore runs the agent in a different toolchain environment. For example, Karma suites cannot start Chrome as root with a small /dev/shm, and, where the agent sandbox has open egress, the agent's Maven builds cannot reach Maven Central. Under an egress policy that allows only the model endpoint, the agent sandbox cannot reach the mirror either. The Chrome wrapper, DOTNET_GCHeapHardLimit and GRADLE_USER_HOME still apply. Training recipes set legacy_container_setup: true for both servers, through a shared config anchor, to get the old behavior back. Server configs drop unknown keys without a warning, so until this lands those recipes run without the setup.

Related PRs

#5656 also ships a Chrome wrapper and setup to swe_rebench and swe_internal_v1 sandboxes, through new generic sandbox_config.files and setup_command keys. It does not read legacy_container_setup, so recipes that set this key need this change. Merging both would give Gym two ways to ship the same files to the same sandboxes. This PR replaces the setup half of #5656 and keeps the key the recipes already use.

Issue

No issue is linked: this change restores container behavior that existing training recipes rely on.

Tests

  • The new module's tests check the exact environment variables, the files shipped (with and without Maven settings.xml), the setup command it runs, and that a failed or timed-out setup raises. They also run the real setup command through sh: it fails when the wrapper cannot be made executable, and it succeeds when the other Gradle homes are missing. They also run the Chrome wrapper against a stub binary to confirm it passes the container flags first, then the caller's arguments.
  • The swe_rebench server tests check that:
    • the setup is off by default;
    • with the flag on, the agent sandbox gets the environment variables, the files and the setup step;
    • an eval sandbox keeps its verification files;
    • explicit config environment variables still win;
    • overwrite_maven_settings: false keeps settings.xml out of the agent sandbox;
    • the mirror files match the verification mirror paths.
  • The swe_internal_v1 server tests check that the setup is off by default, that the agent sandbox gets the environment variables, the files and the setup step with the flag on, and that an eval sandbox keeps its verification files.
  • The new behavior tests fail with the server and module changes reverted. The chmod failure test fails against the command that always exited 0.

Commands run:

PYTHONPATH=$PWD python -m pytest -q resources_servers/swe_rebench/tests
PYTHONPATH=$PWD python -m pytest -q resources_servers/swe_internal_v1/tests
PYTHONPATH=$PWD python -m pytest -q resources_servers/swebench/tests/test_swe_agents_container_setup.py
pre-commit run --files resources_servers/swe_internal_v1/app.py resources_servers/swe_internal_v1/tests/test_app.py resources_servers/swe_rebench/app.py resources_servers/swe_rebench/tests/test_app.py resources_servers/swebench/swe_agents_container_setup.py resources_servers/swebench/tests/test_swe_agents_container_setup.py

Rollout evidence

Smoke runs with legacy_container_setup: true ran locally from a workstation against a remote OpenSandbox cluster, with a hosted model behind Gym's openai_model server. They used three rows:

  • swe_rebench cqfn__diktat-932 (Kotlin, Maven)
  • swe_rebench video-dev__hls.js-6692 (TypeScript, Karma)
  • swe_internal_v1 getmoto__moto-5949 (Python)

Agent sandbox. For each swe_rebench image, I created a sandbox through SWERebenchResourcesServer._create_sandbox on OpenSandbox and inspected it. This is the same call that seeds an agent session. In both sandboxes:

  • CHROME_BIN and CHROMIUM_BIN were /tmp/chrome-wrapper.sh, and the wrapper was executable.
  • _JAVA_OPTIONS, GRADLE_USER_HOME=/root/.gradle and DOTNET_GCHeapHardLimit=0x200000000 were set.
  • /root/.m2/settings.xml mirrored central only.
  • nemo_gym_mirror.gradle was present in /root/.gradle/init.d, /home/gradle/.gradle/init.d and /home/user/.gradle/init.d.

On the JVM image, java and mvn printed Picked up _JAVA_OPTIONS, and java.net.preferIPv6Addresses was false. On the Karma image, $CHROME_BIN --headless --dump-dom rendered a test page.

Eval sandbox. I ran golden-patch verification through gym env start and gym eval run with the flag on for both servers:

Row Reward Result
cqfn__diktat-932 1.0 Resolved. The log shows Picked up _JAVA_OPTIONS and Maven resolving from the Google mirror.
video-dev__hls.js-6692 1.0 Resolved. Karma 6.4.4 launched Chrome Headless 144, which connected.
getmoto__moto-5949 1.0 Resolved through swe_internal_v1.

Evaluation completed for every row, and no setup step failed.

Agent rollout. OpenCode ran one swe_rebench row end to end with the flag on, through the swe_rebench.yaml OpenCode route. Gym's Docker sandbox provider ran on the workstation with network: host, so OpenCode inside the container reached Gym's model server on 127.0.0.1. The model was openai/openai/eccn-gpt-6-luna on the NVIDIA inference API, behind openai_model. The inference key stayed in the model server on the host.

Row Reward Result
cqfn__diktat-932 0.0 Verification completed and the sample was not masked. OpenCode made 22 tool calls and produced a 2,225-byte patch, which applied. The PASS_TO_PASS tests passed. LineLengthFixTest (FAIL_TO_PASS) still failed, so the model's fix was wrong.

Inside the running agent container, CHROME_BIN pointed at the executable wrapper, and GRADLE_USER_HOME and DOTNET_GCHeapHardLimit were set. nemo_gym_mirror.gradle was present in all three Gradle homes. OpenCode's own mvn calls printed Picked up _JAVA_OPTIONS, which shows the agent's tool calls ran in the container with the setup applied. apply_swe_agents_container_setup reported no failure.

Still open: an agent rollout through swe_internal_v1. That server's setup is covered by unit tests and the golden-patch run above.

Compatibility

Default behavior is unchanged. The flag is off unless a config sets it.

The Apptainer swe_agents harness gave both the agent's container and the
evaluator's container a Maven/Gradle mirror, a Chrome wrapper for Karma
(--no-sandbox --disable-dev-shm-usage, needed as root with a small
/dev/shm), and _JAVA_OPTIONS, GRADLE_USER_HOME, DOTNET_GCHeapHardLimit,
CHROME_BIN and CHROMIUM_BIN. swe_rebench sets only GRADLE_USER_HOME and
ships the mirror to eval sandboxes only, so a run moved from that harness
trains and grades in a different toolchain environment.

Add resources_servers/swebench/legacy_container_setup.py and apply it to
the agent and eval sandboxes of swe_rebench when sandbox_config sets
legacy_container_setup: true (default off). Environment variables go
through SandboxSpec.env, and explicit sandbox_config.env keys still win.
Files go through SandboxSpec.files: an eval sandbox's verification files
win on shared paths, and the mirror uses the same paths as swe_rebench's
verification files so it is installed once. A setup exec marks the
wrapper executable and copies the Gradle init script to the other Gradle
homes the harness covered; if it fails, the sandbox is stopped. The
Apptainer-only steps (the /etc/hosts rewrite and /var/run/postgresql)
are not carried over.

overwrite_maven_settings: false also keeps settings.xml out of the
added files, so a provider's read-only settings.xml is left alone in
both sandboxes.

Co-authored-by: Jiaqi Zeng <[email protected]>
Signed-off-by: Ananth Subramaniam <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

ananthsub and others added 4 commits November 13, 2026 15:19
…on chmod

Rename the module to swe_agents_container_setup.py and its names after
the harness they copy. The config key stays legacy_container_setup
because existing training recipes set it.

The setup command now fails when it cannot make the Chrome wrapper
executable. Before, the command always exited 0, so Karma failed later
and the row scored 0 instead of being reported as a failed setup. The
Gradle init script copies are still best effort.

The _JAVA_OPTIONS comment now says preferIPv6Addresses is kept to match
the harness, and that swe_rebench measured no effect from it.

Signed-off-by: Ananth Subramaniam <[email protected]>
The setup command test ran the real mkdir under /home, which creates
directories on the host when tests run as root. Point both Gradle homes
at tmp_path, and check that the init script is copied to the writable
home while the unwritable one still lets the command succeed.

Signed-off-by: Ananth Subramaniam <[email protected]>
Asserting that no /home/ path remains failed falsely when TMPDIR is
under /home. Check the two home paths the command uses instead.

Signed-off-by: Ananth Subramaniam <[email protected]>
Apply the swe_agents container setup to swe_internal_v1's agent and eval
sandboxes when sandbox_config sets legacy_container_setup: true, as
swe_rebench already does. Training recipes set the key for both servers
through a shared anchor, and until now swe_internal_v1 ignored it.
swe_internal_v1 has no overwrite_maven_settings option, so it always
ships the Maven settings.

Co-authored-by: Jiaqi Zeng <[email protected]>
Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub ananthsub changed the title feat(swe_rebench): opt-in swe_agents container setup for sandboxes feat(swe): opt-in swe_agents container setup for swe_rebench and swe_internal_v1 Nov 13, 2026
ananthsub added a commit that referenced this pull request Nov 14, 2026
…rk loans

swe_internal_v1 goes back to its mapping sandbox_config: PRs #5656 and
#6173 read new keys from it with .get(), so it moves to the stage after
they merge. LentSandboxes now refuses network_access no_network, since
the harness in a lent sandbox calls the model server, and
SandboxNetwork's validator returns Self.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub requested review from yaoyu-33 and yfw November 16, 2026 17:09
@ananthsub
ananthsub marked this pull request as ready for review November 16, 2026 17:45
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 16, 2026 17:46

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

SHIP WITH CARE

I found no confirmed runtime defect in the setup, precedence, or retry/cleanup paths. The remaining RISK is the missing model rollout through swe_internal_v1, described inline.

NOTE, documentation suggestion: Could you document the option outside the PR description? Neither server's running guide exposes it: swe_rebench or swe_internal_v1. Users migrating recipes need a persistent reference for this behavior-changing startup option.

Add a short Fern section linked from both READMEs with sandbox_config.legacy_container_setup: true nested under each resources-server configuration. Explain that it defaults to false, affects agent and evaluator sandboxes, and lets explicit environment values win. Distinguish the servers: overwrite_maven_settings: false is a server-level option in swe_rebench, while swe_internal_v1 always supplies the Maven settings when setup is enabled. Keep the feature opt-in and describe failed setup as infrastructure failure, not a completed task failure. Static acceptance: compare both documented examples and precedence statements with the two _create_sandbox implementations; no runtime change is requested.

I inspected all six changed files and traced their affected sandbox lifecycle and verification paths. I did not execute tests in this read-only review.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

self._verifier_sandboxes[verifier_session_id] = sandbox
await sandbox.start(spec)
if swe_agents_setup:
await sandbox.start_with_setup(spec, apply_swe_agents_container_setup)

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.

RISK: finish the model smoke rollout through swe_internal_v1. The description explicitly leaves this run open. Its golden-patch run exercises evaluator creation, but skips the agent path through _start_task_sandbox, model tool execution, and patch capture. The new recording sandbox also stores the setup callback without executing it. This leaves the newly enabled agent environment unvalidated for this server. It is a validation gap, not a confirmed runtime failure.

Could you run one representative supported row end to end with a real model and legacy_container_setup: true, as required for behavior-changing environment work by AGENTS.md? Record the command, provider, model, row, and inspected outcome. Acceptance: agent setup succeeds, its tool commands see the configured environment and executable wrapper, its patch reaches verification in a fresh sandbox, and verification completes without infrastructure masking. Reward may be 0 for an incorrect model patch; it need not be 1. Confirm both sandboxes are cleaned up. Keep the existing golden-patch and swe_rebench rollout evidence; no production-code rewrite or default change is requested.

yaoyu-33
yaoyu-33 previously approved these changes Nov 16, 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.

Reviewed f4195bc; no blocking source defect found, including an independent review.

Completed the missing swe_internal_v1 integration smoke on a workstation using the repository's public getmoto__moto-5949 fixture, the default OpenCode session route, Docker, and deepseek-ai/deepseek-v4.1-flash through Gym's openai_model. Set sandbox_config.legacy_container_setup: true and is_verifying_golden_patch: false.

  • The model's own shell output confirmed all five setup environment variables, the executable Chrome wrapper, Maven settings, and all three Gradle mirror copies.
  • Captured a 2,130-byte model worktree patch, distinct from the golden patch. A separate evaluator sandbox applied it; all four required tests passed: reward 1.0, evaluation_completed: true, mask_sample: false, no verifier error.
  • Both sandboxes passed setup inspection and were removed; session close and collector shutdown completed.

Qualification: the agent reached its configured 900-second execution budget after producing its edits and returned incomplete/timeout. Patch capture, verification, and cleanup still completed. This validates the affected integration path using the public fixture, not the private training delivery.

Invocation (paths shortened):

gym eval run --config run.yaml --output rollouts.jsonl --concurrency 1 --split benchmark --num-repeats 1

The flagged rollout-evidence gap is covered. Current CI has no failed or pending checks.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers ready-to-merge PR is approved, current, and waiting for final CI or merge labels Nov 16, 2026
Keep the legacy container setup tests and the pinned log parser tests in resources_servers/swe_rebench/tests/test_app.py.

Signed-off-by: svcnemo-autobot <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the area:sandbox Sandbox providers, isolation, and sandbox runtime contracts label Nov 16, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

/ok to test feccaf8

yaoyu-33
yaoyu-33 previously approved these changes Nov 16, 2026
@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 16, 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/43960582323

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 16, 2026
@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 16, 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/43972659243

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 16, 2026
@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test cb0cbfa

@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 cb0cbfa; no blocking issue found, including an independent recheck.

The merge-queue failure came from test config stubs missing sandbox_provider_options after #6177. The fixtures now instantiate the real server config models; all assertions and production behavior are preserved.

Validation on ws: 144 tests passed on the PR revision, 162 passed on the failed merge-group revision with this repair, all 31 benchmark-preparation tests passed, and pre-commit run --all-files passed. The separate core-test hang did not reproduce. The runtime setup code is unchanged from f4195bc; I rechecked the existing model-smoke and cleanup evidence recorded in the earlier review: #6173 (review) . No new model rollout was needed for this test-only repair.

Fresh CI is running at this exact head: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43979466816 . Approval does not assert that the pending CI or merge queue has passed.

@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 17, 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/43985742488

Merged via the queue into main with commit 27c4f17 Nov 17, 2026
70 checks passed
@yaoyu-33
yaoyu-33 deleted the ananthsub/swe-rebench-legacy-container-setup branch November 17, 2026 00:26
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 area:sandbox Sandbox providers, isolation, and sandbox runtime contracts feature New capabilities, enhancements, or enablement work ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants