Repository navigation
SWE: Opencode Integration - #1302
Merged
Merged
Conversation
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Sugam Devare <[email protected]>
Contributor
|
Hi @sdevare-nv, are we planning to move to opencode instead of openhands? Or is this just to support various harnesses? |
Contributor
|
can u add example rollouts which use opencode? |
Contributor
Author
Signed-off-by: Sugam Devare <[email protected]>
Signed-off-by: Junkeun Yi <[email protected]>
This reverts commit c34d56c.
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]>
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
approved these changes
Jul 9, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opencode as a second agent harness for
swe_agents, alongside the existing OpenHands harness, plus several supporting benchmark and infrastructure additions:agent_framework: opencode) — runs opencode's realprocessor.tsagentic loop via a custom@opencode-ai/nemo-gymLanguageModelV3provider 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.DeepSWEDatasetProcessor/DeNovoSWEDatasetProcessor, each with a golden-patch-validated harness (DeepSWE: 110/113 golden-resolved; DeNovoSWE: 3034/3668, 82.69%).function_call/function_call_outputitems) can be resumed instead of starting fresh, powering training-time replay and trajectory branching.apptainer_memory_limit_mb) are now enforced by a userspace RSS watchdog (RunOpenHandsAgent._memory_watchdog) instead ofulimit -v/apptainer --memory(both silently no-op in this sandbox). OOM kills feed into GRPO masking so accidental rewards aren't credited.testbed, R2E-Gym →.venv, default → condatestbed).What's new
opencode integration
OpenCodeHarnessProcessor, paired with the existingRunOpenHandsAgent.process_single_datapointdriver (only the in-SIF command differs byagent_framework)._resolve_opencode_workspace_path): defaults to/testbed(the real SWE-bench image convention) with per-dataset overrides fornv-internal-1/deepswe(/app),denovoswe(packedworkspace_path),swe-bench-ext(/workspace/repo), andSWE-rebench-V2(/{repo_name}).opencode_subagents_enabled, with per-session trajectory capture and host-copy for offline training pickup.resolved_user_prompt_template/resolved_system_prompt_template), rendered into a fixed SIF-mounted path.DeepSWE / DeNovoSWE (WIP)
tests/test.shverifier, reward read from/logs/verifier/reward.txt. Config:configs/swebench_deepswe.yaml.clean.sh, re-injects the spec asREADME.md, applies the agent patch, lays canonical tests fromtest_patch, and runs per-file pytest with a--collect-onlypre-flight. Config:configs/swebench_denovoswe.yaml.Prompt, agent-class, and tool-name diversity
prompts/(breadth-first, codex, minimalist, root-cause, etc.), each pairing asystem_prompt.j2/user_prompt.j2with anagent_cls(CodeActAgent,OpenCodeAgent,CodexAgent,Terminus2Agent).instance_idby default (reproducible eval) or uniformly random per run whenagent_prompt_override_random=true(RL training diversity).diversify_tool_names/camel_case_tool_namesknobs to break the model's reliance on memorized tool names.Reliability / infra
AGENT_VISIBLE_INSTANCE_FIELDS) is exposed inside the agent container; eval-only fields (gold/test patches, graded test names) stay host-side undereval_private/.GRPO masking (
mask_sample)SWEBenchWrapperInstanceConfig.mask_sampletells 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 toTruewhen any of:max_iterationor blew thecontext_window(bucketed from the agent's error string by_classify_agent_error) — the reward is accidental, not earned.swebench_tests_timeout— the reward is unreliable (tests may not have finished running).swebench_agent_timeout(wall-clock) — masked regardless of whether it resolved.