Skip to content

fix(server): tell SGLang when a native generate request starts inside reasoning - #327

Merged
krisztian-gajdar merged 1 commit into
mainfrom
fix/sglang-native-reasoning-requests
Sep 22, 2026
Merged

krisztian-gajdar merged 1 commit into
mainfrom
fix/sglang-native-reasoning-requests

Conversation

@krisztian-gajdar

@krisztian-gajdar krisztian-gajdar commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

SGLang's native /generate endpoint defaults require_reasoning to false (GenerateReqInput in 0.5.10.post1 and 0.5.20). Its reasoning-aware grammar backend then starts every request in the answer phase (ReasonerGrammarObject.maybe_init_reasoning(False)). On a prompt that ends inside an open thinking block:

  • a JSON-schema or regex grammar constrains the thinking block instead of the answer after it;
  • --enable-strict-thinking never engages, because its token filter runs only in the thinking phase.

SGLang's OpenAI chat endpoint derives the flag from the chat template. The queued worker renders the template itself and calls /generate, so it never set the flag. Two cases lose both guarantees on the queued route: chat templates that always open a thinking block (GLM-5.3-Flash), and thinking profiles whose template seeds one.

Changes

SGLangGenerationAdapter.generate() sets require_reasoning: true when both hold:

  • it runs a reasoning parser;
  • the rendered prompt leaves that parser's reasoning block open (reasoning_starts_in_prompt, including Gemma 4's split channel marker).

The flag is set on all three request bodies: single, streaming multi-candidate and non-streaming multi-candidate. A closed or absent block, or no reasoning parser, leaves the engine default untouched.

Verification

  • New tests cover all three bodies, a closed Qwen block, an unopened block, no parser, and a seeded Gemma channel. With the flag forced off, the four positive cases fail and the negative cases still pass.
  • test_sglang_generation.py and test_generation_base.py pass (388 tests), and ruff check and format pass.
  • On eight H100s, through a local gateway, NATS, sidecar and worker, I served GLM-5.3-Flash, whose template always opens a thinking block, with this change and feat(server): parse and force GLM tool calls on the queued route #328:
    • a chat request with a json_schema response format returned {"capital": "Paris"} after 179 completion tokens of hidden reasoning;
    • tool_choice: "required" returned a structured get_weather call;
    • a regex-constrained generate returned yes.

… reasoning

SGLang's native /generate endpoint defaults require_reasoning to false. Its
reasoning-aware grammar backend then starts every request in the answer
phase, so on a prompt that ends inside an open thinking block:

- a JSON-schema or regex grammar constrains the thinking block instead of
  the answer that follows it, and
- --enable-strict-thinking never engages, because its token filter only
  runs in the thinking phase.

The engine's OpenAI chat endpoint derives the flag from the chat template.
The queued worker renders the template itself and calls /generate, so it
never set the flag. Chat templates that always open a thinking block, and
thinking profiles that seed one, therefore lost both guarantees on the
queued route.

The adapter now sets require_reasoning when it runs a reasoning parser and
the rendered prompt leaves that parser's reasoning block open, on the
single, streaming multi-candidate and non-streaming multi-candidate
bodies. The shared and CUDA 13 SGLang bundles (0.5.10.post1, 0.5.20) both
accept the field. A closed or absent block, or no reasoning parser, keeps
the engine default.
@krisztian-gajdar
krisztian-gajdar requested a review from a team as a code owner September 22, 2026 14:41
@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: b64b9713-62d1-43c1-a018-7e7afd87ad7b

📥 Commits

Reviewing files that changed from the base of the PR and between 40ae372 and ba21cce.

📒 Files selected for processing (2)
  • packages/sie_server/src/sie_server/adapters/sglang/generation.py
  • packages/sie_server/tests/adapters/test_sglang_generation.py

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

SGLang generation now detects reasoning prompts when a reasoning parser is configured. It forwards require_reasoning for streaming, non-streaming, single-candidate, and multi-candidate requests. Tests cover GLM, Qwen3, and Gemma prompt formats.

Changes

SGLang reasoning control

Layer / File(s) Summary
Reasoning detection and request propagation
packages/sie_server/src/sie_server/adapters/sglang/generation.py, packages/sie_server/tests/adapters/test_sglang_generation.py
The adapter derives require_reasoning from the configured parser and resolved prompt format. It forwards the flag in supported generation request bodies. Tests cover required, omitted, and parser-independent reasoning cases.

Suggested reviewers: huronat

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to ba21c

The adapter enables required reasoning for applicable open reasoning prompts while preserving existing behavior otherwise. The change is ready to merge with routine checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: informing SGLang when native generate requests begin inside a reasoning block.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@krisztian-gajdar
krisztian-gajdar merged commit 26702c7 into main Sep 22, 2026
21 checks passed
@krisztian-gajdar
krisztian-gajdar deleted the fix/sglang-native-reasoning-requests branch September 22, 2026 16:02
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.

1 participant