The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(telemetry): loopback provider aliases and AWS ARNs collapse model ids to custom
teknium1a2d08fba3673
diff --git a/hermes_cli/observability/shared_metrics_catalog.py b/hermes_cli/observability/shared_metrics_catalog.pyindex 0a7fe3566a3..546d5ddf18c 100644--- a/hermes_cli/observability/shared_metrics_catalog.py+++ b/hermes_cli/observability/shared_metrics_catalog.py@@ -103,13 +103,18 @@ def user_named_model_providers() -> frozenset[str]:"""Providers whose model ids the user names: custom endpoints and loopback servers."""from urllib.parse import urlparse+ from hermes_cli import auth, models, providersfrom hermes_cli.auth import PROVIDER_REGISTRY- loopback = {"localhost", "127.0.0.1", "::1", "0.0.0.0"}- return frozenset(+ hosts = {"localhost", "127.0.0.1", "::1", "0.0.0.0"}+ loopback = {name for name, config in PROVIDER_REGISTRY.items()- if urlparse(str(getattr(config, "inference_base_url", "") or "")).hostname in loopback- ) | {CUSTOM}+ if urlparse(str(getattr(config, "inference_base_url", "") or "")).hostname in hosts+ }+ # Alias spellings (``lm-studio``) pass provider_metric_name as shipped names, so they must collapse too.+ tables = (providers.ALIASES, getattr(auth, "_PROVIDER_ALIASES", {}), getattr(models, "_PROVIDER_ALIASES", {}))+ aliases = {alias for table in tables for alias, canon in table.items() if canon in loopback}+ return frozenset(loopback | aliases | {CUSTOM})@functools.cache@@ -289,10 +294,11 @@ def model_metric_name(raw: object, provider: str, *, max_length: int) -> str:return model-# The user's own server, never a public model id: a URL or path (``:/``), a weight file, a loopback-# or IPv4 host, or ``host:port`` (a 2-5 digit port, so Bedrock's ``...-v1:0`` stays readable).+# The user's own server or account, never a public model id: a URL or path (``:/``), a weight file,+# a loopback or IPv4 host, ``host:port`` (a 2-5 digit port, so Bedrock's ``...-v1:0`` stays readable),+# or an AWS ARN (it carries the account id)._LOCATION_MODEL = re.compile(- r".*:/|.*\.(?:gguf|bin|safetensors)$|(?:localhost|\d{1,3}(?:\.\d{1,3}){3})(?:[:/]|$)|[^/:]+:\d{2,5}(?:/|$)"+ r"arn:|.*:/|.*\.(?:gguf|bin|safetensors)$|(?:localhost|\d{1,3}(?:\.\d{1,3}){3})(?:[:/]|$)|[^/:]+:\d{2,5}(?:/|$)")diff --git a/tests/hermes_cli/test_shared_metrics_model_attribution.py b/tests/hermes_cli/test_shared_metrics_model_attribution.pyindex a6c3dfe913e..832ad25c9a7 100644--- a/tests/hermes_cli/test_shared_metrics_model_attribution.py+++ b/tests/hermes_cli/test_shared_metrics_model_attribution.py@@ -164,6 +164,10 @@ def test_network_address_model_ids_and_raw_injected_marks_never_reach_counters(dfor model in ("127.0.0.1:8080/x", "localhost/qwen", "10.0.0.5/x", "gpu-box.lan:8000/qwen", "gpu-box.lan:8000"):assert model_route("openrouter", model)["model"] == "custom", model+ # An AWS ARN carries the account id; an alias spelling of a loopback provider names the user's model.+ for provider, model in (("bedrock", "arn:aws:bedrock:us-east-1:123456789012:inference-profile/x"),+ ("lm-studio", "my-model-x"), ("lm_studio", "my-model-x")):+ assert model_route(provider, model)["model"] == "custom", (provider, model)for provider, model in (("bedrock", "anthropic.claude-3-5-sonnet-20241022-v2:0"),("openrouter", "openai/gpt-4o:free"), ("ollama-cloud", "gpt-oss:120b")):assert model_route(provider, model)["model"] == model