Skip to content

SWE: Opencode Integration - #1302

Merged
bxyu-nvidia merged 28 commits into
mainfrom
sdd/opencode-trainer
Jul 9, 2026
Merged

bxyu-nvidia merged 28 commits into
mainfrom
sdd/opencode-trainer

Conversation

@sdevare-nv

@sdevare-nv sdevare-nv commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds opencode as a second agent harness for swe_agents, alongside the existing OpenHands harness, plus several supporting benchmark and infrastructure additions:

  • opencode harness (agent_framework: opencode) — runs opencode's real processor.ts agentic loop via a custom @opencode-ai/nemo-gym LanguageModelV3 provider that swaps the LLM transport while keeping opencode's tools, prompts, and parsing intact. Trajectory format, token-ID contiguity guarantees, and patch extraction are unchanged from OpenHands, so downstream training/eval code needs no changes to consume opencode rollouts.
  • DeepSWE and DeNovoSWE dataset integrations (⚠️ WIP, not yet baselined against a reference model) — new DeepSWEDatasetProcessor / DeNovoSWEDatasetProcessor, each with a golden-patch-validated harness (DeepSWE: 110/113 golden-resolved; DeNovoSWE: 3034/3668, 82.69%).
  • swe-bench-ext fixes for the variant-generation config path.
  • Message replay for OpenHands — a prior partial trajectory (system + user + function_call/function_call_output items) can be resumed instead of starting fresh, powering training-time replay and trajectory branching.
  • Memory watchdog (OOM handling) — the enroot/apptainer sandbox has no cgroup support, so per-container memory limits (apptainer_memory_limit_mb) are now enforced by a userspace RSS watchdog (RunOpenHandsAgent._memory_watchdog) instead of ulimit -v/apptainer --memory (both silently no-op in this sandbox). OOM kills feed into GRPO masking so accidental rewards aren't credited.
  • Dataset-aware environment activation for the opencode harness (SWE-Gym → conda testbed, R2E-Gym → .venv, default → conda testbed).
  • Results now write to a per-run dedicated folder instead of a shared directory.

What's new

opencode integration

  • New OpenCodeHarnessProcessor, paired with the existing RunOpenHandsAgent.process_single_datapoint driver (only the in-SIF command differs by agent_framework).
  • Workspace path resolution is dataset-aware (_resolve_opencode_workspace_path): defaults to /testbed (the real SWE-bench image convention) with per-dataset overrides for nv-internal-1/deepswe (/app), denovoswe (packed workspace_path), swe-bench-ext (/workspace/repo), and SWE-rebench-V2 (/{repo_name}).
  • Subagent support behind opencode_subagents_enabled, with per-session trajectory capture and host-copy for offline training pickup.
  • Prompt overrides propagate the same way as OpenHands (resolved_user_prompt_template / resolved_system_prompt_template), rendered into a fixed SIF-mounted path.
  • Replay is intentionally not implemented for opencode (short-circuits to the OpenHands-only path).

DeepSWE / DeNovoSWE (WIP)

  • DeepSWE: Harbor task format, in-SIF tests/test.sh verifier, reward read from /logs/verifier/reward.txt. Config: configs/swebench_deepswe.yaml.
  • DeNovoSWE: doc-to-repo tasks; wipes original source via clean.sh, re-injects the spec as README.md, applies the agent patch, lays canonical tests from test_patch, and runs per-file pytest with a --collect-only pre-flight. Config: configs/swebench_denovoswe.yaml.
  • Both are golden-patch validated but not yet baselined against a reference model — treat their reward signal as directional for now.

Prompt, agent-class, and tool-name diversity

  • 15 prompt families under prompts/ (breadth-first, codex, minimalist, root-cause, etc.), each pairing a system_prompt.j2/user_prompt.j2 with an agent_cls (CodeActAgent, OpenCodeAgent, CodexAgent, Terminus2Agent).
  • Selection is deterministic per instance_id by default (reproducible eval) or uniformly random per run when agent_prompt_override_random=true (RL training diversity).
  • Independent diversify_tool_names / camel_case_tool_names knobs to break the model's reliance on memorized tool names.

