ai: only list custom GGUFs llama-server can load; reset context on custom select

Review found two gaps in the custom-model listing.

Any *.gguf basename was listed and accepted, but start_llama_server.sh
reads active_model back out of ai.yaml through read_config_value.sh.
PyYAML dumps non-ASCII as escapes the reader prints literally, the
reader strips " #..." before unquoting, and the start script's
traversal guard rejects any ".." run. Those names got a 200 from the
API and then "Model file does not exist" at startup. A shared
is_loadable_model_name check now filters the catalog loop and rejects
the name in manage_settings, so the UI never shows an activation that
cannot start. Directories named *.gguf are skipped too.

Selecting a custom model after a catalog model kept the previous
model's explicit context_size (e.g. 16384 from the 4B) because the
adopt branch was skipped when there was no catalog default. The
default is now always written on model selection, so a custom model
resets to null and the conservative default applies. The hint text
says so instead of claiming the default is used unconditionally.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-09-24 13:49:15 -06:00
parent 49ff97c3ad
commit 32e0f69abc
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
4 changed files with 90 additions and 8 deletions

View file

@ -750,7 +750,8 @@ async def manage_catalog(_: Request):
# here on every request (no file refresh) so it appears in the Active Model dropdown.
catalog_names = {i['name'] for i in models}
for name, path in sorted(on_disk.items()):
if name not in catalog_names:
# Skip names start_llama_server.sh could not load (see is_loadable_model_name).
if name not in catalog_names and path.is_file() and catalog.is_loadable_model_name(name):
models.append(dict(
name=name,
tier='custom',
@ -788,11 +789,16 @@ async def manage_settings(_: Request, body: schema.AIManageSettingsRequest):
if body.active_model is not None:
if body.active_model and not (catalog.get_models_directory() / body.active_model).is_file():
raise ValidationError(f'Model is not downloaded: {body.active_model}')
if body.active_model and not catalog.is_loadable_model_name(body.active_model):
raise ValidationError(f'Model file name cannot be loaded by llama-server; rename it to plain ASCII'
f' without #, quotes, or "..": {body.active_model}')
config.active_model = body.active_model
# Each model has its own context default (the 4B runs 16k, the small tier 8k); selecting
# a model adopts it unless this request also sets context_size explicitly.
if body.context_size is None and (default := catalog.get_model_default_context(body.active_model)):
config.context_size = default
# a model adopts it unless this request also sets context_size explicitly. A custom model
# has no catalog default, so the previous model's explicit value is cleared rather than
# carried over.
if body.context_size is None:
config.context_size = catalog.get_model_default_context(body.active_model)
if body.enabled is not None:
config.enabled = body.enabled
if body.idle_unload_minutes is not None: