[Bugfix] Guard missing end_token substring in streaming reasoning parsers - #53303
[Bugfix] Guard missing end_token substring in streaming reasoning parsers#53303arnavahire19 wants to merge 1 commit into
Conversation
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in PRs do not trigger a full CI run by default. Reviewers with write access and configured trusted contributors can comment Once the PR is approved or has the If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. Agent GuidelinesIMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban. 🚀 |
Motivation
In
BaseThinkingReasoningParserandDeepSeekR1ReasoningParser, whenend_token_idis present indelta_token_ids,delta_text.find(self.end_token)is called to split reasoning and content text.If
self.end_tokenliteral string is not present indelta_text(e.g. during multi-token deltas where the special token is detokenized as empty or formatted separately),find()returns-1. Previously, slicingdelta_text[:end_index]evaluated todelta_text[:-1], silently clipping the last character off the reasoning buffer and slicing intocontent.Proposed Changes
if end_index != -1:before slicingdelta_textinBaseThinkingReasoningParserandDeepSeekR1ReasoningParser.end_index == -1, safely keepsreasoning = delta_textwithout character truncation.test_end_token_id_without_literal_substringintests/reasoning/test_base_thinking_reasoning_parser.pycovering multi-token delta handling.