Skip to content

The agent that grows with you

fix(profiles): match endpoint identity the way runtime does when merging

kshitijk4pooref57cbd94613
diff --git a/hermes_cli/profile_model_seed.py b/hermes_cli/profile_model_seed.py
index db692f8333e..e7720688804 100644
--- a/hermes_cli/profile_model_seed.py
+++ b/hermes_cli/profile_model_seed.py
@@ -1,10 +1,9 @@
"""Copy the model and its selected custom endpoint when creating an independent profile."""
-from hermes_cli.config import _expand_env_vars, find_provider_entry
+from hermes_cli.config import _expand_env_vars, find_provider_entry, is_provider_enabled
from hermes_cli.config_providers import _normalize_custom_provider_entry
from hermes_cli.providers import custom_provider_aliases
from hermes_cli.runtime_provider_custom import (
- _entry_url,
_get_named_custom_provider,
_normalize_custom_provider_name,
_shadowed_by_builtin,
@@ -58,9 +57,12 @@ def launch_model_seed(source_cfg: dict) -> dict:
return seed
-def _identity(entry: dict, key: str = "") -> frozenset[str]:
- """Aliases runtime matches *entry* by; empty when it has no URL (runtime skips those)."""
- if not _entry_url(entry):
+def _identity(entry, key: str = "") -> frozenset[str]:
+ """Aliases runtime can match *entry* by: empty for non-dicts, disabled entries and entries
+ the shared normalizer rejects (no usable URL; ``baseUrl`` counts, as it does at runtime)."""
+ if not isinstance(entry, dict) or not is_provider_enabled(entry):
+ return frozenset()
+ if _normalize_custom_provider_entry(entry, provider_key=key) is None:
return frozenset()
key = key or str(entry.get("provider_key") or "")
return custom_provider_aliases(str(entry.get("name") or key), key)
@@ -70,8 +72,8 @@ def merge_endpoint_seed(dst_cfg: dict, seed: dict) -> dict:
"""Return a copy of *dst_cfg* with the seeded endpoint written first. Runtime takes the first
alias match (keyed ``providers:`` before ``custom_providers:``), so destination entries with a
URL that claim the same identity would shadow the inherited endpoint and are dropped; a
- same-key destination entry is replaced whole. URL-less entries never match at runtime: a
- URL-less tuning seed replaces only its own key, and URL-less destination entries are kept."""
+ same-key destination entry is replaced whole. Entries runtime cannot match (no URL, disabled)
+ never shadow: such a seed replaces only its own key, and such destination entries are kept."""
seed_providers = seed.get("providers") or {}
seed_custom = seed.get("custom_providers") or []
claimed: set[str] = set()
@@ -85,14 +87,14 @@ def merge_endpoint_seed(dst_cfg: dict, seed: dict) -> dict:
if isinstance(dst_providers, dict) or seed_providers:
kept = {
k: v for k, v in (dst_providers if isinstance(dst_providers, dict) else {}).items()
- if k not in seed_providers and not (isinstance(v, dict) and claimed & _identity(v, str(k)))
+ if k not in seed_providers and not claimed & _identity(v, str(k))
}
merged["providers"] = {**seed_providers, **kept}
dst_custom = dst_cfg.get("custom_providers")
if isinstance(dst_custom, list) or seed_custom:
kept_list = [
e for e in (dst_custom if isinstance(dst_custom, list) else [])
- if not (isinstance(e, dict) and claimed & _identity(e))
+ if not claimed & _identity(e)
]
merged["custom_providers"] = seed_custom + kept_list
return merged
diff --git a/tests/hermes_cli/test_profile_model_seed.py b/tests/hermes_cli/test_profile_model_seed.py
index 7f9c7618940..ee68a1cba4a 100644
--- a/tests/hermes_cli/test_profile_model_seed.py
+++ b/tests/hermes_cli/test_profile_model_seed.py
@@ -207,12 +207,29 @@ URL = "http://127.0.0.1:11434/v1"
),
# A URL-less tuning seed replaces only its own key.
(
- {"providers": {"lab": {"request_timeout_seconds": 5}}},
- {"providers": {"lab-alt": {"name": "lab", "base_url": URL}}},
+ {"providers": {"custom": {"request_timeout_seconds": 5}}},
+ {"providers": {"local": {"name": "custom", "base_url": URL}}},
{
"providers": {
- "lab": {"request_timeout_seconds": 5},
- "lab-alt": {"name": "lab", "base_url": URL},
+ "custom": {"request_timeout_seconds": 5},
+ "local": {"name": "custom", "base_url": URL},
+ }
+ },
+ ),
+ # A camelCase ``baseUrl`` legacy seed is a live endpoint and still evicts its shadow.
+ (
+ {"custom_providers": [{"name": "Lab", "baseUrl": URL}]},
+ {"providers": {"lab": {"base_url": URL + "x"}}},
+ {"providers": {}, "custom_providers": [{"name": "Lab", "baseUrl": URL}]},
+ ),
+ # A disabled destination entry can never shadow, so it is kept.
+ (
+ {"providers": {"lab": {"base_url": URL}}},
+ {"providers": {"old": {"name": "lab", "base_url": URL + "x", "enabled": False}}},
+ {
+ "providers": {
+ "lab": {"base_url": URL},
+ "old": {"name": "lab", "base_url": URL + "x", "enabled": False},
}
},
),