Skip to content

fix(rollouts): build turns from Anthropic Messages model calls - #5547

Merged
gwarmstrong merged 2 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/rollouts-messages-turns
Nov 5, 2026
Merged

gwarmstrong merged 2 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/rollouts-messages-turns

Conversation

@gwarmstrong

@gwarmstrong gwarmstrong commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

_turn_content in nemo_gym/rollouts/trajectory_builder.py now reads Anthropic Messages calls, the third dialect the Model Server captures (/v1/messages). For a captured Messages response it splits the content blocks: thinking and redacted_thinking blocks become the turn's reasoning, the other blocks its answer, and tool_use blocks its tool calls. Responses and chat-completions handling is unchanged.

Why. claude_code_agent calls the Gym Model Server through /v1/messages, and model-call capture records those calls with dialect: "messages". The turn builder (added in #3721, moved in #5232) parsed only Responses output items and chat-completions choices, so every turn built from a Claude Code rollout had no answer and no steps, and rollout health marked every Claude Code rollout agent_turn_hollow. Scoring was unaffected.

Part of #5552. A contained fix found while running Claude Code on HLE.

Validation

  • pytest tests/unit_tests/rollouts: 2116 passed, 5 skipped.
  • New test TestTurnsFromModelCalls::test_messages_calls_split_the_content_blocks_and_their_thinking fails without the change.
  • Review fix (c1ae64e): rollout health counts a Messages turn's nonempty thinking (thinking or signature) and redacted_thinking (data) blocks as turn content, through a helper used only for turn reasoning, so the length-limit check still treats thinking as no answer. test_a_messages_turn_with_only_thinking_is_not_hollow builds the turn from a captured Messages call and runs health: thinking-only turns are not hollow, empty ones stay hollow, text and tool_use are unchanged; its three thinking cases fail without the fix. The runaway-generation test gains redacted-thinking, signature-only and chat-thinking-part cases, all still flagged.
  • pre-commit run --all-files: clean.

Rollouts

Internal HLE runs: Nemotron 3.5 Super served by vLLM, 5 text tasks, claude_code_agent (CLI 2.1.108) in an OpenSandbox sandbox it creates, on a Gym fork that carries this change plus the session-harness follow-ups.

Compatibility and benchmark impact

Turn records for Messages calls now carry their content. No config, API, or score change.

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.
  • Documentation added or updated, or N/A with justification. N/A: no setting or documented behavior changes; turn records gain content they were missing.
  • Pre-commit checks pass locally (pre-commit run --all-files).
  • New source files include the required Apache-2.0 SPDX header. N/A: no new source files.
  • All commits have DCO sign-off (git commit -s).

The Model Server captures Anthropic Messages calls, which Claude Code
makes, but turns rebuilt from captured calls read only Responses output
and chat-completions messages. Every Claude Code turn came out with no
answer, reasoning or tool calls, so rollout health marked each rollout
unhealthy (agent_turn_hollow) although its response was complete. Split
a Messages response's content blocks the same way: thinking blocks are
the reasoning, the rest the answer, and tool_use blocks the tool calls.

Signed-off-by: gwarmstrong <[email protected]>
@copy-pr-bot

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

@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test d69d23c

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

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.

SHIP WITH CARE

One RISK remains: Messages turns containing only thinking are still reported as hollow. The parser now retains their reasoning, but the health check doesn't recognize its fields. This is a remaining case in the intended fix, not a newly introduced scoring regression.

I reviewed both changed files and traced the capture, turn construction, health, serialization, and export paths. I didn't execute tests in this read-only review.


Inline comments (escaped v1):

  • nemo_gym/rollouts/health/checks.py line 150: RISK — Recognize Messages reasoning in hollow-turn checks

    Could you update _nonempty for the raw reasoning blocks returned by the new Messages branch? A root invocation referencing a status-200 call with response {"type":"message","content":[{"type":"thinking","thinking":"inspect first","signature":""}],"stop_reason":"end_turn"} now gets answer=[] and populated reasoning_content. This helper ignores thinking, signature, and data, so _agent_steps still sets both content flags false and the turn receives agent_turn_hollow. The same happens with {"type":"redacted_thinking","data":"opaque"}. The converter supports both shapes. Thus reasoning-only Messages turns still make their rollouts unhealthy, unlike equivalent Responses reasoning turns.

    The invariant is that nonempty Messages reasoning counts as turn content without becoming actionable answer text. Replace this dictionary-branch opening with the following, leaving the existing generic return any(...) fallback immediately below it:

        if isinstance(value, dict):
            if value.get("type") == "thinking" and (
                _nonempty(value.get("thinking")) or _nonempty(value.get("signature"))
            ):
                return True
            if value.get("type") == "redacted_thinking" and _nonempty(value.get("data")):
                return True
    

    This preserves the captured blocks and all existing fallback keys; arbitrary dictionaries containing data or signature won't count as messages.

    Proposed acceptance checks:

    • Build a trajectory from one captured call owned by a root invocation, using the response above. Assert that its reasoning remains the original block and health reports no agent_turn_hollow. Repeat with redacted thinking and with empty thinking plus a nonempty signature.
    • Empty content, empty thinking with an empty signature, and empty redacted data must remain hollow. Nonempty text and tool_use answers must remain non-hollow.
    • Retain has_message=True, has_tool_calls=True, and no hollow finding in the existing Responses reasoning/function-call test.
    • Retain the separate runaway-generation assertions: a length-limited reasoning-only call is flagged, while a call with text or a tool call isn't. Recognizing reasoning as turn content must not make it actionable output.

    I traced this suggestion through those branches but couldn't execute it; please verify it before adopting it.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@giuliolovisotto giuliolovisotto left a comment

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.

Confirming the existing hollow-turn finding at d69d23c: a helper-level probe of the added Messages branch and _nonempty retains thinking / redacted_thinking but reports no message content for either.

Please recognize these typed reasoning blocks in health and add trajectory-to-health regressions: nonempty reasoning is not hollow, genuinely empty blocks remain hollow, and reasoning alone does not become an actionable answer or suppress the length-limit check. This completes the intended health fix; no end-to-end rollout was run for this review.

— @codex

A turn built from a Messages call that returned only thinking kept its
blocks as reasoning, but rollout health still reported it hollow: the
check reads text, summary and encrypted content, not a thinking block's
thinking or signature or a redacted block's data. Turn reasoning now
counts those. The answer check that decides whether a length-limited call
gave the agent anything to act on is unchanged, so thinking still never
counts as an answer there.

Signed-off-by: gwarmstrong <[email protected]>
@gwarmstrong

Copy link
Copy Markdown
Contributor Author

Thanks to both of you. Fixed in c1ae64e.

A turn's reasoning now counts as content when it holds a nonempty thinking block (its thinking or signature) or a nonempty redacted_thinking block (its data), so a Messages turn with only thinking is no longer agent_turn_hollow. I put this in a separate _reasoning_nonempty used only for a turn's reasoning_content, rather than in _nonempty as the bot suggested. _nonempty also feeds _response_has_usable_output, the length-limit check's "anything to act on" test, and with the change there a chat message whose content is a part typed thinking would count as an answer and stop being flagged as a runaway generation. The new chat_thinking_part case in the runaway test fails with the global change and passes with this one.

Tests in tests/unit_tests/rollouts/test_rollout_health.py:

  • test_a_messages_turn_with_only_thinking_is_not_hollow builds the turn with _turns_from_model_calls from one captured Messages call owned by the root invocation, checks the turn keeps the blocks as reasoning and not as answer, then runs health. Thinking, redacted thinking and empty thinking with a signature are not hollow; text and tool_use are not hollow; empty content, empty thinking with an empty signature and empty redacted data stay hollow. With the fix reverted, the three thinking cases fail.
  • The runaway-generation test gains redacted-thinking, signature-only and chat-thinking-part cases, all still flagged; the actionable cases and the Responses reasoning/function-call test are unchanged.

tests/unit_tests/rollouts: 2116 passed, 5 skipped. pre-commit is clean on the changed files.

@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test c1ae64e

@giuliolovisotto giuliolovisotto left a comment

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.

Rechecked c1ae64e: the scoped _reasoning_nonempty helper addresses my finding while preserving the distinction between retained reasoning and actionable output. The added trajectory-to-health and runaway-generation cases cover the requested regressions. No remaining concern from my previous review.

Nine helper-level cases passed against this exact head. I could not rerun pytest because the available environment lacks it; no live rollout was run.

— @codex

@giuliolovisotto giuliolovisotto left a comment

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.

Approved following the re-review of c1ae64e; the reasoning-only health finding is addressed.

@gwarmstrong
gwarmstrong added this pull request to the merge queue Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

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

Merged via the queue into NVIDIA-NeMo:main with commit 0d0e8e7 Nov 5, 2026
61 of 64 checks passed
@gwarmstrong
gwarmstrong deleted the georgea/rollouts-messages-turns branch November 5, 2026 17:09

This branch was previously deployed

1 inactive deployment
public — c1ae64ea Deployed Nov 4, 2026 by copy-pr-bot[bot] via release / finalize / notify #10058
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants