Skip to content

The agent that grows with you

fix(local): the picker's Local row id and the provider resolver share one definition (#116249)

Hermes04f37f74b0bc
diff --git a/hermes_cli/inventory.py b/hermes_cli/inventory.py
index 80c338c1a7c..a71c99a9a37 100644
--- a/hermes_cli/inventory.py
+++ b/hermes_cli/inventory.py
@@ -666,14 +666,17 @@ def _apply_pricing(rows: list[dict], *, force_fresh_nous_tier: bool = False, cac
def _local_runtime_row(ctx: "ConfigContext") -> dict | None:
"""The ``llamacpp`` row from staged GGUFs (``None`` when none) — downloaded models must be selectable
- before the server runs (selection starts it via the runtime_provider seam)."""
+ before the server runs (selection starts it via the runtime_provider seam). The row's id comes from
+ the provider registry's own definition, never a local literal: a row the resolver can't resolve is
+ the bug this row's offline-first contract depends on not having."""
try:
from hermes_cli.local_runtime.bootstrap import staged_model_ids
+ from hermes_cli.providers import LLAMACPP_ALIASES, LLAMACPP_PROVIDER_ID
staged = staged_model_ids()
if not staged:
return None
- current = (ctx.current_provider or "").strip().lower() in ("llamacpp", "llama.cpp", "llama-cpp")
+ current = (ctx.current_provider or "").strip().lower() in LLAMACPP_ALIASES
if not current:
# A LIVE session on the managed server reports provider "custom" with the managed base_url;
# match on the endpoint so the session being chatted in still shows a selection.
@@ -686,7 +689,7 @@ def _local_runtime_row(ctx: "ConfigContext") -> dict | None:
except Exception:
current = False
# Bare "Local" user-facing (engine name is an implementation detail); authenticated = reachability.
- return _row("llamacpp", "Local", current, models=staged, total_models=len(staged),
+ return _row(LLAMACPP_PROVIDER_ID, "Local", current, models=staged, total_models=len(staged),
source="local-runtime", authenticated=True, auth_type="local", warning=None)
except Exception:
return None
diff --git a/hermes_cli/local_runtime/endpoint.py b/hermes_cli/local_runtime/endpoint.py
index e1649d5315d..8f31e9e76b4 100644
--- a/hermes_cli/local_runtime/endpoint.py
+++ b/hermes_cli/local_runtime/endpoint.py
@@ -88,6 +88,12 @@ def resolve_llamacpp_endpoint(config: dict | None = None,
from hermes_cli.local_runtime.detect import detect_server
+ # ``local_runtime.detect_ports`` is the documented knob for an external llama-server on a
+ # non-default port, but every provider-resolution caller invokes this bare — without loading the
+ # config here the knob was dead on the only paths that need it, so a server on e.g. :8010 stayed
+ # undetected and `provider: llamacpp` resolved to nothing.
+ with suppress(Exception):
+ config = _load_config_if_none(config)
ports = ((config or {}).get("local_runtime") or {}).get("detect_ports") or []
hit = detect_server(extra_ports=tuple(int(p) for p in ports))
if hit and not hit.auth_required:
diff --git a/hermes_cli/model_switch.py b/hermes_cli/model_switch.py
index 0124fef71ed..54fc5000716 100644
--- a/hermes_cli/model_switch.py
+++ b/hermes_cli/model_switch.py
@@ -14,8 +14,8 @@ from dataclasses import dataclass, field
from typing import Any, NamedTuple, Optional
from hermes_cli.providers import (
- ProviderDef, custom_provider_aliases, determine_api_mode, get_label, host_mandated_api_mode,
- is_aggregator, resolve_provider_full)
+ LLAMACPP_ALIASES, ProviderDef, custom_provider_aliases, determine_api_mode, get_label,
+ host_mandated_api_mode, is_aggregator, resolve_provider_full)
from hermes_cli.model_normalize import normalize_model_for_provider
from agent.models_dev import (
ModelCapabilities, ModelInfo, get_model_capabilities, get_model_info, list_provider_models)
@@ -1407,6 +1407,10 @@ def _creds_for_switched_provider(st: _Switch) -> Optional[ModelSwitchResult]:
try:
st.resolve_runtime(requested=st.target_provider, explicit_base_url=alias_url or None)
except Exception as e:
+ if st.target_provider.strip().lower() in LLAMACPP_ALIASES:
+ # A local-runtime alias has no credential to add: the seam's own message ("server
+ # isn't running" / "turned off") is the actionable one, the auth hint below is noise.
+ return st.fail_on_target(str(e))
return st.fail_on_target(
f"{st.provider_label} is not connected: no API key or login was found for it. Add one with "
f"`hermes auth add {st.target_provider}`, or pick a connected provider in /model.\n"
diff --git a/hermes_cli/providers.py b/hermes_cli/providers.py
index 3840d9efa12..8c25304f6e4 100644
--- a/hermes_cli/providers.py
+++ b/hermes_cli/providers.py
@@ -475,20 +475,40 @@ def _lossy_alias_registry_pdef(raw: str, canonical: str) -> Optional[ProviderDef
return None
+# The local llama.cpp runtime's provider id + aliases: ONE definition, shared by the resolver rung
+# below and the picker's Local row (``hermes_cli/inventory.py``) — the two drifting apart is what
+# made the row's own id unresolvable.
+LLAMACPP_PROVIDER_ID = "llamacpp"
+LLAMACPP_ALIASES: Tuple[str, ...] = (LLAMACPP_PROVIDER_ID, "llama.cpp", "llama-cpp")
+
+
+def _has_staged_local_models() -> bool:
+ """True when GGUFs are staged under the Hermes home's ``models/`` — the model the picker's Local
+ row offers, which the runtime seam serves by booting/attaching a server on selection."""
+ try:
+ from hermes_cli.local_runtime.bootstrap import staged_model_ids
+ return bool(staged_model_ids())
+ except Exception:
+ return False
+
+
def _llamacpp_pdef() -> Optional[ProviderDef]:
"""The llamacpp aliases are a real provider whenever the managed server (or a detected external
- one) resolves — reachability is the credential. Without this rung model-switch rejected the very
- provider the Local Models 'Use' flow writes to config."""
+ one) resolves — reachability is the credential — OR a model is staged for the runtime to serve.
+ The picker's Local row is built from staged GGUFs and is deliberately offline-first (selection
+ starts the server through the runtime seam), so requiring a live endpoint before admitting the id
+ made that row offer a provider the resolver rejected ("Unknown provider 'llamacpp'"). Without
+ this rung model-switch rejected the very provider the Local Models 'Use' flow writes to config."""
try:
from hermes_cli.config import load_config_readonly
from hermes_cli.local_runtime.endpoint import resolve_llamacpp_endpoint
endpoint = resolve_llamacpp_endpoint(load_config_readonly(), wait_for_boot_s=0)
except Exception:
endpoint = None
- if not endpoint:
+ if not endpoint and not _has_staged_local_models():
return None
- return ProviderDef(id="llamacpp", name="Local", transport="openai_chat", api_key_env_vars=(), base_url=endpoint["base_url"],
- source="local-runtime")
+ return ProviderDef(id=LLAMACPP_PROVIDER_ID, name="Local", transport="openai_chat", api_key_env_vars=(),
+ base_url=(endpoint or {}).get("base_url", ""), source="local-runtime")
def resolve_provider_full(name: str, user_providers: Optional[Dict[str, Any]] = None,
@@ -523,7 +543,7 @@ def resolve_provider_full(name: str, user_providers: Optional[Dict[str, Any]] =
custom_pdef = resolve_custom_provider(name, custom_providers)
if custom_pdef is not None:
return custom_pdef
- if raw in ("llamacpp", "llama.cpp", "llama-cpp"):
+ if raw in LLAMACPP_ALIASES:
pdef = _llamacpp_pdef()
if pdef is not None:
return pdef
diff --git a/tests/hermes_cli/test_local_runtime.py b/tests/hermes_cli/test_local_runtime.py
index 67e201729b8..61edb297dcf 100644
--- a/tests/hermes_cli/test_local_runtime.py
+++ b/tests/hermes_cli/test_local_runtime.py
@@ -862,6 +862,72 @@ def test_runtime_provider_seam_explicit_base_url_wins(tmp_path, monkeypatch):
assert runtime["source"] != "local-runtime"
+def _stage_local_model(home, model_id):
+ models = home / "models"
+ models.mkdir(parents=True, exist_ok=True)
+ (models / f"{model_id}.gguf").write_bytes(b"GGUF")
+
+
+def test_staged_local_model_resolves_without_a_running_server(tmp_path, monkeypatch):
+ """The picker's Local row exists from staged GGUFs alone (contract: selectable before the server
+ runs — selection starts it through the runtime seam). Selecting one must reach that seam instead
+ of dying at the provider gate with "Unknown provider 'llamacpp'": the row's id and the resolver's
+ are one definition, so an id the picker offers always resolves."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
+ _stage_local_model(tmp_path / ".hermes", "Qwen3.8-27B-IQ3_S-mtp")
+ monkeypatch.setattr("hermes_cli.local_runtime.detect.DEFAULT_PROBE_PORTS", ())
+
+ from hermes_cli.providers import LLAMACPP_PROVIDER_ID, resolve_provider_full
+
+ pdef = resolve_provider_full(LLAMACPP_PROVIDER_ID, {}, [])
+ assert pdef is not None, "staged model, but the picker's own provider id does not resolve"
+ assert pdef.id == LLAMACPP_PROVIDER_ID
+
+ from hermes_cli.model_switch import switch_model
+
+ result = switch_model("Qwen3.8-27B-IQ3_S-mtp", current_provider="nous",
+ current_model="Hermes-4.5", current_base_url="",
+ explicit_provider=LLAMACPP_PROVIDER_ID)
+ assert result.success is False # no server anywhere; the seam reports it
+ error = result.error_message or ""
+ assert "Unknown provider" not in error
+ assert "local model server" in error.lower(), error
+
+
+def test_llamacpp_id_stays_unresolved_without_models_or_server(tmp_path, monkeypatch):
+ """Nothing staged and nothing running: the alias is still unknown — admitting it unconditionally
+ would offer a provider with neither a model nor an endpoint."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))
+ monkeypatch.setattr("hermes_cli.local_runtime.detect.DEFAULT_PROBE_PORTS", ())
+
+ from hermes_cli.providers import resolve_provider_full
+
+ assert resolve_provider_full("llamacpp", {}, []) is None
+
+
+def test_external_server_on_a_configured_detect_port_is_used(tmp_path, monkeypatch, stub_server):
+ """A llama-server the user runs on a fixed non-default port is what `provider: llamacpp` resolves
+ to when that port is declared in local_runtime.detect_ports — the knob is documented for exactly
+ this, and every provider path calls the endpoint resolver without a config."""
+ port, handler = stub_server
+ handler.props = {"build_info": "b10964-test", "model_path": "/models/ext-model.gguf",
+ "default_generation_settings": {"n_ctx": 4096}}
+ handler.models = {"data": [{"id": "ext-model", "owned_by": "llamacpp"}]}
+ home = tmp_path / ".hermes"
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ _stage_local_model(home, "ext-model")
+ (home / "config.yaml").write_text(
+ f"local_runtime:\n enabled: false\n detect_ports: [{port}]\n", encoding="utf-8")
+ monkeypatch.setattr("hermes_cli.local_runtime.detect.DEFAULT_PROBE_PORTS", ())
+
+ from hermes_cli.model_switch import switch_model
+
+ result = switch_model("ext-model", current_provider="nous", current_model="Hermes-4.5",
+ current_base_url="", explicit_provider="llamacpp")
+ assert result.success, result.error_message
+ assert result.base_url == f"http://127.0.0.1:{port}/v1"
+
+
def test_local_runtime_config_defaults_shape():
"""Contract: the section exists, is off by default, and carries no
context/VRAM knobs (design: constants, not knobs)."""