Reliability / infra

  • Memory watchdog replaces the (nonfunctional in this sandbox) cgroup/ulimit-based memory limiting; OOM kills on either the agent or eval container are tracked and mask the GRPO sample.
  • Message replay for OpenHands, with the input/output split in the response found by matching tool-call ids against the replayed prefix.
  • Ground-truth redaction: only an allowlisted set of instance fields (AGENT_VISIBLE_INSTANCE_FIELDS) is exposed inside the agent container; eval-only fields (gold/test patches, graded test names) stay host-side under eval_private/.

GRPO masking (mask_sample)

SWEBenchWrapperInstanceConfig.mask_sample tells downstream RL to drop the gradient for a rollout whenever the reward can't be trusted, rather than filtering it out entirely — the trajectory is still returned, just flagged. It's set to True when any of:

  1. The patch resolved the tests but the agent didn't actually submit cleanly — it hit max_iteration or blew the context_window (bucketed from the agent's error string by _classify_agent_error) — the reward is accidental, not earned.
  2. The eval container hit swebench_tests_timeout — the reward is unreliable (tests may not have finished running).
  3. The agent itself hit swebench_agent_timeout (wall-clock) — masked regardless of whether it resolved.
  4. The memory watchdog OOM-killed the agent container.
  5. The memory watchdog OOM-killed the eval container.

Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
@youngeunkwon0405

Copy link
Copy Markdown
Contributor

Hi @sdevare-nv, are we planning to move to opencode instead of openhands? Or is this just to support various harnesses?

@cmunley1

cmunley1 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

can u add example rollouts which use opencode?

@sdevare-nv

Copy link
Copy Markdown
Contributor Author

@cmunley1 the examples are added here

Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Junkeun Yi <[email protected]>
This reverts commit c34d56c.
@copy-pr-bot

copy-pr-bot Bot commented Jun 10, 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.

Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
@bxyu-nvidia
bxyu-nvidia merged commit 102f1ca into main Jul 9, 2026
16 checks passed
@bxyu-nvidia
bxyu-nvidia deleted the sdd/opencode-trainer branch July 9, 2026 18:24
OlegSudakov pushed a commit to OlegSudakov/Gym that referenced this pull request Jul 15, 2026
## Summary

Adds [opencode](https://opencode.ai) as a second agent harness for
`swe_agents`, alongside the existing OpenHands harness, plus several
supporting benchmark and infrastructure additions:

- **opencode harness** (`agent_framework: opencode`) — runs opencode's
real `processor.ts` agentic loop via a custom `@opencode-ai/nemo-gym`
`LanguageModelV3` provider that swaps the LLM transport while keeping
opencode's tools, prompts, and parsing intact. Trajectory format,
token-ID contiguity guarantees, and patch extraction are unchanged from
OpenHands, so downstream training/eval code needs no changes to consume
opencode rollouts.
- **DeepSWE and DeNovoSWE dataset integrations** (⚠️ WIP, not yet
baselined against a reference model) — new `DeepSWEDatasetProcessor` /
`DeNovoSWEDatasetProcessor`, each with a golden-patch-validated harness
(DeepSWE: 110/113 golden-resolved; DeNovoSWE: 3034/3668, 82.69%).
- **swe-bench-ext fixes** for the variant-generation config path.
- **Message replay for OpenHands** — a prior partial trajectory (system
+ user + `function_call`/`function_call_output` items) can be resumed
instead of starting fresh, powering training-time replay and trajectory
branching.
- **Memory watchdog (OOM handling)** — the enroot/apptainer sandbox has
no cgroup support, so per-container memory limits
(`apptainer_memory_limit_mb`) are now enforced by a userspace RSS
watchdog (`RunOpenHandsAgent._memory_watchdog`) instead of `ulimit
-v`/`apptainer --memory` (both silently no-op in this sandbox). OOM
kills feed into GRPO masking so accidental rewards aren't credited.
- **Dataset-aware environment activation** for the opencode harness
(SWE-Gym → conda `testbed`, R2E-Gym → `.venv`, default → conda
`testbed`).
- Results now write to a per-run dedicated folder instead of a shared
directory.

## What's new

### opencode integration
- New `OpenCodeHarnessProcessor`, paired with the existing
`RunOpenHandsAgent.process_single_datapoint` driver (only the in-SIF
command differs by `agent_framework`).
- Workspace path resolution is dataset-aware
(`_resolve_opencode_workspace_path`): defaults to `/testbed` (the real
SWE-bench image convention) with per-dataset overrides for
`nv-internal-1`/`deepswe` (`/app`), `denovoswe` (packed
`workspace_path`), `swe-bench-ext` (`/workspace/repo`), and
`SWE-rebench-V2` (`/{repo_name}`).
- Subagent support behind `opencode_subagents_enabled`, with per-session
trajectory capture and host-copy for offline training pickup.
- Prompt overrides propagate the same way as OpenHands
(`resolved_user_prompt_template` / `resolved_system_prompt_template`),
rendered into a fixed SIF-mounted path.
- Replay is intentionally **not** implemented for opencode
(short-circuits to the OpenHands-only path).

### DeepSWE / DeNovoSWE (WIP)
- DeepSWE: Harbor task format, in-SIF `tests/test.sh` verifier, reward
read from `/logs/verifier/reward.txt`. Config:
`configs/swebench_deepswe.yaml`.
- DeNovoSWE: doc-to-repo tasks; wipes original source via `clean.sh`,
re-injects the spec as `README.md`, applies the agent patch, lays
canonical tests from `test_patch`, and runs per-file pytest with a
`--collect-only` pre-flight. Config: `configs/swebench_denovoswe.yaml`.
- Both are golden-patch validated but not yet baselined against a
reference model — treat their reward signal as directional for now.

### Prompt, agent-class, and tool-name diversity
- 15 prompt families under `prompts/` (breadth-first, codex, minimalist,
root-cause, etc.), each pairing a `system_prompt.j2`/`user_prompt.j2`
with an `agent_cls` (`CodeActAgent`, `OpenCodeAgent`, `CodexAgent`,
`Terminus2Agent`).
- Selection is deterministic per `instance_id` by default (reproducible
eval) or uniformly random per run when
`agent_prompt_override_random=true` (RL training diversity).
- Independent `diversify_tool_names` / `camel_case_tool_names` knobs to
break the model's reliance on memorized tool names.

### Reliability / infra
- Memory watchdog replaces the (nonfunctional in this sandbox)
cgroup/ulimit-based memory limiting; OOM kills on either the agent or
eval container are tracked and mask the GRPO sample.
- Message replay for OpenHands, with the input/output split in the
response found by matching tool-call ids against the replayed prefix.
- Ground-truth redaction: only an allowlisted set of instance fields
(`AGENT_VISIBLE_INSTANCE_FIELDS`) is exposed inside the agent container;
eval-only fields (gold/test patches, graded test names) stay host-side
under `eval_private/`.

### GRPO masking (`mask_sample`)
`SWEBenchWrapperInstanceConfig.mask_sample` tells downstream RL to drop
the gradient for a rollout whenever the reward can't be trusted, rather
than filtering it out entirely — the trajectory is still returned, just
flagged. It's set to `True` when any of:
1. The patch resolved the tests **but** the agent didn't actually submit
cleanly — it hit `max_iteration` or blew the `context_window` (bucketed
from the agent's error string by `_classify_agent_error`) — the reward
is accidental, not earned.
2. The eval container hit `swebench_tests_timeout` — the reward is
unreliable (tests may not have finished running).
3. The agent itself hit `swebench_agent_timeout` (wall-clock) — masked
regardless of whether it resolved.
4. The memory watchdog OOM-killed the **agent** container.
5. The memory watchdog OOM-killed the **eval** container.

---------

Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Junkeun Yi <[email protected]>
Co-authored-by: Junkeun Yi <[email protected]>
Signed-off-by: Oleg Sudakov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants