Repository navigation
fix(opencode): preserve overrides and sandbox tool outcomes - #4046
Conversation
|
/ok to test 49035c1 |
@lafrancef, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
|
/ok to test 49035c1 |
| if ( | ||
| native_status == "completed" | ||
| and part.get("tool") == "bash" | ||
| and type(exit_code) is int |
There was a problem hiding this comment.
OpenCode 1.17.11 records shell timeout/abort as completed with exit: null, so this still reports completed (reproduced with native-shaped SQLite records). Could we preserve timeout/cancelled, or unknown when indistinguishable? This is a remaining gap, not a new regression.
| trajectory = ( | ||
| TrajectoryRecord(task_id="unscoped", rollout_id=rollout_id or "unscoped") if collect_observations else None | ||
| TrajectoryRecord(task_id="unscoped", rollout_id=rollout_id or "unscoped") | ||
| if collect_observations and not capture_turns |
There was a problem hiding this comment.
I see the intentional turn-count change in the description. Could we confirm that canonical turns should include auxiliary responses too? Enabling capture now changes the count from native agent steps to provider responses, so historical and cross-harness turn counts are no longer directly comparable.
There was a problem hiding this comment.
@giuliolovisotto Can you double check if this is correct? Or if we need to change TE def?
There was a problem hiding this comment.
I would retain OpenCode’s native policy turns, and think about the TE later. I haven't look too much into how auxiliary responses should appear.
e5c1ae2 to
5dc3d2e
Compare
|
@lafrancef #4180 makes the same The old value makes every OpenCode rollout through a Gym model server fail with a 422 on the first request after a tool call. The one difference is that this PR uses |
…vers (NVIDIA-NeMo#4180) ## What does this PR do? When `opencode_agent` runs through a Gym model server (`model_server` set), the OpenCode config it generates sets `interleaved.field` to `reasoning`. OpenCode then sends earlier assistant turns back with a `reasoning` key. Gym's Chat Completions request schema accepts `reasoning_content` on assistant messages, not `reasoning`, so the first request after any tool call fails with a 422 (`extra_forbidden` at `body.messages[i]...reasoning`). The rollout ends at that point, but `gym eval run` still exits 0 and the failures file stays empty. Single-turn answers are unaffected, which makes this easy to miss. This PR sets the field to `reasoning_content`, the key Gym model servers send and accept. `opencode_sandboxed_agent` doesn't set `interleaved` and is unaffected. No GitHub issue: the bug was reported through internal QA, and this PR includes the reproduction below. Overlap: NVIDIA-NeMo#4046 makes the same change, using `setdefault` so a user's own `interleaved` setting wins, as part of a larger conformance change stacked on NVIDIA-NeMo#4045. This PR fixes the bug on its own so it can land first. NVIDIA-NeMo#4046 can drop its copy of the line or rebase over it. ## Validation - Added `test_model_server_replayed_reasoning_is_accepted_by_gym_chat_completions`. It builds the assistant message OpenCode sends after a tool call, using the field from the generated config, and validates it against `NeMoGymChatCompletionCreateParamsNonStreaming`. Without the fix it fails with the same `extra_forbidden` error. - `pytest responses_api_agents/opencode_agent/tests` in a fresh environment (`uv venv && uv sync --extra dev`). - `pre-commit run --all-files`. ## Rollouts All runs use OpenCode 1.17.11, `environments/opencode_reasoning_gym`, and `--model-type inference_provider`, with `model_server` pointing at `policy_model` and model-call capture enabled. Status codes come from the capture store. | Scenario | Model | Code | Call after the tool call | Result | |---|---|---|---|---| | Subtask command from the bug reproduction, 1 task | `eccn-gpt-oss-20b` | before | 422 | Stopped after 1 turn | | Subtask command from the bug reproduction, 1 task | `eccn-gpt-oss-20b` | after | 200 | 2 turns, reward 1.0 | | Model's own `bash` call, 3 tasks | `eccn-nemotron-3-nano-30b-a3b` | before | 422 on all 3 | Rewards 0, 0, 0 (empty answers); exit 0; failures file empty | | Model's own `bash` call, 3 tasks | `eccn-nemotron-3-nano-30b-a3b` | after | 200 | Rewards 1.0, 1.0, 1.0 | With the fix, OpenCode sends the model's reasoning back under `reasoning_content` (5,203 and 7,631 characters on the two tasks that used a tool). In the subtask scenario the replayed reasoning is empty, because OpenCode creates that tool call itself without calling the model. The Nemotron runs add a system prompt that requires one bash call before answering, so every task reaches the post-tool-call turn. ## Compatibility and benchmark impact OpenCode rollouts through a Gym model server no longer stop after their first tool call. Scores from multi-turn OpenCode runs on this route will change, since earlier runs were cut short. Nothing else in the configuration or API changes. ## Checklist - [x] I have read the [contributing guidelines](https://github.com/NVIDIA-NeMo/Gym/blob/main/CONTRIBUTING.md). - [x] The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs. - [x] Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable). - [x] Documentation added or updated, or N/A with justification. N/A: the README doesn't describe the `interleaved` setting. - [x] Pre-commit checks pass locally (`pre-commit run --all-files`) (so CI lint/format checks pass). - [x] New source files include the required Apache-2.0 SPDX header. N/A: no new files. - [x] All commits have DCO sign-off (`git commit -s`) (so the DCO check passes). Signed-off-by: Ananth Subramaniam <[email protected]>
49035c1 to
1ecddad
Compare
Respect explicit interleaved settings and apply the shell-outcome rules from #4450 to the separate sandboxed adapter. Co-authored-by: Frederic Lafrance <[email protected]> Co-authored-by: yaoyu-33 <[email protected]> Signed-off-by: Giulio Lovisotto <[email protected]>
1ecddad to
b1735c5
Compare
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/38251150169 |
The main/merge-queue [run 38069955548](https://github.com/NVIDIA-NeMo/Gym/actions/runs/38069955548/job/114266522363) completed all probe jobs but failed the P0 measurement: Codex 0/7, OpenCode 5/7, Pi 6/7, Hermes 7/7. The reporter is correctly exposing retained-evidence failures. This integrates the applicable existing fixes with the current native-session adapters: - Port NVIDIA-NeMo#4047's temporary Codex session reader and bounded 429 forwarding retries, including its timeout result preservation. Keep invocation ownership, original tool IDs/arguments/results and shell exit status before removing the temporary session. Native sandbox-session execution remains as implemented on main. - Port the shell-outcome portion of NVIDIA-NeMo#4046 into the shared OpenCode artifact parser. Nonzero exits fail; absent/null/invalid exits remain unknown. Preserve native turn semantics, per that PR's review discussion. - Require one terminal-400 token reconciliation outcome: `healthy`, with a known zero aggregate for zero finished responses. Preserve Hermes' actual runtime counters when early error returns omit them. Failed model termination still must be `unhealthy`; missing aggregate usage and incorrect nonzero totals fail. The health engine is unchanged. The token-total rule follows merged NVIDIA-NeMo#4287. This deliberately does not revive closed NVIDIA-NeMo#4286's proposal to accept either healthy or unobserved. No separate issue is necessary: the linked run is the reproduction, and NVIDIA-NeMo#4046/NVIDIA-NeMo#4047 plus FEA-461 track the underlying gaps. Existing PRs are left intact for author/maintainer coordination. Codex work is attributed to Frederic Lafrance and Giulio Lovisotto; OpenCode's nonzero-exit correction derives from Frederic's patch. Validation on macOS arm64 / Python 3.13.14, OpenAI SDK 2.44.0; base `728ac3395d1bc26b995b03ffb9aa6f0362b768ea`: - **2,050 passed, 113 skipped** in the final selected suite; skips are platform/optional-runtime cases. - Full `pre-commit run --all-files` and staged/working-tree `git diff --check` pass. Commit has DCO sign-off. - **28/28 conformance scenarios pass** across all four pinned harnesses; final Codex-only rerun is also 7/7. - Real `nvidia/nemotron-3-super-120b-a12b` model smoke: Codex, OpenCode and Hermes each have four captured model calls, one failed tool followed by two successful tools, and reward **1.0**. A local verifier independently checked the file contains `391` and the final answer contains `CONFORMANCE_DONE`. OpenCode's initial attempt was denied by its native external-directory permission; the rerun explicitly granted only the smoke's temporary artifact directory. Both attempts are retained. Exact test selection: ```bash python -m pytest --import-mode=importlib -q -o addopts='' -o log_cli=false \ scripts/harness_conformance/tests tests/unit_tests/harness_capabilities \ tests/unit_tests/test_harness_conformance_ci.py tests/unit_tests/test_harness_conformance_checks.py \ tests/unit_tests/test_rollout_collection.py tests/unit_tests/test_rollout_health.py \ responses_api_agents/codex_agent/tests responses_api_agents/opencode_agent/tests \ responses_api_agents/opencode_sandboxed_agent/tests responses_api_agents/pi_agent/tests \ responses_api_agents/hermes_agent/tests python scripts/run_harness_conformance.py --harness codex --harness opencode --harness pi --harness hermes --output <NEW_DIRECTORY> ``` Runtime pins: Codex 0.144.4, OpenCode 1.17.11, Pi 0.80.2, Hermes 26bb847a. Source imports were verified against the repair worktree; an early mixed-source/SDK setup attempt was discarded. The final Codex suite was rerun after adding malformed-record protection. Compatibility: correlated local Codex runs temporarily persist a session and can retry 429 twice; OpenCode shell-status evidence becomes accurate; terminal-rejection aggregate usage is strict. No dataset, reward policy, model settings, or benchmark-score claim changes. These probes qualify local adapter evidence; remote sandbox lifecycle qualification, Linux-only skipped tests and full repository CI remain separate. CI classification is **full**, because runner/shared test paths changed. No CI trust-gate comment was posted. Follow-up validation (`daab232a8`): Codex returns observations and timeout state directly instead of encoding synthetic stdout events. All 227 Codex tests passed (45 skipped), all-file pre-commit passed, and all seven fresh Codex conformance scenarios passed. Retry behavior is unchanged. --------- Signed-off-by: yaoyu-33 <[email protected]> Signed-off-by: Giulio Lovisotto <[email protected]> Co-authored-by: Frederic Lafrance <[email protected]> Co-authored-by: Giulio Lovisotto <[email protected]>
After #4450, two OpenCode gaps remain: local configuration overwrites explicit
interleavedsettings, and the separateopencode_sandboxed_agentreader treats completed shell execution as successful even for nonzero exits.This preserves explicit
interleavedsettings (defaulting toreasoning_contentonly when absent) and applies the existing shared reader's shell-outcome handling to the separate sandboxed reader: nonzero integer exits are failed; missing/invalid exits are unknown with an evidence gap. The existing outcome regression runs against both readers. Native policy turns and reward computation are unchanged.Based directly on main after #4450 merged. This follows up #4046's original review concerns; no separate issue is needed for these two remaining fixes.
Validation on rebased commit
b1735c5e2, main33be39484:pytest -q -o addopts='' -o log_cli=false --import-mode=importlib responses_api_agents/opencode_agent/tests responses_api_agents/opencode_sandboxed_agent/tests).pre-commit run --all-filesandgit diff --check: passed.scripts/run_harness_conformance.py --harness opencode: 7/7 scenarios passed, OpenCode 1.17.11.nvidia/nvidia/nemotron-3-nano-30b-a3bsmoke through Gym collection: 4 model calls, reward 1, evaluation_completed=true. An independent verifier checked the computed file value (391) and final answer. Both production readers agreed on one failed shell tool and two successful tools from the saved native SQLite artifact. This validates the separate sandboxed reader, not a full container execution; Docker-backed conformance is separate work.No dataset or scoring-policy changes. Saved sandbox tool outcomes become more accurate.