[Bugfix] Fix reasoning dropped on streaming boundary deltas (#42691)

Signed-off-by: sfeng33 <4florafeng@gmail.com>
This commit is contained in:
Flora Feng
2026-05-23 16:18:30 -07:00
committed by GitHub
parent 10d264a2b9
commit b32fe416ea
2 changed files with 95 additions and 7 deletions
+23 -7
View File
@@ -634,6 +634,13 @@ class DelegatingParser(Parser):
return False
return self._reasoning_parser.is_reasoning_end(input_ids)
def is_reasoning_end_streaming(
self, input_ids: list[int], delta_ids: list[int]
) -> bool:
if self._reasoning_parser is None:
return False
return self._reasoning_parser.is_reasoning_end_streaming(input_ids, delta_ids)
def extract_content_ids(self, input_ids: list[int]) -> list[int]:
if self._reasoning_parser is None:
return input_ids
@@ -679,15 +686,16 @@ class DelegatingParser(Parser):
current_token_ids=current_token_ids,
delta_token_ids=delta_token_ids,
)
# Hand off remaining content to tool parser
if self._tool_parser and self.is_reasoning_end(delta_token_ids):
if self.is_reasoning_end_streaming(current_token_ids, delta_token_ids):
state.reasoning_ended = True
current_token_ids = self.extract_content_ids(delta_token_ids)
if delta_message and delta_message.content:
current_text = delta_message.content
delta_message.content = None
else:
current_text = ""
current_text = (
delta_message.content
if delta_message and delta_message.content
else ""
)
delta_text = current_text
delta_token_ids = current_token_ids
# Tool call extraction
if self._in_tool_call_phase(state):
@@ -698,6 +706,9 @@ class DelegatingParser(Parser):
delta_text = current_text
delta_token_ids = current_token_ids
# A boundary delta may carry both reasoning and tool call,
# save it before the tool parser overwrites delta_message.
reasoning = delta_message.reasoning if delta_message else None
delta_message, state.function_name_returned = (
self._extract_tool_calls_streaming(
previous_text=state.previous_text,
@@ -712,6 +723,11 @@ class DelegatingParser(Parser):
function_name_returned=state.function_name_returned,
)
)
if reasoning:
if not delta_message:
delta_message = DeltaMessage()
delta_message.reasoning = reasoning
if (
delta_message
and delta_message.tool_calls