Skip to content

fix(swe): mask verifications without a verdict and block agent egress in more SWE servers - #6670

Open
yfw wants to merge 12 commits into
mainfrom
yifuw/swe-egress-block-no-verdict-masks
Open

yfw wants to merge 12 commits into
mainfrom
yifuw/swe-egress-block-no-verdict-masks

Conversation

@yfw

@yfw yfw commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR brings two SWE changes to more resources servers.

  1. No-verdict masks for swe_gym, r2e_gym and scale_swe. Before, these servers trained some infrastructure failures as a reward of 0. Now they mask them (mask_sample: true, failure_kind: verifier_error). scale_swe also uses provider_unavailable and session_lost, as its episode-session path already does. On main, swemer_v1, swemer_v2, swemer_ultra and swe_next already mask these cases.
  2. Agent egress block for swe_gym, r2e_gym and swemer_ultra. These servers now take the enforce_agent_no_network and sandbox_model_server fields that the other SWE servers already have (resources_servers/swebench/agent_network.py). The flag is off by default.

These changes were written by Jiaqi Zeng (@HeyyyyyyG), on top of a swe_gym fix by Hemil Desai.

Commits, in order:

Commit Author What it does
fix(swe_gym): grade unfinished test runs as inconclusive and capture both test streams Hemil Desai If the sandbox ends the eval script without an exit status, swe_gym reports the run as inconclusive and retries it. The eval script also captures the stdout and stderr of the test command in full. This PR takes only the swe_gym part of a larger SWE fix that is not public.
feat(swe): block agent sandbox egress in r2e_gym, swe_gym and swemer_ultra Jiaqi Zeng Adds AgentNetworkConfig to the three server configs and uses its provider options for the agent's sandbox.
fix(r2e_gym,swe_gym): mask verifications that produce no verdict Jiaqi Zeng Masks no-verdict results on the episode-session path and on the Agent /run path.
fix(scale_swe): mask a missing verdict on the Agent /run cookie path Jiaqi Zeng The cookie path now captures and classifies like the episode-session path. The unused _extract_model_patch is removed.
docs(scale_swe): say which cookie path stops are bounded Yi-Fu Wu One README sentence. After the commit above, the task sandbox stop on the cookie path uses the bounded wait.
fix(swe_gym): report a timed-out test run as a completed 0 Yi-Fu Wu A swe_gym timeout keeps its retry and stays unmasked, and the response now says evaluation_completed: true, as the sibling SWE servers do. Before, Gym's eval recovery read the row as masked and not measured.
fix(swe): read the reserved exit codes only before the test output starts Yi-Fu Wu swe_gym, r2e_gym and scale_swe read exit 97 or 96 as a broken image only when the test output never started. Code from the patch can make the test command exit 97.
fix(swe_gym,r2e_gym): name the verifier's error in a no-verdict mask Yi-Fu Wu After a git failure on the agent's repository, a mask now names the verifier's error, not the capture's.
fix(scale_swe): take the captured sandbox out of a cookie session Yi-Fu Wu The cookie path pops the task sandbox and its state before the capture and stops that exact sandbox. A new seed with the same cookie keeps its own sandbox, and a failed stop leaves no state behind.
fix(swebench): treat a null provider_options as no options Yi-Fu Wu A provider_options: null in sandbox_config no longer raises TypeError in the servers that use AgentNetworkConfig.
test(swe_gym,r2e_gym): pin the stream capture, the empty patch and a bounded wait Yi-Fu Wu Tests only.
fix(scale_swe): drop a cookie session's stop task once it ends Yi-Fu Wu A cookie-path stop that outlasts sandbox_stop_timeout_seconds no longer stays in _stop_tasks for the life of the server.

The last seven commits answer review comments.

No issue is linked. This PR upstreams existing fixes, and the related PRs below give the context.

Training effect

These rows were trained as 0 before. They are masked now:

  • swe_gym and r2e_gym: the verifier gives no verdict after its retry. Examples are a grading sandbox that did not start, an exec that raised, an image without the repository, runner or conda environment, and a SWE-Gym test patch that did not apply.
  • swe_gym and r2e_gym: a row without its grading data. That is an R2E-Gym row without expected_output_json, or a SWE-Gym (repo, version) without a SWE-bench spec.
  • swe_gym and r2e_gym: the server did not get the agent's patch because of the provider (an error or a timeout on the capture command, or an unreachable sandbox). Before, the server graded an empty patch.
  • swe_gym and r2e_gym: the provider ended the eval exec without an exit status, for a reason other than a timeout. Before, the server graded the partial log.
  • scale_swe, on the Agent /run cookie path: the cases that its episode-session path already masks. These are no verdict after the retry, a verifier exec without an exit status (not a timeout), an eval script that stopped before pytest started, and a patch capture lost to infrastructure.

These rows stay trained as 0:

  • Tests that ran and did not pass, and a patch that did not apply.
  • An empty patch from the model.
  • Git exiting non-zero on the repository that the agent left.
  • A test run that hit evaluation_timeout. swe_gym now retries it on a fresh sandbox (inconclusive_verification_retries, 1 by default), then scores 0 without a mask. Its partial log is no longer graded. A run that hangs can hold the verifier for up to 1 + inconclusive_verification_retries times evaluation_timeout. r2e_gym and scale_swe grade it as before.
  • A test run whose own exit status is 97 or 96, for example from a conftest.py in the patch. These codes mean a broken image only before the test output starts.

The swe_gym eval script now puts the test command's stderr inside the graded region, after its stdout. Before, when the provider returned stderr apart from stdout, it came after the end marker and was not graded. A grade can change when stderr carries a result line for a required test.

In a run with sandbox or provider trouble, expect fewer trained 0 rewards and more masked samples from these servers.

Compatibility

  • Egress block: enforce_agent_no_network is false in every config, so the default behavior does not change. If you turn it on, the agent's sandbox gets a deny-by-default network policy that allows only the host of sandbox_model_server. The evaluation sandbox keeps its network. The flag needs a sandbox provider that can enforce network policies, such as OpenSandbox. At startup, the server refuses a provider that cannot enforce it.
  • Responses: more responses from these servers carry mask_sample: true, failure_kind and failure_reason. The reward of these rows stays 0, and evaluation_completed is false. Some of these rows reported evaluation_completed: true before this PR, because the server graded them. One case is a patch capture lost to the provider: the server graded an empty patch. A second case is an eval exec that the provider ended without an exit status: the server graded its partial log. Both cases apply to swe_gym, r2e_gym and the scale_swe cookie path. On the scale_swe cookie path, an eval script that stopped before the tests started was also graded.
  • The swe_gym VerificationResult has a new field timed_out (default false).
  • On the scale_swe cookie path, a failed patch capture is no longer graded as an empty patch. The cookie path also takes the task sandbox out of the session before the capture, so a new seed with the same cookie keeps its own sandbox.
  • A provider_options: null in sandbox_config now counts as no options. Before, it raised TypeError on the first sandbox in every server that uses AgentNetworkConfig, also on main.
  • refactor(sandbox): build SWE task sandboxes with the typed SandboxConfig.spec #6179 rewrites _create_sandbox in swe_gym, r2e_gym and swemer_ultra onto the typed SandboxConfig.spec(). Whichever PR merges second must pass the agent sandbox's egress policy through spec(network_policy=...), because AgentNetworkConfig reads sandbox_config as a mapping. It must also update the three tests/test_agent_network.py fixtures, which patch app.resolve_provider_metadata, an import refactor(sandbox): build SWE task sandboxes with the typed SandboxConfig.spec #6179 removes. A plain conflict resolution fails the egress tests.
  • Known limit: a patch capture that times out is still masked, as on main. SWE servers: an agent can stall patch capture so that its rollout is masked, not graded #6732 tracks this.

Related PRs

Validation

All commands ran on CPU. pre-commit and the scale_swe tests ran on the head 8645c67618. The other servers ran on df91095b0b, and the last commit changes only scale_swe.

pre-commit run --all-files
# every hook passed or skipped

gym env test +entrypoint=resources_servers/<name> +should_validate_data=true
# swe_gym 159, r2e_gym 78, scale_swe 130, swemer_ultra 74 passed, data validated
# swebench 363 passed (agent_network.py changed)
# The other servers that use AgentNetworkConfig: swemer_v1 74, swemer_v2 53, swemer_oml 55, swe_next 62,
# swe_rebench 126, swe_internal_v1 58 passed

I also made sure that the new tests fail without the code change:

  • With the swe_gym, r2e_gym and swemer_ultra app.py files from main, tests/test_agent_network.py gives 7 failed and 3 passed in each server.
  • With the swe_gym and r2e_gym app.py and verification.py files from before the mask commit, 28 swe_gym tests and 1 r2e_gym test fail.
  • With the scale_swe app.py from main, 9 of the 13 cookie path tests fail. The 4 that pass check behavior that does not change.
  • Without the reserved-exit guard, the new tests fail: 2 in swe_gym, 2 in r2e_gym and 1 in scale_swe.
  • With the scale_swe app.py from before the cookie-path fix, test_reseed_during_capture_keeps_the_new_sandbox and test_slow_task_stop_leaves_no_cookie_state fail.
  • Without the null guard in agent_network.py, test_null_provider_options_are_no_options fails in both cases.
  • test_a_mask_after_a_git_failure_names_the_verifier_s_error fails for both servers without its fix.
  • The bash test of the swe_gym eval script fails with the script from main, without the stderr capture, and with a brace group in place of the subshell.

The diff is server-only (resources_servers/**), so CI runs the core and sandbox tests and the tests of the changed servers.

Rollouts

The run below was at head df91095b0b. The later commit 8645c67618 changes only the scale_swe stop-task cleanup on the cookie path.

  • Smoke run on head df91095b0b with the agent egress block on (enforce_agent_no_network: true), OpenSandbox, a hosted Nemotron model and the OpenCode agent through each server's Agent /run cookie path: 3 example rows each of r2e_gym, swe_gym and scale_swe. All 9 rows finished with a verdict and no mask: 7 resolved, 2 graded 0.
  • Live egress test on each server: after an episode /seed_session, commands in the agent's sandbox failed to resolve DNS, to reach pypi.org or github.com, to open TCP to 1.1.1.1:443 and to pip download. TCP to the model server worked. /verify then completed in a fresh sandbox (evaluation_completed: true, unmasked).
  • In the smoke rows, an agent's own pip install and curl https://pypi.org/... failed with a name resolution error, and the rows were still graded.
  • In an RL run that used these commits, the no-verdict masks fired on 16 of 9,552 rows of these three servers. All 16 were scale_swe rows on the cookie path whose held-out test patch did not apply after the retry. Before this PR, these rows were trained as a reward of 0. r2e_gym (1,728 rows) and swe_gym (800 rows) had no masks.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally.
  • Documentation added or updated (scale_swe/README.md). The other servers have no README text about masks or egress.
  • Pre-commit checks pass locally (pre-commit run --all-files).
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s).

🤖 Generated with Claude Code

hemildesai and others added 5 commits November 23, 2026 14:55
…both test streams

This brings an existing SWE fix to swe_gym. If the sandbox ends the eval
script without an exit status (a dropped stream, a timeout or a provider
error), the partial log cannot grade the run. run_verification now returns
an inconclusive result, so the run is retried and is not graded as 0.

The eval script also captures the stdout and stderr of the test command
in full and prints both between the output markers. Some test runners
report on stderr, and a provider can return stderr apart from stdout.

Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
…ultra

These three servers lend the agent the sandbox they start in seed_session but had no way to
block its egress, so an RL agent could fetch a task's upstream fix. Give them the same
enforce_agent_no_network / sandbox_model_server fields as swe_next, swe_internal_v1 and the
other SWE servers (resources_servers/swebench/agent_network.py): the sandbox started for a
session gets a deny-by-default OpenSandbox policy that allows only the model server's host,
the startup check refuses a provider that cannot enforce it, and the evaluation sandbox keeps
its network. The flag stays off by default.

Tests mirror swe_internal_v1/tests/test_agent_network.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jiaqi Zeng <jiaqiz@nvidia.com>
Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Both servers trained an infrastructure failure as a 0. They now mask it
(mask_sample, failure_kind verifier_error), as swemer_v1 does, on both the
episode-session and the agent /run path.

Trained as 0 before, masked now:
- The verifier never produced a verdict after its retry: the grading sandbox
  failed to start or exec raised, the image lacks the repo / runner / conda env,
  or SWE-Gym's held-out test patch did not apply.
- R2E-Gym: the provider ended the eval exec without an exit status (not a
  timeout). The partial log used to be graded as a completed 0; it is now no
  verdict, retried, then masked.
- Missing task data: an R2E-Gym row without expected_output_json, a SWE-Gym
  row whose (repo, version) has no SWE-bench spec.
- The agent's patch could not be read for an infrastructure reason (provider
  error or timeout on the capture command, unreachable sandbox). The empty
  fallback patch used to be graded; now nothing is graded.

Still trained, unchanged:
- A completed run that does not resolve, a patch that does not apply.
- Git itself exiting non-zero on the repository the agent left (empty patch
  graded as before).
- A test run that hit evaluation_timeout: R2E-Gym grades it as before; SWE-Gym
  still retries it and then scores 0 unmasked (new VerificationResult.timed_out).

Signed-off-by: Jiaqi Zeng <jiaqiz@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
The live OpenCode agent verifies through /seed_session + cookie, and on that
path scale_swe masked nothing. Before, these were all trained as reward 0
(mask_sample false):
- a verification with no verdict (test patch did not apply, verifier exec
  raised, verifier sandbox never started, inconclusive after the retry);
- a verifier exec that ended without an exit status (non-timeout) or an eval
  script that stopped before pytest started (not reclassified as no verdict);
- a failed patch extraction (agent sandbox unreachable, capture ended without
  an exit status, no base commit, no task sandbox), which graded an EMPTY
  patch as a completed 0.

Now the cookie path uses the episode-session classification: those cases are
mask_sample true with failure_kind verifier_error / provider_unavailable /
session_lost and a failure_reason, and a lost capture is no longer graded.
Unchanged (still trained 0, unmasked): tests that ran and failed, a genuinely
empty model patch, a verifier timeout (a hang the patch caused), and git
exiting non-zero on a repository the agent broke. The cookie path still does
not replay. The now-unused _extract_model_patch is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jiaqi Zeng <jiaqiz@nvidia.com>
Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
The cookie path now captures the patch through _capture_model_patch, so
its task sandbox stop uses the bounded wait of sandbox_stop_timeout_seconds.
Its verifier sandbox stops are still not bounded. The README now says so.

Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@copy-pr-bot

copy-pr-bot Bot commented Nov 23, 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.

@yfw yfw added area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer labels Nov 23, 2026
@yfw

yfw commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1560b3c

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 23, 2026 23:05
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Nov 23, 2026

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

HOLD — agent-caused capture timeouts can now suppress training samples, and Scale-SWE cookie verification can stop a replacement sandbox.

Reviewed all 17 changed files, surrounding consumers, lifecycle handling and tests against the trusted base conventions. Existing feedback contains three issue comments, no formal reviews and no inline comments.

RISK — Representative model-rollout evidence is missing. The PR explicitly reports no model rollout and no live OpenSandbox enforcement test. These changes affect verifier masking and agent connectivity, so the smoke-rollout requirement in AGENTS.md applies. Could you provide representative real model rollouts covering the changed server paths, inspect agent/verifier outcomes, and verify that enabled egress enforcement permits model calls while blocking unrelated destinations? Record the head, configuration and observed outcomes in the PR. A full training run or reward profile is not required for these training environments.

Validation: CI run 45285605716, attempt 1, succeeded on 1560b3c3: core tests, all eight server-suite shards, sandbox tests and final aggregation passed. Lint also passed. Session-routing end-to-end and changed-server jobs were skipped, not passed. I did not rerun CI suites.

Purpose-built probes ran in 766267172432.dkr.ecr.us-east-1.amazonaws.com/gym:main-offline, Python 3.13.14, with checkout import origins verified. Real-Git base/head differential probes reproduced the capture-masking defect. Cookie/episode probes confirmed both affected consumers and episode replay. An endpoint-interleaving probe reproduced the Scale-SWE replacement-sandbox race on head but not merge-base. Generated-shell execution verified both output streams, exit-code preservation and timeout/provider-error classification. Fake-provider seed probes confirmed network-policy wiring in all three servers; they do not establish live network enforcement.

Note: formal approval is not available for this request, so this review is posted as a comment only.

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

Comment thread resources_servers/r2e_gym/app.py Resolved
Comment thread resources_servers/scale_swe/app.py Resolved
@yaoyu-33
yaoyu-33 requested a review from adil-a November 24, 2026 00:38
yfw and others added 6 commits November 23, 2026 17:03
A swe_gym run that hit evaluation_timeout returned reward 0 with no mask,
but with evaluation_completed false. Gym's eval recovery reads that row
as masked and not measured, so a resubmit stopped with "the run is not
complete", and run health counted a trial failure. The reward profile
and NeMo RL read mask_sample, so they already scored it as 0.

The response now reports the timeout as completed, as the sibling SWE
servers do. The retry on a fresh sandbox stays, because the retry loop
reads VerificationResult.completed, which does not change.

Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…arts

The eval scripts of swe_gym, r2e_gym and scale_swe exit 97 or 96 when the
image lacks the repository, the conda env or the hidden tests. They end
with the test command's own exit status, and code from the model's patch
runs inside the test process. A patch can therefore make pytest exit 97,
for example from a root conftest.py, and the server read that as a broken
image. With this PR's masks, the row was masked instead of a trained 0.

The servers now read 97 and 96 as a broken image only when the output
has no begin marker. The scripts exit with these codes before they print
the marker, so a real broken image is still masked.

Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When git fails on the agent's repository, these servers still grade the
empty patch. If that grading has no verdict, the row is masked. Its
failure_reason named the capture ("Failed to extract model patch: ...")
and dropped the verifier's own error, so it read like a patch capture
lost to the provider. The mask now uses the verifier's error as its
failure_reason, as swemer_ultra does. The error field does not change.

Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On the cookie path, _capture_model_patch read the task sandbox with .get,
and its finally looked the session up again to stop it. Two problems
followed:

- A /seed_session with the same cookie that finished during the capture
  registered a new sandbox, and the old verification stopped and forgot
  it. The re-seed also stopped the sandbox that the capture was reading.
- A cookie session has no close. After a stop that failed or outlasted
  sandbox_stop_timeout_seconds, the sandbox, base commit and untracked
  files stayed in the session maps for good.

The cookie path now pops the sandbox, base commit and untracked files at
the start, as the removed _extract_model_patch did, and stops that exact
sandbox with the bounded _wait_for_stop. The episode path does not
change: it holds the session lock for the whole verification. The
sandbox_stop_timeout_seconds description and the README now say which
cookie path stops are bounded.

Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A YAML provider_options key whose children are all commented out loads as
null. AgentNetworkConfig read it with .get("provider_options", {}), whose
default applies only to a missing key, so dict(None) raised TypeError on
the first sandbox. This PR made swe_gym, r2e_gym and swemer_ultra build
every sandbox's options through this helper, so they would fail even with
the egress flag off. The seven servers that already use the helper fail
the same way on main. A null value now counts as no options.

Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bounded wait

- A bash test runs the swe_gym eval script between its markers, with a
  runner that reports on stderr and one that calls exit itself. It fails
  against the script from main, without the stderr capture, and without
  the subshell.
- The model's own empty patch stays a graded, unmasked 0 in swe_gym and
  r2e_gym.
- The test of an interrupted grading waits for the grading to start
  with a 5 s limit, so a regression that skips grading fails instead of
  hanging the CI job.

Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yfw

yfw commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test df91095

On the cookie path, _capture_model_patch stops the captured sandbox with
_wait_for_stop. That wait removes its entry from _stop_tasks only when
the stop is done at the end of the wait. A stop that outlasted
sandbox_stop_timeout_seconds stayed in _stop_tasks for the life of the
server, and its task held the sandbox object. No close comes for a
cookie session, so nothing waited for that stop again.

The cookie path now adds a done callback that removes the entry when
the stop ends.

Signed-off-by: Yi-Fu Wu <yifu.wu@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yfw

yfw commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8645c67

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 25, 2026

This branch has not been deployed

No deployments
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 bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer risk:high Autobot PR risk: high 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.

4 participants