Fix reasoning_effort tier mapping and context-gate misreading
Follows up on #635 (@kernelzeroday, @zom-2018) and #653 (@rell666) — this is the patch discussed there, posted as a comment first (https://github.com/antirez/ds4/issues/635#issuecomment-5192049609) and opened as a PR per @darkbasic's question.
Two independent bugs, same two functions
-
DS4_THINK_HIGHnever rendered a prefix at all. OnlyDS4_THINK_MAXdid, using text that is actually the official "high" tier prefix perdeepseek-ai/DeepSeek-V4-Flash-0731'sencoding/README.md(verified verbatim against the primary source). Everyreasoning_effortother than"max"silently rendered as official "low". The real"max"prefix ("Beyond maximum — exhaustive, relentless, and uncompromising...", note the em dash U+2014) was absent from the codebase entirely — unreachable via the API regardless of setting. Fixed in both independent prompt-rendering paths that had this bug:ds4.c'schat_push_think_prefix()(CLI/engine) andds4_server.c'srender_deepseek_chat_prompt_text()(server). -
ds4_think_mode_for_context()downgraded"max"→"high"below a 384K context threshold, citing DeepSeek's guidance as an input-context requirement. The model card's actual text: "For thehighandmaxreasoning effort levels, we recommend a maximum output length of 384K tokens." That's an output-budget guideline, not a context-size precondition. Turned into a documented no-op rather than removed outright, since fourds4_server.ccall sites use it andds4_think_max_min_context()may still be useful for client-side output-length advice.
Testing
- Adds
test_render_think_high_prompt_prefix()— there was previously zero test coverage of the "high" tier ever rendering anything. - Fixes the now-incorrect context-gate assertion in
test_reasoning_effort_mapping(). - Adds a mutual-exclusivity assertion to the existing
"max"prompt test. make ds4_testpasses clean against the full existing suite plus these changes.- Smoke-tested live against a real 0731 quant:
reasoning_effort: highand: maxnow produce visibly distinct prompts;: maxno longer collapses to the "high" text below 384K context.
Requirements
- I have read and agree with the contributing guidelines.
- AI usage disclosure: YES — diagnosed and patched with Claude Code, verified against the primary source (DeepSeek's own model card) and the project's existing test suite.
Update: a real DS4_THINK_LOW tier (issue #660)
Found while looking for other reasoning_effort-related community reports to help with: issue #660 ("New 0731 iq2 thinks forever!") describes reasoning_effort: "low" producing 9k tokens of runaway reasoning.
Root cause, again verified against DeepSeek-V4's own encoding spec (encoding/README.md, "Reasoning Effort" section): it defines exactly three levels — "low" (the default, prompt prefix "none"), "high", and "max". DS4's parse_reasoning_effort_name() collapsed "low" (and "medium"/"minimal") into the same DS4_THINK_HIGH enum value as an explicit "high" request — the code even had a comment acknowledging this: "DS4 only exposes HIGH and MAX above zero, so minimal collapses to the smallest non-zero level (HIGH)." So a client asking for "low" got the most elaborate non-max prompt DS4 has, instead of the model's own default behavior with no extra prompting — a very plausible direct cause of runaway reasoning on tasks that don't need it.
Added DS4_THINK_LOW as a genuine fourth ds4_think_mode value ("thinking enabled, no prompt prefix", distinct from DS4_THINK_NONE which disables thinking entirely) and wired it through every switch/branch over the enum. The default reasoning_effort when a client sends none at all is untouched (still high); this only fixes what an explicit "low"/"minimal" request does.
Tested the same way as the rest of this PR: full suite passes, new regression test (test_render_think_low_prompt_prefix) plus updated test_reasoning_effort_mapping, and a live A/B on the production Flash quant confirming reasoning_effort: "low" and "high" now produce genuinely different reasoning_content (they were byte-identical prompts before this fix).