Skip to content

fix(opencode): preserve overrides and sandbox tool outcomes - #4046

Merged
giuliolovisotto merged 1 commit into
mainfrom
flafrance/opencode-harness-conformance
Oct 12, 2026
Merged

giuliolovisotto merged 1 commit into
mainfrom
flafrance/opencode-harness-conformance

Conversation

@lafrancef

@lafrancef lafrancef commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

After #4450, two OpenCode gaps remain: local configuration overwrites explicit interleaved settings, and the separate opencode_sandboxed_agent reader treats completed shell execution as successful even for nonzero exits.

This preserves explicit interleaved settings (defaulting to reasoning_content only 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, main 33be39484:

  • Both complete OpenCode adapter test directories: 420 passed, 37 skipped (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-files and git diff --check: passed.
  • Fresh scripts/run_harness_conformance.py --harness opencode: 7/7 scenarios passed, OpenCode 1.17.11.
  • Fresh live nvidia/nvidia/nemotron-3-nano-30b-a3b smoke 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.

@lafrancef lafrancef added bug Something isn't working area:agent Agent harnesses and Responses API agent behavior needs-review PR is ready for code review and waiting on a reviewer labels Oct 5, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 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 added the complexity:low Localized change in one scope with a small, straightforward review surface label Oct 5, 2026
@lafrancef

Copy link
Copy Markdown
Contributor Author

/ok to test 49035c1

@copy-pr-bot

copy-pr-bot Bot commented Oct 5, 2026

Copy link
Copy Markdown

/ok to test 49035c1

@lafrancef, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@lafrancef

Copy link
Copy Markdown
Contributor Author

/ok to test 49035c1

if (
native_status == "completed"
and part.get("tool") == "bash"
and type(exit_code) is int

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.

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.

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.

done.

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

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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giuliolovisotto Can you double check if this is correct? Or if we need to change TE def?

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.

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.

@lafrancef
lafrancef force-pushed the flafrance/pi-harness-conformance branch from e5c1ae2 to 5dc3d2e Compare October 6, 2026 20:44
Base automatically changed from flafrance/pi-harness-conformance to main October 6, 2026 21:15
@ananthsub

Copy link
Copy Markdown
Contributor

@lafrancef #4180 makes the same interleaved.field change as this PR, from reasoning to reasoning_content, as a standalone fix.

The old value makes every OpenCode rollout through a Gym model server fail with a 422 on the first request after a tool call. gym eval run still exits 0 and the failures file stays empty, so the failure is easy to miss. The goal is to land that fix without waiting on #4045 and the turn-counting changes here.

The one difference is that this PR uses setdefault, so a user's own interleaved setting wins. #4180 always overwrites it, like the old line did. If #4180 lands first, this PR only needs to rebase onto it, keeping the setdefault form and the override test. I've requested your review on #4180.

jeffwillette pushed a commit to jeffwillette/Gym that referenced this pull request Oct 7, 2026
…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]>
@giuliolovisotto
giuliolovisotto force-pushed the flafrance/opencode-harness-conformance branch from 49035c1 to 1ecddad Compare October 12, 2026 09:12
@giuliolovisotto giuliolovisotto changed the title fix(opencode): complete harness conformance evidence fix(opencode): preserve overrides and sandbox tool outcomes Oct 12, 2026
@giuliolovisotto
giuliolovisotto changed the base branch from main to codex/base-pr-4450 October 12, 2026 09:13
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]>
@giuliolovisotto
giuliolovisotto force-pushed the flafrance/opencode-harness-conformance branch from 1ecddad to b1735c5 Compare October 12, 2026 10:45
@giuliolovisotto
giuliolovisotto requested a review from a team as a code owner October 12, 2026 10:45
@giuliolovisotto
giuliolovisotto changed the base branch from codex/base-pr-4450 to main October 12, 2026 10:45
@giuliolovisotto
giuliolovisotto added this pull request to the merge queue Oct 12, 2026
@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/38251150169

Merged via the queue into main with commit fb11551 Oct 12, 2026
47 checks passed
@giuliolovisotto
giuliolovisotto deleted the flafrance/opencode-harness-conformance branch October 12, 2026 13:02
ananthsub pushed a commit to ananthsub/Gym that referenced this pull request Oct 12, 2026
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]>

This branch was previously deployed

1 inactive deployment
public — b1735c5e Deployed Oct 12, 2026 by copy-pr-bot[bot] via release / finalize / notify #5023
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 bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants