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

@ -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