Repository navigation
fix(rollouts): build turns from Anthropic Messages model calls - #5547
Conversation
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]>
|
/ok to test d69d23c |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
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.pyline 150: RISK — Recognize Messages reasoning in hollow-turn checksCould you update
_nonemptyfor 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 getsanswer=[]and populatedreasoning_content. This helper ignoresthinking,signature, anddata, so_agent_stepsstill sets both content flags false and the turn receivesagent_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 TrueThis preserves the captured blocks and all existing fallback keys; arbitrary dictionaries containing
dataorsignaturewon'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_useanswers 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.
- 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
Review generated by codex. This was a full review. Request a full review with /review reset=true.
giuliolovisotto
left a comment
There was a problem hiding this comment.
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]>
|
Thanks to both of you. Fixed in c1ae64e. A turn's reasoning now counts as content when it holds a nonempty Tests in
|
|
/ok to test c1ae64e |
giuliolovisotto
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Approved following the re-review of c1ae64e; the reasoning-only health finding is addressed.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42065779585 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42068711904 |
What does this PR do?
_turn_contentinnemo_gym/rollouts/trajectory_builder.pynow reads Anthropic Messages calls, the third dialect the Model Server captures (/v1/messages). For a captured Messages response it splits the content blocks:thinkingandredacted_thinkingblocks become the turn's reasoning, the other blocks its answer, andtool_useblocks its tool calls. Responses and chat-completions handling is unchanged.Why.
claude_code_agentcalls the Gym Model Server through/v1/messages, and model-call capture records those calls withdialect: "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 rolloutagent_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.TestTurnsFromModelCalls::test_messages_calls_split_the_content_blocks_and_their_thinkingfails without the change.thinking(thinking or signature) andredacted_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_hollowbuilds the turn from a captured Messages call and runs health: thinking-only turns are not hollow, empty ones stay hollow, text andtool_useare 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.agent_turn_hollow.Compatibility and benchmark impact
Turn records for Messages calls now carry their content. No config, API, or score change.
Checklist
pre-commit run --all-files).git commit -s).