Skip to content

fix(opencode): replay reasoning as reasoning_content on Gym model servers - #4180

Merged
ananthsub merged 1 commit into
NVIDIA-NeMo:mainfrom
ananthsub:ananthsub/opencode-reasoning-content
Oct 7, 2026
Merged

ananthsub merged 1 commit into
NVIDIA-NeMo:mainfrom
ananthsub:ananthsub/opencode-reasoning-content

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

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: #4046 makes the same change, using setdefault so a user's own interleaved setting wins, as part of a larger conformance change stacked on #4045. This PR fixes the bug on its own so it can land first. #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

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification. N/A: the README doesn't describe the interleaved setting.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header. N/A: no new files.
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

@ananthsub ananthsub added bug Something isn't working area:agent Agent harnesses and Responses API agent behavior complexity:low Localized change in one scope with a small, straightforward review surface labels Oct 7, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 7, 2026 16:52
@ananthsub
ananthsub requested a review from lafrancef October 7, 2026 16:52
…vers

The generated OpenCode provider entry set interleaved.field to "reasoning",
so OpenCode replayed earlier assistant turns with a `reasoning` key. Gym's
Chat Completions request schema only accepts `reasoning_content` on assistant
messages, so the first request after any tool call failed with a 422 and the
rollout ended early while `gym eval run` still exited 0.

Use `reasoning_content`, which Gym model servers emit and accept.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/opencode-reasoning-content branch from ee1c8c3 to d23be51 Compare October 7, 2026 19:02
@copy-pr-bot

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

@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test d23be51

@ananthsub ananthsub added the r0.7.0 Auto-cherrypick to release branch. Apply before merge; cherrypick happens after merge. label Oct 7, 2026
@ananthsub
ananthsub enabled auto-merge October 7, 2026 19:27
@ananthsub
ananthsub added this pull request to the merge queue Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/37674855142

@yaoyu-33 yaoyu-33 added the ready-to-merge PR is approved, current, and waiting for final CI or merge label Oct 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 7, 2026
@ananthsub
ananthsub added this pull request to the merge queue Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/37676702195

Merged via the queue into NVIDIA-NeMo:main with commit d64ae96 Oct 7, 2026
37 checks passed
@ananthsub
ananthsub deleted the ananthsub/opencode-reasoning-content branch October 7, 2026 20:03
ananthsub added a commit that referenced this pull request Oct 7, 2026
…l servers (4180)` into `r0.7.0` (#4191)

beep boop [🤖]: Hi @ananthsub 👋,

    we've cherry picked #4180 into `r0.7.0` for you! 🚀

    Please review and approve this cherry pick by your convenience!

Signed-off-by: Ananth Subramaniam <[email protected]>
Signed-off-by: NeMo Bot <[email protected]>
Co-authored-by: Ananth Subramaniam <[email protected]>
DanialTaheri added a commit to DanialTaheri/Gym that referenced this pull request Oct 29, 2026
… the policy

OpenCode's interleaved-reasoning config sends each assistant turn's reasoning
back in a "reasoning" key. The policy server's chat-completions request model
now forbids unknown message keys (extra="forbid"), so every multi-turn
track_token_ids request after the first failed with 422 and OpenCode exited.
The re-attached token bundle already carries that turn's tokens.

OpenCode now replays reasoning as reasoning_content by default (Gym NVIDIA-NeMo#4180), which the
request model accepts; it is dropped too, so the proxied request renders as before.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: smohsenitahe <[email protected]>
DanialTaheri added a commit to DanialTaheri/Gym that referenced this pull request Oct 30, 2026
… the policy

OpenCode's interleaved-reasoning config sends each assistant turn's reasoning
back in a "reasoning" key. The policy server's chat-completions request model
now forbids unknown message keys (extra="forbid"), so every multi-turn
track_token_ids request after the first failed with 422 and OpenCode exited.
The re-attached token bundle already carries that turn's tokens.

OpenCode now replays reasoning as reasoning_content by default (Gym NVIDIA-NeMo#4180), which the
request model accepts; it is dropped too, so the proxied request renders as before.

Signed-off-by: smohsenitahe <[email protected]>

This branch was previously deployed

1 inactive deployment
public — d23be514 Deployed Oct 7, 2026 by copy-pr-bot[bot] via release / finalize / notify #4579
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 r0.7.0 Auto-cherrypick to release branch. Apply before merge; cherrypick happens after merge. ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants