Repository navigation
fix(server): tell SGLang when a native generate request starts inside reasoning - #327
Conversation
… 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.
|
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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughSGLang generation now detects reasoning prompts when a reasoning parser is configured. It forwards ChangesSGLang reasoning control
Suggested reviewers: Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
Summary
SGLang's native
/generateendpoint defaultsrequire_reasoningtofalse(GenerateReqInputin 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:--enable-strict-thinkingnever 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()setsrequire_reasoning: truewhen both hold: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
test_sglang_generation.pyandtest_generation_base.pypass (388 tests), and ruff check and format pass.json_schemaresponse format returned{"capital": "Paris"}after 179 completion tokens of hidden reasoning;tool_choice: "required"returned a structuredget_weathercall;generatereturnedyes.