opencode: offer one model, not a menu where four of five fail

Only one model is loaded at a time, so listing every model that fits gave a
picker with one working entry and four that now answer 404 -- and the entry that
worked changed id on every `llmhost switch`, invalidating any client's saved
default.

Replace the list with a single entry, `default`, which is a name the API itself
answers to: vLLM takes it as a second --served-model-name and still reports the
real slug, being first in the list; the MLX proxy accepts it as an alias. So
`llmhost/default` survives a switch. The local entry is labelled with whatever is
loaded, refreshed by both switch paths; a remote block is pasted once and never
refreshed, so it names no model rather than make a claim that goes stale.

Existing configs point at a specific model, which this provider no longer has and
opencode would reject, so configure() and sync() migrate `<prov>/<model>` to
`<prov>/default`. Other providers' defaults are untouched, and an older remote
block that still lists many models keeps working, including as the fallback when
the local provider is removed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Neil Bantoc 2026-11-03 02:26:34 -08:00
parent 51c2880a2e
commit 9af7f1e545
6 changed files with 124 additions and 50 deletions

View file

@ -7,7 +7,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))
import harness
ROOT = harness.setup()
from llmhost import opencode, paths
from llmhost import opencode, paths, plan
harness.guard(paths, ROOT)
CFG = harness.config()
@ -36,15 +36,15 @@ check("id is llmhost", prov == "llmhost", prov)
check('name is "LLMHost (Local)"', d["provider"]["llmhost"]["name"] == "LLMHost (Local)", d["provider"]["llmhost"]["name"])
check("baseURL localhost", d["provider"]["llmhost"]["options"]["baseURL"] == "http://localhost:1134/v1")
check("apiKey -> llm-host key file", str(paths.KEY_FILE) in d["provider"]["llmhost"]["options"]["apiKey"])
check("model set", d["model"] == "llmhost/ornith-1.5-9b", d.get("model"))
check("model set to the alias", d["model"] == "llmhost/default", d.get("model"))
mods = d["provider"]["llmhost"]["models"]
check("model keyed by slug", "qwen3.8-27b" in mods, list(mods))
check("label = title + slug", mods["qwen3.8-27b"]["name"] == "Qwen3.8 27B \u00b7 qwen3.8-27b (Local)", mods["qwen3.8-27b"]["name"])
check("active model marked loaded", mods[CFG["active"]]["name"].endswith("(Local, loaded)"), mods[CFG["active"]]["name"])
check("only the active one is marked",
sum(v["name"].endswith(", loaded)") for v in mods.values()) == 1,
[v["name"] for v in mods.values()])
check("slug searchable for every model", all(k in v["name"] for k, v in mods.items()))
check("exactly one entry", list(mods) == ["default"], list(mods))
check("keyed by the API alias", list(mods) == [plan.SERVED_ALIAS])
check("label names the loaded model", mods["default"]["name"] == "Default model \u00b7 Ornith 1.5 9B (Local)", mods["default"]["name"])
check("limits come from the loaded model",
mods["default"]["limit"]["context"] == next(m["est_context"] for m in CFG["models"] if m["name"] == CFG["active"]),
mods["default"]["limit"])
check("reasoning flag from the loaded model", mods["default"].get("reasoning") is True, mods["default"])
print("\n2. local + remote side by side")
rp, rb = remote("popos.local")
@ -53,9 +53,9 @@ st, path, prov, authcl = opencode.configure(CFG)
d = load()
check("remote id is llmhost-popos", rp == "llmhost-popos", rp)
check('remote name is "LLMHost (popos.local)"', rb["name"] == "LLMHost (popos.local)", rb["name"])
check("remote model label", rb["models"]["qwen3.8-27b"]["name"] == "Qwen3.8 27B \u00b7 qwen3.8-27b (popos.local)", rb["models"]["qwen3.8-27b"]["name"])
check("remote block is NOT marked loaded", not any(", loaded)" in v["name"] for v in rb["models"].values()),
[v["name"] for v in rb["models"].values()])
check("remote has one entry too", list(rb["models"]) == ["default"], list(rb["models"]))
check("remote label names no model (it would go stale)",
rb["models"]["default"]["name"] == "Default model (popos.local)", rb["models"]["default"]["name"])
check("local added alongside", sorted(d["provider"]) == ["llmhost", "llmhost-popos"], sorted(d["provider"]))
check("remote untouched", d["provider"][rp] == rb)
check("existing model kept", d["model"] == f"{rp}/qwen3.8-27b", d["model"])
@ -70,24 +70,35 @@ check("remote block intact", d["provider"]["llmhost"] == rb2)
check("local under llmhost-local", d["provider"]["llmhost-local"]["options"]["baseURL"] == "http://localhost:1134/v1")
print("\n4. user renamed the local provider (gap 2)")
reset({"provider": {"mymac": opencode.local_block(CFG)}, "model": "mymac/ornith-1.5-9b"})
reset({"provider": {"mymac": opencode.local_block(CFG)}, "model": "mymac/default"})
st, path, prov, authcl = opencode.configure(CFG)
d = load()
check("recognised under new name", prov == "mymac", prov)
check("no duplicate added", list(d["provider"]) == ["mymac"], list(d["provider"]))
check("status unchanged", st == "unchanged", st)
check("nothing to change -> unchanged", st == "unchanged", st)
# But a stale per-model default IS a change worth making.
reset({"provider": {"mymac": opencode.local_block(CFG)}, "model": "mymac/ornith-1.5-9b"})
st, path, prov, authcl = opencode.configure(CFG)
check("a stale default makes it an update", st == "updated", st)
check("and it is migrated", load()["model"] == "mymac/default", load().get("model"))
print("\n5. uninstall: remove local, keep remote, repoint model")
rp, rb = remote("popos.local")
reset({"provider": {"llmhost": opencode.local_block(CFG), rp: rb}, "model": "llmhost/ornith-1.5-9b"})
reset({"provider": {"llmhost": opencode.local_block(CFG), rp: rb}, "model": "llmhost/default"})
st, path, removed, new_model = opencode.remove(local=True)
d = load()
check("status removed", st == "removed", st)
check("removed only local", removed == ["llmhost"], removed)
check("remote survives", list(d["provider"]) == [rp], list(d["provider"]))
first = CFG["models"][0]["name"]
check("model repointed to remote's first (plan-order) model",
new_model == f"{rp}/{first}" and d["model"] == new_model, (new_model, d.get("model")))
check("model repointed to the surviving provider's entry",
new_model == f"{rp}/{plan.SERVED_ALIAS}" and d["model"] == new_model, (new_model, d.get("model")))
# An older remote block, pasted before the single-entry change, still lists every model;
# the fallback takes its first in plan order rather than whichever name sorts first.
legacy = {**rb, "models": {m["name"]: {"name": m["name"]} for m in CFG["models"]}}
reset({"provider": {"llmhost": opencode.local_block(CFG), rp: legacy}, "model": "llmhost/default"})
st, path, removed, new_model = opencode.remove(local=True)
check("legacy multi-model block falls back to its first",
new_model == f"{rp}/{CFG['models'][0]['name']}", new_model)
print("\n6. uninstall must NOT glob llmhost*")
reset({"provider": {rp: rb}, "model": f"{rp}/qwen3.8-27b"})
@ -249,13 +260,16 @@ check("config dir gone", not paths.CONFIG_DIR.exists())
check("a reinstall mints a different key", paths.api_key(create=True).strip() != key2.strip())
print("\n20. sync() refreshes an existing block after a switch")
reset({"provider": {"llmhost": opencode.local_block(CFG)}, "model": "llmhost/" + CFG["active"]})
reset({"provider": {"llmhost": opencode.local_block(CFG)}, "model": "llmhost/default"})
switched = dict(CFG, active="qwen3-coder")
prov = opencode.sync(switched)
mods = load()["provider"]["llmhost"]["models"]
d = load()
mods = d["provider"]["llmhost"]["models"]
check("reported the provider", prov == "llmhost", prov)
check("new model marked loaded", mods["qwen3-coder"]["name"].endswith("(Local, loaded)"), mods["qwen3-coder"]["name"])
check("old one unmarked", not mods[CFG["active"]]["name"].endswith(", loaded)"), mods[CFG["active"]]["name"])
check("still one entry, same id", list(mods) == ["default"], list(mods))
check("label follows the switch", "Qwen3 Coder 30B A3B" in mods["default"]["name"], mods["default"]["name"])
check("the client's saved default still resolves", d["model"] == "llmhost/default", d.get("model"))
check("reasoning dropped for a non-reasoning model", "reasoning" not in mods["default"], mods["default"])
check("idempotent", opencode.sync(switched) is None)
print("\n21. sync() never wires opencode up on its own")
@ -268,4 +282,18 @@ check("foreign provider untouched", load()["provider"] == {"popos-vllm": foreign
reset({"provider": {"mymac": opencode.local_block(CFG)}})
check("finds a renamed local block", opencode.sync(dict(CFG, active="qwen3-coder")) == "mymac")
check.section("22. a default naming a specific model is migrated to the alias")
for old_model, expect in (("llmhost/qwen3.8-27b", "llmhost/default"),
("llmhost/ornith-1.5-9b", "llmhost/default"),
("llmhost/default", "llmhost/default"),
("popos-vllm/qwen3.8-27b", "popos-vllm/qwen3.8-27b"),
("llmhost-popos/qwen3.8-27b", "llmhost-popos/qwen3.8-27b")):
reset({"provider": {"llmhost": opencode.local_block(CFG)}, "model": old_model})
opencode.configure(CFG)
got = load().get("model")
check(f"{old_model} -> {expect}", got == expect, got)
reset({"provider": {"mymac": opencode.local_block(CFG)}, "model": "mymac/qwen3-coder"})
opencode.sync(dict(CFG, active="qwen3-coder"))
check("migrated under a renamed provider too", load()["model"] == "mymac/default", load().get("model"))
check.done(ROOT)