Skip to content

fix(parsers): tools are leaking in the reasoning content (deepseek) - #32539

Closed
slivanovich wants to merge 8 commits into
sgl-project:mainfrom
slivanovich:dsml-problem
Closed

fix(parsers): tools are leaking in the reasoning content (deepseek)#32539
slivanovich wants to merge 8 commits into
sgl-project:mainfrom
slivanovich:dsml-problem

Conversation

@slivanovich

@slivanovich slivanovich commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Motivation

DeepSeek V4 can start emitting DSML tool-call markup before closing an open <think> block. When that happens, the reasoning parser should stop treating subsequent text as reasoning; otherwise DSML tool-call markup may be counted or streamed as reasoning content.

This PR makes DeepSeek V4 DSML tool section markers explicit reasoning exit points.

Modifications

Python - python/sglang/srt/parser/reasoning_parser.py

  • Added DeepSeekBaseDetector for DeepSeek reasoning parsing behavior with optional tool-start markers.
  • Moved streaming DSML tool-start handling out of DeepSeekV4Detector and into the DeepSeek base detector.
  • Configured DeepSeek V4 to exit reasoning on <|DSML|tool_calls> or <|DSML|invoke name=.
  • Preserved DeepSeek V4 strict-thinking excluded tokens for constrained reasoning.
  • Added streaming buffering for partial DSML tool-start prefixes split across deltas.

Python - test/registered/unit/parser/test_reasoning_parser.py

  • Added regression coverage for DeepSeek V4:
    • DSML tool section markers split across streaming deltas.
    • DSML tool section markers emitted in the same delta as <think>.
    • Split DSML invoke markers.
    • Non-tool DSML-like prefixes that should remain reasoning content.
    • </think> taking priority over DSML tool-start text already inside reasoning.

Where should the reviewer start?

  • python/sglang/srt/parser/reasoning_parser.py:901 - DeepSeekBaseDetector with reasoning parsing and optional tool-start handling.
  • python/sglang/srt/parser/reasoning_parser.py:997-1009 - Partial tool-start buffering for streaming deltas.
  • python/sglang/srt/parser/reasoning_parser.py:1025-1052 - DeepSeek V4 detector configuration with DSML tool-start markers.
  • test/registered/unit/parser/test_reasoning_parser.py:185-244 - DeepSeek V4 DSML reasoning-exit regression tests.

Related PRs

Checklist


CI States

Latest PR Test (Base): ❌ Run #31493822238
Latest PR Test (Extra): ❌ Run #31493821942

slivanovich added 2 commits July 27, 2026 17:20
Signed-off-by: slivanovich <skuralenok@172.24.29.171-spb.dhcp.yndx.net>
Signed-off-by: slivanovich <skuralenok@172.24.29.171-spb.dhcp.yndx.net>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

slivanovich added 3 commits July 27, 2026 17:33
Signed-off-by: slivanovich <skuralenok@172.24.29.171-spb.dhcp.yndx.net>
Signed-off-by: slivanovich <skuralenok@172.24.29.171-spb.dhcp.yndx.net>
Signed-off-by: slivanovich <skuralenok@172.24.29.171-spb.dhcp.yndx.net>
@slivanovich

Copy link
Copy Markdown
Contributor Author

friendly ping @JustinTong0323

@hnyls2002

Copy link
Copy Markdown
Collaborator

Covered by #34458 (5899674). DeepSeekV4Detector now passes tool_start_token, so a DSML block that follows reasoning without a </think> is routed to normal_text and reaches the tool-call detector instead of staying in reasoning_content.

The merged version does this by passing the argument rather than introducing a shared base class, but the behaviour this PR reported is fixed.

You are credited as a co-author on that commit.

If I misread what this PR does and part of it is still missing, please rebase on main and reopen — happy to take it.

@hnyls2002 hnyls2002 closed this Aug 12, 2026
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.

2 participants