Skip to content

The agent that grows with you

fix(tui): a new profile inherits a bare `custom` launch model with its endpoint

kshitijk4poor463d40192d92
diff --git a/hermes_cli/web_routers/profiles.py b/hermes_cli/web_routers/profiles.py
index fcd4c87aea5..2e9602929ac 100644
--- a/hermes_cli/web_routers/profiles.py
+++ b/hermes_cli/web_routers/profiles.py
@@ -121,7 +121,8 @@ def _scope_profile_name(path: Path) -> Optional[str]:
return path.name
-def _write_profile_model(profile_dir: Path, provider: str, model: str, validate_in: Optional[Path] = None) -> None:
+def _write_profile_model(profile_dir: Path, provider: str, model: str, validate_in: Optional[Path] = None,
+ base_url: str = "") -> None:
"""Write the main model assignment into ``profile_dir``'s config.yaml (HERMES_HOME-scoped)
through the same validated /model shape as ``POST /api/model/set``.
@@ -133,11 +134,14 @@ def _write_profile_model(profile_dir: Path, provider: str, model: str, validate_
Both spans enter ``_config_profile_scope`` (home + secret scope), matching ``/api/model/set``:
once the dashboard has served a secondary profile, ``switch_model``'s ``key_env`` probe goes
through ``get_secret``, which fails closed without a scope and reports the provider as
- unconnected (UnscopedSecretError class, #114676)."""
+ unconnected (UnscopedSecretError class, #114676).
+
+ ``base_url`` is the endpoint a bare ``custom`` pick binds to (``switch_model`` has nothing else
+ to resolve it from in a fresh profile); other providers ignore it."""
from hermes_cli.config import load_config, save_config
with _config_profile_scope(_scope_profile_name(validate_in or profile_dir)):
provider, model = _normalize_main_model_assignment(provider, model)
- result = _validated_main_model_selection(load_config(), provider, model)
+ result = _validated_main_model_selection(load_config(), provider, model, base_url)
with _config_profile_scope(_scope_profile_name(profile_dir)), _CONFIG_MUTATION_LOCK: # RMW span
cfg = load_config()
cfg["model"] = _apply_main_model_assignment(cfg.get("model", {}), result)
diff --git a/tests/tui_gateway/test_profiles_inherit_launch_model.py b/tests/tui_gateway/test_profiles_inherit_launch_model.py
index c3c0d50ac0d..ffd8b964f19 100644
--- a/tests/tui_gateway/test_profiles_inherit_launch_model.py
+++ b/tests/tui_gateway/test_profiles_inherit_launch_model.py
@@ -96,6 +96,35 @@ def test_inherit_launch_model_carries_a_custom_provider_gateway(
assert copied["api_key"] == "${FAKE_GW_TOKEN}"
+def test_inherit_launch_model_pins_a_bare_custom_endpoint(monkeypatch, tmp_path):
+ home = tmp_path / ".hermes"
+ home.mkdir()
+ monkeypatch.setattr(Path, "home", lambda: tmp_path)
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ for var in ("CUSTOM_BASE_URL", "OPENAI_BASE_URL"):
+ monkeypatch.delenv(var, raising=False)
+ url = "http://127.0.0.1:11434/v1"
+ atomic_config_write(
+ home / "config.yaml",
+ {
+ "model": {"provider": "custom", "default": "llama3", "base_url": url},
+ "_config_version": DEFAULT_CONFIG["_config_version"],
+ },
+ )
+ profile = home / "profiles" / "scout"
+ profile.mkdir(parents=True)
+ # Voice mirroring writes config.yaml before inheritance runs (#85755).
+ atomic_config_write(
+ profile / "config.yaml",
+ {"tts": {"provider": "edge"}, "_config_version": DEFAULT_CONFIG["_config_version"]},
+ )
+
+ assert srv._inherit_launch_model(profile) is True
+
+ model = read_user_config_raw(profile / "config.yaml")["model"]
+ assert (model["provider"], model["default"], model["base_url"]) == ("custom", "llama3", url)
+
+
def test_inherit_launch_model_preserves_explicit_profile_selection(
monkeypatch, tmp_path
):
diff --git a/tui_gateway/methods_profiles.py b/tui_gateway/methods_profiles.py
index 5e80f78219d..9e8328993e3 100644
--- a/tui_gateway/methods_profiles.py
+++ b/tui_gateway/methods_profiles.py
@@ -38,8 +38,9 @@ def _lazy(module, name):
return getattr(__import__(module, fromlist=[name]), name)
-def _pin_profile_model(profile_dir, provider, model) -> None:
- _lazy("hermes_cli.web_routers.profiles", "_write_profile_model")(profile_dir, provider, model)
+def _pin_profile_model(profile_dir, provider, model, base_url="") -> None:
+ _lazy("hermes_cli.web_routers.profiles", "_write_profile_model")(
+ profile_dir, provider, model, base_url=base_url)
def _model_provider_params(params) -> tuple:
@@ -528,7 +529,10 @@ def _inherit_launch_model(path) -> bool:
merge = _lazy("hermes_cli.profile_model_seed", "merge_endpoint_seed")
with _hermes_home_scope(path):
save_config(merge(read_user_config_raw(), seed))
- _pin_profile_model(path, str(model_cfg["provider"]), str(model_cfg["default"]))
+ # A bare ``custom`` model is its endpoint: the pin validates it in the empty new profile, where
+ # nothing else names that base_url.
+ _pin_profile_model(path, str(model_cfg["provider"]), str(model_cfg["default"]),
+ str(model_cfg.get("base_url") or ""))
return True