Refuse a request for a model that isn't loaded; show the slug in /models

The MLX proxy rewrote every request's "model" to the preloaded one, so asking
for a model the server wasn't running returned another model's output wearing
the requested name -- silently. The rewrite itself has to stay (mlx_lm would
otherwise try to load a model matching the name), so validate first: a name
that is neither the served name nor its repo id gets 404 model_not_found,
naming what is loaded and how to switch. An unstated name still means "the
loaded one", and the key is still checked before the model.

opencode's /models hid the same trap twice over. Label models
`<title> · <slug> (<where>)` so the list is searchable by the id used
everywhere else -- titles alone had dropped the slug -- and mark the loaded
one `(Local, loaded)`, refreshed by both switch paths (CLI and dashboard)
through a new opencode.sync(), which only ever refreshes a block that is
already there.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Neil Bantoc 2026-11-03 00:38:35 -08:00
parent 8c6615dbb4
commit 2c0818ca2b
5 changed files with 78 additions and 11 deletions

View file

@ -13,7 +13,7 @@ from collections import deque
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
from .. import hfcache, hw, paths, service
from .. import hfcache, hw, opencode, paths, service
HERE = Path(__file__).resolve().parent
SAMPLE_SECONDS = 2
@ -205,6 +205,7 @@ class Sampler:
cfg["active"] = model
paths.save_config(cfg)
self.cfg = cfg
opencode.sync(cfg) # keep /models' "loaded" marker honest after a dashboard switch
fn = service.restart
else:
fn = {"stop": service.stop, "start": service.start, "restart": service.restart}[kind]