fix: Add parity in behavior and tests with vllm nemotron_v3 for tools parser - #9058
Conversation
Signed-off-by: Indrajit Bhosale <iamindrajitb@gmail.com>
WalkthroughThe PR adds support for disabling reasoning extraction in vLLM Nemotron v3 responses when specific chat template arguments are set. It introduces a new parser alias ( ChangesNemotron v3 Reasoning Disabling
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip 💬 Introducing Slack Agent: Turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 👉 Get your free trial and get 200 agent minutes per Slack user (a $50 value). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/llm/src/preprocessor.rs`:
- Around line 1494-1524: The stream-end path currently discards any bytes left
in state.buffer (so a partial think prefix like "<thi" is lost); update the
branch that returns None at stream completion to check state.buffer and, if
non-empty, emit it as normal content instead of dropping it — e.g. construct an
output string from state.buffer (taking into account stripping think_start_token
if appropriate, using state.think_start_token and the same logic used earlier)
and set choice.delta.content = Some(ChatCompletionMessageContent::Text(...))
before returning the processed_response/state; ensure state.buffer is cleared
afterwards and that existing fields (state.decided, choice.delta.content) are
handled consistently with the other branch.
- Around line 1457-1516: The current strip_leading_reasoning_start_from_stream
uses a single StripReasoningStartState with shared buffer and decided fields,
which incorrectly mixes state across multiple choices in a single streamed
response; update StripReasoningStartState to track per-choice state keyed by
choice.index (e.g., a HashMap<usize, (buffer: String, decided: bool)>), and then
in the processing closure use the choice.index to lookup/create the per-choice
buffer/decided pair, operate on that pair when accumulating/checking
think_start_token, write back the possibly-trimmed output into
choice.delta.content, and remove the per-choice entry when you know the choice
is finished to avoid unbounded growth. Ensure you reference
strip_leading_reasoning_start_from_stream, StripReasoningStartState,
choice.index, state.buffer and state.decided in your changes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0a851996-4dea-498b-9735-dd507f91f757
📒 Files selected for processing (4)
docs/agents/reasoning.mdlib/llm/src/preprocessor.rslib/llm/tests/postprocessor_parsing_stream.rslib/parsers/src/reasoning/mod.rs
Signed-off-by: Indrajit Bhosale <iamindrajitb@gmail.com>
Signed-off-by: Indrajit Bhosale <iamindrajitb@gmail.com>
Signed-off-by: Indrajit Bhosale <iamindrajitb@gmail.com>
Signed-off-by: Indrajit Bhosale <iamindrajitb@gmail.com>
Signed-off-by: Indrajit Bhosale <iamindrajitb@gmail.com>
Signed-off-by: Indrajit Bhosale <iamindrajitb@gmail.com>
Signed-off-by: Indrajit Bhosale <iamindrajitb@gmail.com>
keivenchang
left a comment
There was a problem hiding this comment.
thanks Indrajit — helper extraction, new PRE.6 doc, and the PARSER_CASES rename all landed cleanly. ship it.
Merge with main pulls in #9058's `choice.stop_reason = None;` against #8119's `ChatChoiceStream` (which no longer has that field). Path- filtered CI on main's next commit (#9230, sglang-only) skipped rust- clippy so the broken combination landed silently — exposed here by the merge. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Merge with main pulls in #9058's `choice.stop_reason = None;` against #8119's `ChatChoiceStream` (which no longer has that field). Path- filtered CI on main's next commit (#9230, sglang-only) skipped rust- clippy so the broken combination landed silently — exposed here by the merge. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Overview:
Port vLLM Nemotron v3 reasoning parser coverage into Dynamo and align Dynamo’s parser naming/disabled-thinking behavior with the vLLM contract.
Why:
vLLM added Nemotron v3 reasoning parser with tests.
Dynamo has a separate Rust implementation of reasoning parsing, so this PR adds matching coverage to make the expected Nemotron v3 behavior explicit and trackable.
vLLM source test file:
https://github.com/vllm-project/vllm/blob/main/tests/reasoning/test_nemotron_v3_reasoning_parser.py
Missing relevant vLLM test cases:
test_nemotron_v3_reasoningwithout_start_tokenwithout_start_token_streamingwith_start_tokenwith_start_token_streamingtest_nemotron_v3_without_thinking_returns_contenttest_nemotron_v3_force_nonempty_content_returns_contentDetails:
Added nemotron_v3 as a reasoning parser alias for the existing force-reasoning ... parser.
Added direct vLLM parity tests for Nemotron v3 reasoning extraction:
Added postprocessor coverage for vLLM request-flag behavior:
Documented nemotron_v3 as the vLLM-compatible alias.
Newly added vLLM-to-Dynamo test mapping:
without_start_tokentest_nemotron_v3_detect_and_parse_vllm_caseswith_start_tokentest_nemotron_v3_detect_and_parse_vllm_caseswithout_start_token_streamingtest_nemotron_v3_streaming_vllm_caseswith_start_token_streamingtest_nemotron_v3_streaming_vllm_casestest_nemotron_v3_without_thinking_returns_contentpostprocessor_parsing_stream_nemotron_v3_enable_thinking_false_returns_contenttest_nemotron_v3_force_nonempty_content_returns_contentpostprocessor_parsing_stream_nemotron_v3_force_nonempty_strips_start_tokenAdditional Dynamo-only regression coverage:
<think>strip state independent per streamed choicepostprocessor_parsing_stream_nemotron_v3_force_nonempty_tracks_prefix_per_choiceWhere should the reviewer start?
lib/parsers/src/reasoning/mod.rslib/llm/src/preprocessor.rsnemotron_v3<think>stripping when reasoning is disabledlib/llm/tests/postprocessor_parsing_stream.rsenable_thinking=falseandforce_nonempty_content=truedocs/agents/reasoning.mdSummary by CodeRabbit
New Features
nemotron_v3as an alternative name for Nemotron reasoning parsersDocumentation