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

@ -309,18 +309,22 @@ check("model is <provider>/<an entry in the block>",
snip["model"].partition("/")[0] == prov_id and snip["model"].partition("/")[2] in block["models"],
(snip["model"], list(block["models"])))
check.section("24. the block offers only the effort levels the loaded model accepts")
check("qwen3.8: hide high, add xhigh",
opencode.effort_variants(("low", "medium", "xhigh")) == {"high": {"disabled": True},
"xhigh": {"reasoningEffort": "xhigh"}},
opencode.effort_variants(("low", "medium", "xhigh")))
check("no levels: hide opencode's whole menu",
opencode.effort_variants(()) == {l: {"disabled": True} for l in ("low", "medium", "high")})
check.section("24. the block never offers a reasoning chooser of its own")
check("opencode's whole menu is switched off",
opencode.effort_variants() == {l: {"disabled": True} for l in ("low", "medium", "high")},
opencode.effort_variants())
q = opencode.provider_block(dict(CFG, active="qwen3.8-27b"), "popos.local", "k", "popos.local")
ent = q["models"]["default"]
check("qwen3.8 block (not downloaded: catalog levels)",
ent.get("variants") == {"high": {"disabled": True}, "xhigh": {"reasoningEffort": "xhigh"}}, ent)
check("a reasoning model is marked as one (so thinking blocks render)", ent.get("reasoning") is True, ent)
check("but every effort level is disabled",
ent.get("variants") == {l: {"disabled": True} for l in ("low", "medium", "high")}, ent)
check("no variant carries a reasoningEffort to send",
not any("reasoningEffort" in v for v in ent["variants"].values()), ent["variants"])
check("the model levels from the catalog are not offered either",
not ({"xhigh"} & set(ent["variants"])), ent["variants"])
nr = opencode.provider_block(dict(CFG, active="qwen3-coder"), "popos.local", "k", "popos.local")
check("a non-reasoning model gets no variants", "variants" not in nr["models"]["default"], nr["models"]["default"])
check("one entry only, named for the alias, so the client can't pick a model either",
list(q["models"]) == [plan.SERVED_ALIAS], list(q["models"]))
check.done(ROOT)

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()

View file

@ -63,30 +63,18 @@ else:
check("no other catalog model claims levels",
[m for m in cat.values() if m.get("effort") and m["name"] != "qwen3.8-27b"] == [])
print("\n4. a client's own kwargs win over the server default")
def inject(server_kw, client_body):
"""The precedence rule from the proxy, which mirrors mlx_lm's own."""
if not server_kw:
return client_body.get("chat_template_kwargs")
mine = dict(server_kw)
theirs = client_body.get("chat_template_kwargs")
if isinstance(theirs, dict):
mine.update(theirs)
return mine
check("server default applied when client says nothing",
inject({"reasoning_effort": "low"}, {}) == {"reasoning_effort": "low"})
check("client overrides the same key",
inject({"reasoning_effort": "low"}, {"chat_template_kwargs": {"reasoning_effort": "xhigh"}})
== {"reasoning_effort": "xhigh"})
check("client's other keys survive alongside",
inject({"reasoning_effort": "low"}, {"chat_template_kwargs": {"enable_thinking": False}})
== {"reasoning_effort": "low", "enable_thinking": False})
check("no server default -> body untouched", inject({}, {}) is None)
check("no server default -> client kwargs preserved",
inject({}, {"chat_template_kwargs": {"enable_thinking": False}}) == {"enable_thinking": False})
check("a non-dict from the client isn't merged into",
inject({"reasoning_effort": "low"}, {"chat_template_kwargs": "nope"}) == {"reasoning_effort": "low"})
print("\n4. every knob the dashboard can set is one the proxy takes away from clients")
# The proxy drops plan.REASONING_KEYS from a client's request before applying the
# dashboard's setting. If reasoning_kwargs learns a new template knob and this list
# doesn't, a client could set that knob itself -- so the two must stay in step.
produced = set()
for entry, controls in ((QWEN, BOTH), (ORNITH, THINK), (QWEN, THINK)):
for value, _ in plan.reasoning_options(entry, None, controls):
produced |= set(plan.reasoning_kwargs(value, entry, controls))
check("the dashboard's knobs are exactly the ones taken from clients",
produced == set(plan.REASONING_KEYS), (sorted(produced), plan.REASONING_KEYS))
check("both knobs are covered", set(plan.REASONING_KEYS) == {"enable_thinking", "reasoning_effort"},
plan.REASONING_KEYS)
print("\n5. the setting survives a setup re-run (`llmhost update`)")
from llmhost import cli