Repository navigation
fix(opencode): replay reasoning as reasoning_content on Gym model servers - #4180
Merged
ananthsub merged 1 commit intoOct 7, 2026
Merged
Conversation
yaoyu-33
approved these changes
Oct 7, 2026
…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
force-pushed
the
ananthsub/opencode-reasoning-content
branch
from
October 7, 2026 19:02
ee1c8c3 to
d23be51
Compare
Contributor
Author
|
/ok to test d23be51 |
ananthsub
enabled auto-merge
October 7, 2026 19:27
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/37674855142 |
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 7, 2026
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/37676702195 |
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
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.
What does this PR do?
When
opencode_agentruns through a Gym model server (model_serverset), the OpenCode config it generates setsinterleaved.fieldtoreasoning. OpenCode then sends earlier assistant turns back with areasoningkey. Gym's Chat Completions request schema acceptsreasoning_contenton assistant messages, notreasoning, so the first request after any tool call fails with a 422 (extra_forbiddenatbody.messages[i]...reasoning).The rollout ends at that point, but
gym eval runstill 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_agentdoesn't setinterleavedand 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
setdefaultso a user's owninterleavedsetting 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
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 againstNeMoGymChatCompletionCreateParamsNonStreaming. Without the fix it fails with the sameextra_forbiddenerror.pytest responses_api_agents/opencode_agent/testsin 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, withmodel_serverpointing atpolicy_modeland model-call capture enabled. Status codes come from the capture store.eccn-gpt-oss-20beccn-gpt-oss-20bbashcall, 3 taskseccn-nemotron-3-nano-30b-a3bbashcall, 3 taskseccn-nemotron-3-nano-30b-a3bWith 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
interleavedsetting.pre-commit run --all-files) (so CI lint/format checks pass).git commit -s) (so the DCO check passes).