Skip to content

feat(mini-swe): run mini-SWE in task sandboxes through agent sessions - #5654

Merged
weijiac0619 merged 21 commits into
mainfrom
feat/mini-swe-agent-sessions
Nov 10, 2026
Merged

weijiac0619 merged 21 commits into
mainfrom
feat/mini-swe-agent-sessions

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Adds agent sessions to mini_swe_agent, running pinned mini-SWE 2.4.6 inside a borrowed or agent-owned task sandbox under SandboxSession. The existing SWE-Gym integration remains available through its legacy entrypoint. No separate issue is needed for this focused adapter integration and its review/CI corrections.

  • Seed builds a private Python runtime from the universal lock on the Agent Server and uploads it. The sandbox needs no Python, uv, or package-index access. Healthy runtimes are reused and installations are published atomically; SandboxPythonRuntime(constraints=...) permits the session runtime to differ from the legacy fork.
  • sessions_app.py disables Ray and refuses /run. One activation supports identical retries, rollout identity checks, deadlines/stops, and owner-aware close. Model calls use the rollout-prefixed Responses route and x-session-id.
  • MCP grants and Harbor task context feed the task-local MCP CLI. Recorded calls and submission output become response evidence; rejected model calls are not successful tools. Required connection failures retain their cause, optional failures are observation gaps, and SIGTERM closes stdio servers. MCP records and error text are bounded.
  • Model failures preserve their HTTP status. Gym's context-window marker ends the run as an incomplete context limit; unknown usage remains unknown. A deadline before any recorded model answer remains a retryable failure, while an explicit stop or a deadline after earlier replies remains gradable.
  • The runner and MCP CLI use a linked bin/mini-swe interpreter so pkill -f python does not kill the supervisor. Agent-owned sandboxes support network_access; borrowed sandboxes reject it. Unsupported task users, old glibc, and unsupported tool_choice values are refused before activation.

Compatibility and migration

Session requests accept max_output_tokens as a separate cap on every model call, consistent with other session harnesses. LiteLLM's extra_body preserves exact caps, including values below 16. This is not an aggregate episode budget. The legacy SWE-Gym /run still rejects that request field with HTTP 422; configure its per-call limit on the Model Server or direct endpoint instead.

miniswe_sandboxed_agent is deprecated in favor of mini_swe_agent/mini_swe_agent_sandboxed. Both its legacy and session configurations warn once at startup, without duplicate worker warnings. Existing entrypoints and benchmark presets keep working; no adapter removal date is set. Harbor task folders without [agent].user can use the replacement. Tasks with [agent].user and legacy /run presets, including Terminal-Bench-Science, keep the older adapter until they have a supported migration path. This preserves the migration caveats established in #5222.

Capability remains Evaluation: token-ID capture and training are not qualified. Task commands can modify session evidence files. No TB2.1/TB4 supported-agent declaration or full benchmark score is added, and migration does not promise identical benchmark results.

Failing CI test

The shared supervisor calculated its TERM grace from a timestamp taken before the initial /proc scan. A slow scan could consume the grace before the harness had a chance to save its checkpoint, yielding exit 137. The grace now starts after TERM. A delayed-scan regression reproduces 137 on the old code and passes after the fix. The readiness synchronization introduced in #5783, the original detached-service matrix, and its cleanup assertions remain intact.

Validation at 2d88245079851440cd2cf86dae4ddd909e99c8be

All execution was on the Linux workstation with Python 3.13.14, separate locked component environments, and imports verified against the isolated source checkout.

  • python -m pytest responses_api_agents/mini_swe_agent/tests tests/unit_tests/agents/test_process_supervisor.py tests/unit_tests/agents/test_sandbox_session.py -q -o addopts= — 316 passed.
  • python -m pytest responses_api_agents/miniswe_sandboxed_agent/tests -q -o addopts= — 199 passed.
  • python -m pytest tests/unit_tests/agents/test_sandbox_supervisor_client.py tests/unit_tests/agents/test_sandbox_supervisor_bootstrap.py tests/unit_tests/tooling/test_agent_environment_default_configs.py tests/unit_tests/tooling/test_agent_environment_session_templates.py -q -o addopts= — 98 passed.
  • Regression controls fail on the previous production sources for accepted token caps, both adapter deprecation paths, and delayed-scan checkpointing; the fixed-source suites pass. The real mini-SWE runtime test also verifies the same cap on two successive calls.
  • pre-commit run --all-files — passed, using isolated pre-commit 4.3.0 compatible with the workstation's Git 2.25.1. Final changed-file hashes match the workstation sources; the commit has DCO sign-off.
  • fern check --warnings — zero errors; the unauthenticated remote-redirect check is skipped. The prior head's Fern preview backend failure recovered on retry: successful run.
  • Real-model smoke: one unchanged Reasoning Gym task/verifier, with request controls set to max_output_tokens=4096, temperature 0, top_p 1; NIM nvidia/nemotron-3.5-super-vl-120b-a12b, thinking off, agent-owned Docker debian:bookworm-slim, 180-second activation limit. All six captured model requests retained cap 4096 and returned HTTP 200. The response completed and was graded, unmasked, reward 0.0: without answer tags the verifier parsed the full explanation into extra name/role assignments. An initial attempt hit upstream HTTP 429 and was retained as a retryable, unscored failure. Both attempts left no containers or server/collector process groups. This verifies runtime and grading behavior, not benchmark quality.

Full CI for this exact head passed after maintainer authorization: CICD NeMo Gym (all four core shards, combined core coverage, sandbox tests, all eight server-suite shards, and harness conformance), package validation, and docs preview. Final PR check snapshot: 57 successful, 13 skipped, zero failures or pending checks.

yaoyu-33 and others added 6 commits November 4, 2026 16:50
mini_swe_agent now serves agent sessions next to its SWE-Gym /run path. A session runs
mini-SWE 2.4.6 in the sandbox the Resources Server lends, or in one the agent starts from
sandbox_provider, supervised by SandboxSession. The runtime is built on the agent server
with SandboxPythonRuntime from a full lock (runtime/requirements.txt), uploaded at seed,
checked for its version before reuse, and published atomically; the sandbox needs no
network. SandboxPythonRuntime takes that lock as constraints instead of the agent
server's environment, which keeps the fork /run uses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…trim logs in the sandbox

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…n the response

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@copy-pr-bot

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

@yaoyu-33

yaoyu-33 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e93aff5

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

The metadata keys, observation source and tool-call variable this PR adds follow the upstream distribution name
(mini-swe-agent); miniswe stays only in the deprecated variant and upstream's import package.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 00c4111

app.py declares ray_enabled for the SWE-Gym /run pipeline, so Gym started
Ray for the session template too and required the ray extra where gym
runs. sessions_app.py serves the same agent with ray_enabled = False and
refuses /run; the session template starts it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test cf4aaa0

yaoyu-33 and others added 2 commits November 5, 2026 11:00
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…usals

- List sessions_app.py's Ray opt-out in the Ray inventory test, so core CI
  accepts MiniSWESessionsAgent's ray_enabled = False.
- Report only mcp_calls.jsonl records for the run's MCP servers; count the
  malformed or foreign lines as an mcp_call_record_invalid gap instead of
  failing collection, and read no records in a run without MCP servers.
- Leave the function calls of a response mini-SWE rejected for its format out
  of the response output; they never ran. The model call and usage stay.
- Fail a run that reached its deadline before any model call returned as a
  model transport error (Timeout), unless a rollout stop ended it.
- Report a run that close stopped as cancelled, not killed, when the
  activation returns before close cancels it.
- Refuse request tools that no MCP server can reach (422), and refuse a
  task.json that is not a JSON object or a task MCP server without a name as
  final seed errors.
- Read an existing task.json that cannot be read as a failure, not as absent.
- Keep mini-SWE's config directory in the import check's own HOME.
- Save the trajectory before each step's commands run, so a command that
  kills the runner leaves the model call; decode MCP CLI output with
  errors="replace".
- Report an MCP server whose tool listing fails like one that did not
  connect, instead of failing the whole listing.
- Require the task workdir to be disjoint from the session directory.
- Build the runtime for the real mini-SWE and MCP tests in conftest.py when
  uv is on PATH; add tests for the HTTP session lifecycle, close order,
  disconnected waiters, Harbor task transports, MCP authentication over both
  HTTP transports, background processes, and the cases above.
- README: claim Evaluation until Harness Conformance runs mini-SWE, describe
  the other mini-SWE session adapter, pairings and limits, and the new
  outcomes; list mini-SWE as a resolve_agent_timeout user in the harness docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 274425c

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test c3d0243

@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/42916839316

Merged via the queue into main with commit 65dd99e Nov 10, 2026
70 of 72 checks passed
@weijiac0619
weijiac0619 deleted the feat/mini-swe-agent-sessions branch November 10, 2026 22:53
yaoyu-33 added a commit that referenced this pull request Nov 10, 2026
main's #5654 added a mini-SWE row to the adapter tool table in
add-or-update-a-harness.mdx, right where this branch adds the OpenHands
row. Keep both rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
yaoyu-33 added a commit to yaoyu-33/Gym that referenced this pull request Nov 10, 2026
Resolve the integrate-existing-agents conflict with main's mini-SWE
deprecation (NVIDIA-NeMo#5654): keep main's wording and its new mini_swe_agent
migration paragraph, and drop hermes_sandboxed_agent from the deprecated
list, since this branch removes that agent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
weijiac0619 added a commit that referenced this pull request Nov 11, 2026
Brings in #5654's mini_swe_agent agent sessions (0dc9f54), which the TB4
preset stacked on this branch runs and the docs example names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>
weijiac0619 added a commit that referenced this pull request Nov 11, 2026
The CLI branch now carries main with #5654's mini_swe_agent sessions.
miniswe_sandboxed_agent's deprecation notice and README take main's text,
with its legacy-preset links pointing at miniswe_legacy_agent.yaml; the TB4
Harbor entry's README keeps its committed override and links the moved
Harbor server docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>
weijiac0619 added a commit that referenced this pull request Nov 11, 2026
…ent sessions

terminal_bench_4/miniswe now composes mini_swe_agent's sandboxed config
(#5654) instead of the deprecated miniswe_sandboxed_agent. The benchmark
overrides map onto it: tb4_max_steps to step_limit, tb4_step_timeout_sec
to step_timeout, and tb4_agent_max_timeout_sec to
sandbox_runner_timeout_seconds (default 28800, which each task's own
budget can only shorten). The manifest, the preset test and the READMEs
follow; miniswe_legacy_agent stays on miniswe_sandboxed_agent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>
khazic pushed a commit to khazic/Gym-lao that referenced this pull request Nov 14, 2026
…ment server and keep the relay preset as miniswe_legacy_agent (NVIDIA-NeMo#5697)

* feat(eval): run a benchmark config that names a Harbor target

A benchmark config may set `harbor_target` (a task folder, a committed entry
under environments/harbor/, or a harbor: reference) and define the one agent
instance the benchmark runs. `gym eval prepare --benchmark` and
`gym eval run --benchmark` then run that target as `gym eval run <target>`
does, with the benchmark's harness and its settings. `--agent-type` swaps in
another harness's shipped config; the dataset's allowed_agents still decides at
prepare. `--agent` is refused rather than ignored.

Manifests gain an optional `harbor_target`, mirrored from the config; with it
`datasets` is empty and validation checks the target resolves without a fetch.
Benchmarks that compose their own servers prepare and run as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* feat(terminal_bench_4): run the mini-SWE preset on the Harbor environment server

`terminal_bench_4/miniswe` now names the Harbor entry environments/harbor/
terminal_bench_4 (`harbor_target`) and runs it with miniswe_sandboxed_agent on
episode sessions: the Harbor environment server owns each task sandbox, its
Compose group and the separate verifier. The preset keeps the Artificial
Analysis settings (500 steps, 30 s per command, each task's 8-hour budget) and
raises the episode bound to 54000 s so the slowest verifier fits.

The legacy /run preset stays as `terminal_bench_4/miniswe_run` (deprecated)
until the TB4 resources server is retired; the smoke runner and the server's
example config follow it. The entry's dataset.toml sets CIRCLE_NODE_TOTAL=3 for
nextjs-performance, as the resources server does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* fix(eval): keep a Harbor-backed benchmark's server settings over the server defaults

A benchmark config that names a Harbor target may set the shipped
harbor_environment_server instance's settings, such as a longer episode bound.
build_run loaded the server's own config (harbor.yaml) after the benchmark
config, so the server defaults won: terminal_bench_4/miniswe's 54000 s episode
bound resolved to 21600 s. With --agent-type the benchmark config is not loaded
at all, so its server settings were dropped too.

The settings now travel with the selected agent as server_settings, for the
benchmark's own harness and for one --agent-type swaps in. build_run writes them
to server_config_<agent>.yaml beside the run config and loads it after
harbor.yaml. A test merges the run's config files in Gym's order and checks the
benchmark's episode bound wins with both harnesses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* test(harbor): allow TB4's one committed task override in the entries check

The TB4 entry's dataset.toml now sets CIRCLE_NODE_TOTAL=3 for
nextjs-performance. The committed-entries test still requires TB 2.1's
table to hold only its source, and TB4's to hold only its source and
exactly that override.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* refactor(terminal_bench_4): rename the relay preset to miniswe_legacy_agent

The previous /run preset is kept as terminal_bench_4/miniswe_legacy_agent,
following the *_legacy_agent name used for the other relay presets kept
during the migration. The config, its manifest, smoke.py, the resources
server's example config, the docs and the tests follow the new name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* feat(terminal_bench_4): run the Harbor mini-SWE preset on mini_swe_agent sessions

terminal_bench_4/miniswe now composes mini_swe_agent's sandboxed config
(NVIDIA-NeMo#5654) instead of the deprecated miniswe_sandboxed_agent. The benchmark
overrides map onto it: tb4_max_steps to step_limit, tb4_step_timeout_sec
to step_timeout, and tb4_agent_max_timeout_sec to
sandbox_runner_timeout_seconds (default 28800, which each task's own
budget can only shorten). The manifest, the preset test and the READMEs
follow; miniswe_legacy_agent stays on miniswe_sandboxed_agent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* fix(eval): prepare and run a Harbor-backed benchmark with all of its settings

Preparation runs before the run config exists, and it read only the
overrides left after the benchmark config was dropped, so a preset's
builds:, sandbox, Compose overlay, volume, registry and pairing settings
never reached it. Preparation now loads the benchmark config first, below
every --config overlay and command-line override; collection keeps the
de-duplicated overrides.

The benchmark's own top-level keys besides its agent instance now travel
as benchmark_settings (not only the Harbor server block), loaded after the
server's and the sandbox provider's configs, so a harness --agent-type
swaps in keeps them and the keys they interpolate.

harbor_benchmark checks the config's include closure for the agent count
and for extra resources or environment servers, and refuses an agent
instance that sets _inherit_from. A malformed benchmark YAML is a usage
error rather than a traceback. Test fixtures use mini_swe_agent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* fix(environment): validate a Harbor-backed manifest as the run binds its agent

Static resolution applies the same agent overrides build_run applies to
the generated agent, so a harness whose shipped template leaves
resources_server.name for benchmark composition (Terminus) validates.
The catalog lookup reports no resources server for a Harbor-backed
config. A harbor: target must parse as a hub reference, and a local
target must be a directory.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* docs: describe a Harbor-backed benchmark's settings, selectors and manifest

The Harbor section lists the settings a benchmark config carries and
when they apply, the CLI reference no longer promises --config and
--agent-type are equivalent for a Harbor-backed benchmark, and the
manifest paragraph matches the field reference's Harbor cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* fix(eval): carry included benchmark settings and refuse Harbor presets the run cannot honor

- benchmark_settings now come from the benchmark config with the configs it
  includes, minus its agent instance and keys only the harness's shipped
  config sets, so an included episode bound or builds block reaches the run
  as it reaches preparation, also with --agent-type.
- A config whose includes set harbor_target while it does not is refused
  with a usage error, and `gym eval run --config <Harbor-backed preset>` is
  refused before plain collection starts its bare agent.
- A malformed included config (ConfigError) is a usage error, not a traceback.
- Validation drops an unreachable condition.
- Tests: included settings under both harnesses, variant and --config
  refusals, a malformed include, the oracle's preparation settings, the
  environment-manifest datasets schema rule, and the dataset_owner and
  include-only target validation branches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* docs(harbor): scope Harbor-backed benchmark flags to gym eval run and list benchmark_settings_<agent>.yaml

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* fix(harbor): keep an included Harbor-backed preset's settings and show a gym eval run example for it

A variant that repeats harbor_target and includes a Harbor-backed preset lost the preset's
benchmark settings: the preset also defines the agent instance, so it was read as the harness's
shipped config and its server settings (the episode bound) fell back to the server's default.
A config that sets harbor_target is now a benchmark source; only configs that define the agent
without a target are harness configs.

The environment catalog carries the manifest's harbor_target, so inspecting a Harbor-backed entry
shows a `gym eval run` example instead of `gym env start`, which does not compose its Harbor
environment server. The Harbor page now says `gym list benchmarks` lists such a benchmark through
its manifest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* fix(terminal_bench_4): address review of the Harbor-backed mini-SWE preset

- dataset.toml: set nextjs-performance's CIRCLE_NODE_TOTAL=3 in its separate verifier's
  environment too; the verifier gets only its own [verifier.environment].env.
- miniswe.yaml: raise the server's harness_setup_allowance_s to 900 s, mini-SWE's install timeout.
- miniswe_legacy_agent.yaml: deprecation header, as the other *_legacy_agent presets have.
- README: Harbor scoring, a mapping from the /run keys, the /run profile's sandbox labels and
  readiness wait as deployment settings, a swapped harness's own limits; /run-only sections move
  under "The /run profile", the MCP package-index requirement is restored there, and the output
  truncation note is corrected.
- Harbor entry README, overlay comment and mini_swe_agent README: pinned by tag, and no longer
  name miniswe_sandboxed_agent for this preset.
- Tests: the committed-entries assert covers the verifier override; the preset's literal value
  asserts give way to a variant-of-the-preset test that keeps the 54000 s episode bound.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* style(harbor): apply ruff format to the included-preset and inspect changes

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

---------

Signed-off-by: weijia chen <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

This branch had an error being deployed

1 failed deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer QA_verified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants