Setup: keep the dashboard's reasoning setting across an update

cmd_setup rebuilds config.json from the plan, and the reasoning setting isn't
part of the plan -- the dashboard writes it into the same file. So every
`llmhost update` (setup --yes under the hood) silently put every model back to
"Model default", losing a setting the user had chosen in the UI.

Carry it over, minus models that no longer fit. The helper exists so the reason
is on the record rather than implied by a dict literal; its tests cover the
empty and no-longer-fits cases that must not write the key at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Neil Bantoc 2026-11-03 15:01:12 -08:00
parent 8879db44a0
commit e48517b1cf
2 changed files with 29 additions and 0 deletions

View file

@ -111,6 +111,15 @@ def cmd_plan(a):
say("\nNothing fits. " + (p.get("reason") or "")) say("\nNothing fits. " + (p.get("reason") or ""))
def carried_settings(old, names):
"""Settings setup must not reset. The plan is setup's to rebuild, but the reasoning
setting belongs to the dashboard, which writes it into the same file -- without this an
`llmhost update` would quietly put every model back to "Model default". Models that no
longer fit lose their setting along with their plan."""
kept = {k: v for k, v in (old.get("reasoning") or {}).items() if k in names}
return {"reasoning": kept} if kept else {}
def cmd_setup(a): def cmd_setup(a):
info = hw.detect() info = hw.detect()
cat = paths.load_catalog() cat = paths.load_catalog()
@ -169,6 +178,7 @@ def cmd_setup(a):
"models": p["models"], "excluded": p["excluded"], "active": active, "models": p["models"], "excluded": p["excluded"], "active": active,
p["backend"]: {**old.get(p["backend"], {}), **backend_info}, p["backend"]: {**old.get(p["backend"], {}), **backend_info},
} }
cfg.update(carried_settings(old, names))
paths.save_config(cfg) paths.save_config(cfg)
key = paths.api_key(create=True) key = paths.api_key(create=True)

View file

@ -88,4 +88,23 @@ check("no server default -> client kwargs preserved",
check("a non-dict from the client isn't merged into", check("a non-dict from the client isn't merged into",
inject({"reasoning_effort": "low"}, {"chat_template_kwargs": "nope"}) == {"reasoning_effort": "low"}) inject({"reasoning_effort": "low"}, {"chat_template_kwargs": "nope"}) == {"reasoning_effort": "low"})
print("\n5. the setting survives a setup re-run (`llmhost update`)")
from llmhost import cli
NAMES = ["qwen3.8-27b", "ornith-1.5-9b"]
check("a set choice is carried over",
cli.carried_settings({"reasoning": {"qwen3.8-27b": "xhigh"}}, NAMES)
== {"reasoning": {"qwen3.8-27b": "xhigh"}})
check("every model's choice is kept, not just the active one",
cli.carried_settings({"reasoning": {"qwen3.8-27b": "xhigh", "ornith-1.5-9b": "off"}}, NAMES)
== {"reasoning": {"qwen3.8-27b": "xhigh", "ornith-1.5-9b": "off"}})
check("a model that no longer fits is dropped",
cli.carried_settings({"reasoning": {"qwen3.8-27b": "xhigh", "gone-70b": "low"}}, NAMES)
== {"reasoning": {"qwen3.8-27b": "xhigh"}})
check("nothing set -> no key written", cli.carried_settings({}, NAMES) == {})
check("empty setting -> no key written", cli.carried_settings({"reasoning": {}}, NAMES) == {})
check("no model still fits -> no key written",
cli.carried_settings({"reasoning": {"gone-70b": "low"}}, NAMES) == {})
check("setup's own keys are not touched",
set(cli.carried_settings({"reasoning": {"qwen3.8-27b": "low"}}, NAMES)) == {"reasoning"})
check.done(ROOT) check.done(ROOT)