Reasoning effort is the dashboard's to set, not the client's

One model is loaded at a time under one setting, and that setting belongs next
to the model it applies to -- the same reason the client can't switch models.
So the proxy now takes a client's reasoning settings off the request before
applying the dashboard's: a top-level reasoning_effort, and enable_thinking or
reasoning_effort inside chat_template_kwargs. Other template kwargs, which
llm-host has no opinion about, still pass through.

This reverses the precedence the proxy had (a client's own kwargs won, mirroring
mlx_lm's own rule), which was the wrong model for a single-model server: clients
offer a generic menu -- opencode's low/medium/high -- and a level the template
doesn't define makes it raise, so every request failed with nothing on the
user's screen to explain it.

- opencode: the provider block disables all three of opencode's effort levels
  instead of curating them. A chooser there would be a menu that does nothing.
- Deletes the nearest-effort mapping (EFFORT_SCALE, nearest_effort,
  plan.effort_levels, the effort_levels= parameter through both backends): it
  existed only to rescue a client-supplied level, and none survives now.
- plan.REASONING_KEYS names the knobs this server drives, with a test asserting
  it stays exactly equal to what reasoning_kwargs can emit -- so a new template
  knob can't be added without also taking it away from clients.
- Two strings that still described a menu of models, from before the block held
  a single entry.

Verified against the live MLX server: with the dashboard on xhigh, five request
shapes (nothing, enable_thinking: false, effort low top-level, effort low in
kwargs, and the off-scale "turbo" that used to 404) all answer identically, and
the reply tracks the dashboard alone as it moves off / low / xhigh.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Neil Bantoc 2026-11-03 15:01:26 -08:00
parent e48517b1cf
commit e24c0b7712
10 changed files with 134 additions and 151 deletions

View file

@ -147,7 +147,6 @@ vstats = proxy.Stats()
vstats.ready = True
serve(proxy.make_handler(INNER, "qwen3.8-27b", 262144, KEY, vstats, aliases=("Qwen/Qwen3.8-27B-FP8",),
upstream_model="qwen3.8-27b", upstream_key="sk-inner",
effort_levels=("low", "medium", "xhigh"),
reasoning=lambda: {"reasoning_effort": "low"}), VOUTER)
seen.clear(); auths.clear()
check("alias accepted", post(plan.SERVED_ALIAS, port=VOUTER)[0] == 200)
@ -155,31 +154,53 @@ check("forwarded under vLLM's served name", seen[-1].get("model") == "qwen3.8-27
check("inner key sent, not the client's", auths[-1] == "Bearer sk-inner", auths[-1])
check("other models still refused", post("ornith-1.5-9b", port=VOUTER)[0] == 404)
check.section("10. effort levels the model lacks are mapped to the nearest it has")
for asked, sent in (("high", "xhigh"), ("medium", "medium"), ("xhigh", "xhigh"),
("minimal", "low"), ("max", "xhigh")):
seen.clear()
post(None, port=VOUTER, reasoning_effort=asked)
check(f"top-level {asked} -> {sent}", seen[-1].get("reasoning_effort") == sent, seen[-1])
seen.clear()
post(None, port=VOUTER, chat_template_kwargs={"reasoning_effort": "high"})
check("inside chat_template_kwargs too", seen[-1]["chat_template_kwargs"].get("reasoning_effort") == "xhigh",
seen[-1].get("chat_template_kwargs"))
seen.clear()
post(None, port=VOUTER, reasoning_effort="bogus")
check("an unknown word is left for the server to reject", seen[-1].get("reasoning_effort") == "bogus", seen[-1])
check.section("10. the reasoning setting is the dashboard's; a client can't set it")
seen.clear()
post(None, port=VOUTER)
check("dashboard setting applied when the client sets none",
check("dashboard setting applied when the client asks for nothing",
seen[-1].get("chat_template_kwargs") == {"reasoning_effort": "low"}, seen[-1])
seen.clear()
post(None, port=VOUTER, reasoning_effort="xhigh")
check("a client's own top-level level wins over the dashboard's",
"reasoning_effort" not in (seen[-1].get("chat_template_kwargs") or {})
and seen[-1].get("reasoning_effort") == "xhigh", seen[-1])
check("mapping only where a model has levels",
[plan.nearest_effort("high", ()), plan.nearest_effort("high", ("low", "high"))] == [None, "high"])
check("a tie goes to the higher level", plan.nearest_effort("high", ("medium", "xhigh")) == "xhigh")
check("a client's top-level reasoning_effort never reaches the model",
"reasoning_effort" not in seen[-1], seen[-1])
check("...and the dashboard's setting is what goes instead",
seen[-1].get("chat_template_kwargs") == {"reasoning_effort": "low"}, seen[-1])
seen.clear()
post(None, port=VOUTER, chat_template_kwargs={"reasoning_effort": "xhigh"})
check("nor one inside chat_template_kwargs",
seen[-1]["chat_template_kwargs"] == {"reasoning_effort": "low"}, seen[-1])
seen.clear()
post(None, port=VOUTER, chat_template_kwargs={"enable_thinking": False})
check("a client can't turn thinking off either",
"enable_thinking" not in seen[-1]["chat_template_kwargs"], seen[-1])
seen.clear()
post(None, port=VOUTER, chat_template_kwargs={"enable_thinking": False, "custom_var": 7})
check("template kwargs llm-host has no opinion about are left alone",
seen[-1]["chat_template_kwargs"] == {"custom_var": 7, "reasoning_effort": "low"}, seen[-1])
seen.clear()
post(None, port=VOUTER, chat_template_kwargs="not a dict")
check("junk in chat_template_kwargs is replaced, not merged into",
seen[-1]["chat_template_kwargs"] == {"reasoning_effort": "low"}, seen[-1])
seen.clear()
post(None, port=VOUTER, path="/v1/completions", reasoning_effort="xhigh")
check("a non-chat request is left as it came (no template, no setting)",
seen[-1].get("reasoning_effort") == "xhigh" and "chat_template_kwargs" not in seen[-1], seen[-1])
check.section("10b. with nothing set on the dashboard, the client's setting is still dropped")
NOUTER = 18234
nstats = proxy.Stats()
nstats.ready = True
serve(proxy.make_handler(INNER, "qwen3.8-27b", 262144, KEY, nstats,
upstream_model="qwen3.8-27b", reasoning=lambda: {}), NOUTER)
seen.clear()
post(None, port=NOUTER, reasoning_effort="xhigh", chat_template_kwargs={"enable_thinking": False})
check("both forms dropped", "reasoning_effort" not in seen[-1], seen[-1])
check("and no empty kwargs left behind for the template to read",
"chat_template_kwargs" not in seen[-1], seen[-1])
seen.clear()
post(None, port=NOUTER, chat_template_kwargs={"custom_var": 7})
check("an unrelated kwarg still survives on its own",
seen[-1]["chat_template_kwargs"] == {"custom_var": 7}, seen[-1])
check.section("11. a streamed run is counted from its usage chunk, and recorded")
before = vstats.snapshot()