The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(profiles): inherited endpoint is not shadowed by the profile's own entries
kshitijk4poorac0b63afacab
diff --git a/hermes_cli/profile_model_seed.py b/hermes_cli/profile_model_seed.pyindex 949ad71118b..dd60dc2912e 100644--- a/hermes_cli/profile_model_seed.py+++ b/hermes_cli/profile_model_seed.py@@ -2,7 +2,9 @@from hermes_cli.config import _expand_env_vars, find_provider_entryfrom hermes_cli.config_providers import _normalize_custom_provider_entry+from hermes_cli.providers import custom_provider_aliasesfrom hermes_cli.runtime_provider_custom import (+ _entry_url,_get_named_custom_provider,_normalize_custom_provider_name,_shadowed_by_builtin,@@ -54,3 +56,36 @@ def launch_model_seed(source_cfg: dict) -> dict:seed["custom_providers"] = [entry]return seedreturn seed+++def merge_endpoint_seed(dst_cfg: dict, seed: dict) -> dict:+ """*dst_cfg* with the seeded endpoint written ahead of, and instead of, destination entries+ claiming the same identity. Runtime takes the first alias match (keyed ``providers:`` before+ ``custom_providers:``), so a colliding entry already in the profile would shadow the inherited+ endpoint. URL-less tuning seeds only replace their own key."""+ seed_providers = seed.get("providers") or {}+ seed_custom = seed.get("custom_providers") or []+ claimed: frozenset[str] = frozenset().union(+ *(custom_provider_aliases(str(e.get("name") or k), str(k))+ for k, e in seed_providers.items() if _entry_url(e)),+ *(custom_provider_aliases(str(e.get("name") or ""), str(e.get("provider_key") or ""))+ for e in seed_custom),+ )++ def unclaimed(entry, key="") -> bool:+ if not isinstance(entry, dict):+ return True+ key = key or str(entry.get("provider_key") or "")+ return not claimed & custom_provider_aliases(str(entry.get("name") or key), key)++ merged = dict(dst_cfg)+ existing = dst_cfg.get("providers")+ if isinstance(existing, dict) or seed_providers:+ merged["providers"] = {**seed_providers, **{+ k: v for k, v in (existing if isinstance(existing, dict) else {}).items()+ if k not in seed_providers and unclaimed(v, str(k))}}+ existing = dst_cfg.get("custom_providers")+ if isinstance(existing, list) or seed_custom:+ merged["custom_providers"] = seed_custom + [+ e for e in (existing if isinstance(existing, list) else []) if unclaimed(e)]+ return mergeddiff --git a/tests/tui_gateway/test_profiles_inherit_launch_model.py b/tests/tui_gateway/test_profiles_inherit_launch_model.pyindex 0783cdae713..c3c0d50ac0d 100644--- a/tests/tui_gateway/test_profiles_inherit_launch_model.py+++ b/tests/tui_gateway/test_profiles_inherit_launch_model.py@@ -58,7 +58,13 @@ def test_inherit_launch_model_carries_a_custom_provider_gateway("base_url": "http://127.0.0.1:11436/v1","api_key": "${RETAINED_TOKEN}",}- retained_catalog = {"retained": retained} if schema == "providers" else [retained]+ # Same identity under another key: runtime takes the first alias match, so it must not survive.+ stale = {"name": "my-gateway", "base_url": "http://127.0.0.1:11437/v1"}+ retained_catalog = (+ {"stale": stale, "retained": retained}+ if schema == "providers"+ else [stale, retained]+ )atomic_config_write(profile / "config.yaml",{@@ -75,11 +81,12 @@ def test_inherit_launch_model_carries_a_custom_provider_gateway(provider,"my-finetune",)- assert cfg[schema] == (+ expected = ({"my-gateway": endpoint, "retained": retained}if schema == "providers"else [endpoint, retained])+ assert cfg[schema] == expected# The gateway travels as the launch file wrote it: the ref, never the launch secret.copied = (cfg["providers"]["my-gateway"]diff --git a/tui_gateway/methods_profiles.py b/tui_gateway/methods_profiles.pyindex 1bcbc694adc..5e80f78219d 100644--- a/tui_gateway/methods_profiles.py+++ b/tui_gateway/methods_profiles.py@@ -525,21 +525,9 @@ def _inherit_launch_model(path) -> bool:seed = _lazy("hermes_cli.profile_model_seed", "launch_model_seed")(read_user_config_raw())if seed.get("providers") or seed.get("custom_providers"):from hermes_cli.config import save_config- from hermes_cli.providers import custom_provider_aliases+ merge = _lazy("hermes_cli.profile_model_seed", "merge_endpoint_seed")with _hermes_home_scope(path):- cfg = read_user_config_raw()- if seed.get("providers"):- existing_providers = cfg.get("providers")- cfg["providers"] = {**(existing_providers if isinstance(existing_providers, dict) else {}),- **seed["providers"]}- if custom := seed.get("custom_providers"):- aliases = custom_provider_aliases(custom[0].get("name", ""), custom[0].get("provider_key", ""))- existing = cfg.get("custom_providers")- cfg["custom_providers"] = custom + [- entry for entry in (existing if isinstance(existing, list) else [])- if not isinstance(entry, dict) or not aliases.intersection(- custom_provider_aliases(entry.get("name", ""), entry.get("provider_key", "")))]- save_config(cfg)+ save_config(merge(read_user_config_raw(), seed))_pin_profile_model(path, str(model_cfg["provider"]), str(model_cfg["default"]))return True