Skip to content

The agent that grows with you

fix(telemetry): provider_setup counts only a new provider credential or endpoint (M13, m18)

teknium141ce3104a78a
diff --git a/hermes_cli/observability/shared_metrics_setup.py b/hermes_cli/observability/shared_metrics_setup.py
index 98aa4ba964b..bb11d1179ad 100644
--- a/hermes_cli/observability/shared_metrics_setup.py
+++ b/hermes_cli/observability/shared_metrics_setup.py
@@ -34,6 +34,8 @@ STALE_AFTER_S = 3600
_NOT_A_PROVIDER = frozenset({"aux-config", "cancel", "reasoning", "remove-custom"})
_AUTH_ERROR_TYPES = frozenset({"AuthError", "SignInCopyError"})
_OAUTH_SESSION_KEY = "_metrics_setup_flow"
+# Tokens other tools read too (gh, the Hugging Face Hub): saving one is not connecting that provider.
+_SHARED_TOKENS = frozenset({"GH_TOKEN", "GITHUB_TOKEN", "HF_TOKEN"})
# OAuth session status (+ reason) at its end -> (event, failure_class).
_OAUTH_ENDINGS = {
"approved": ("completed", "none"),
@@ -252,20 +254,31 @@ def record_provider_setup_done(surface: str, provider: Any, *, hermes_home: Any
def provider_for_api_key_env(env_var: Any) -> str | None:
- """The shipped provider whose API key lives in ``env_var``; None for any other variable."""
+ """The shipped provider whose own API key lives in ``env_var``; None for any other variable. A bare
+ key save cannot tell connecting a provider from configuring a tool, so ecosystem tokens and keys a
+ tool's settings panel (TTS, STT, image...) also asks for are None too."""
from hermes_cli.auth import PROVIDER_REGISTRY
+ from hermes_cli.tools_config import TOOL_CATEGORIES
if env_var == "OPENROUTER_API_KEY": # the aggregator is not a registry entry
return "openrouter"
+ if env_var in _SHARED_TOKENS or any(
+ env_var == entry.get("key") for category in TOOL_CATEGORIES.values()
+ for row in category.get("providers", ()) for entry in row.get("env_vars") or ()
+ ):
+ return None
return next((slug for slug, pconfig in PROVIDER_REGISTRY.items()
if env_var in (getattr(pconfig, "api_key_env_vars", None) or ())), None)
-def record_api_key_saved(env_var: Any, surface: str) -> None:
- """Count a provider API key saved from a settings form (other variables are not setups)."""
+def record_api_key_saved(env_var: Any, value: Any, previous: Any, surface: str) -> None:
+ """Count a provider API key saved from a settings form: only a new or changed non-empty value (a
+ clear or a same-value re-save connects nothing; other variables are not setups)."""
try:
from .relay_shared_metrics import enabled
+ if not isinstance(value, str) or not value.strip() or value == previous:
+ return
if enabled() and (provider := provider_for_api_key_env(env_var)):
record_provider_setup_done(surface, provider, background=True)
except Exception:
diff --git a/hermes_cli/web_routers/config_env.py b/hermes_cli/web_routers/config_env.py
index f945a4f94f6..6758abaabb6 100644
--- a/hermes_cli/web_routers/config_env.py
+++ b/hermes_cli/web_routers/config_env.py
@@ -339,12 +339,14 @@ async def set_env_var(body: EnvVarUpdate, profile: Optional[str] = None):
def _save_env_credential(key: str, value: str) -> Any:
- """Save under the request's profile scope; a provider API key also counts as a provider setup."""
+ """Save under the request's profile scope; a new provider API key also counts as a provider setup."""
+ from hermes_cli.config import load_env
from hermes_cli.credential_lifecycle import save_provider_env_credential
from hermes_cli.observability.shared_metrics_setup import record_api_key_saved, web_setup_surface
+ previous = load_env().get(key)
result = save_provider_env_credential(key, value)
- record_api_key_saved(key, web_setup_surface())
+ record_api_key_saved(key, value, previous, web_setup_surface())
return result
@@ -724,12 +726,16 @@ def upsert_custom_endpoint(body: CustomEndpointUpdate, profile: Optional[str] =
# drop this write (or vice versa).
with _config_profile_scope(profile), _CONFIG_MUTATION_LOCK:
cfg = load_config()
+ providers = cfg.get("providers")
+ created = _resolve_custom_endpoint_entry(
+ providers if isinstance(providers, dict) else {}, body.id or body.name)[1] is None
endpoint_id, _entry = _write_custom_endpoint(cfg, body)
save_config(cfg)
response = _custom_endpoint_response(cfg)
from hermes_constants import get_hermes_home
home = get_hermes_home()
- _record_custom_endpoint_setup(home)
+ if created: # editing an endpoint that exists sets nothing new up
+ _record_custom_endpoint_setup(home)
response["ok"] = True
response["id"] = endpoint_id
return response
diff --git a/tests/hermes_cli/test_shared_metrics_signals.py b/tests/hermes_cli/test_shared_metrics_signals.py
index 8e9f0c8bb61..2287b510d09 100644
--- a/tests/hermes_cli/test_shared_metrics_signals.py
+++ b/tests/hermes_cli/test_shared_metrics_signals.py
@@ -266,6 +266,27 @@ def test_pending_oauth_session_does_not_settle(marks, monkeypatch):
def test_api_key_env_maps_to_provider_only():
assert setup_metrics.provider_for_api_key_env("OPENROUTER_API_KEY") == "openrouter"
assert setup_metrics.provider_for_api_key_env("GITHUB_TOKEN_FOR_TOOLS_XYZ") is None
+ # Ecosystem tokens and keys a tool panel also asks for (Gemini TTS) are not a provider connection.
+ for shared in ("GITHUB_TOKEN", "GH_TOKEN", "HF_TOKEN", "GEMINI_API_KEY"):
+ assert setup_metrics.provider_for_api_key_env(shared) is None
+
+
+def test_web_forms_count_only_a_new_provider_key_or_endpoint(marks, monkeypatch):
+ from hermes_cli.web_models import CustomEndpointUpdate
+ from hermes_cli.web_routers import config_env
+
+ done: list[str] = []
+ monkeypatch.setattr(setup_metrics, "record_provider_setup_done", lambda _s, provider, **_k: done.append(provider))
+ monkeypatch.setattr(setup_metrics, "web_setup_surface", lambda: "dashboard")
+ marks.home.mkdir(parents=True, exist_ok=True)
+ for key, value in (("OPENROUTER_API_KEY", "sk-or-a"), ("OPENROUTER_API_KEY", "sk-or-a"), # re-save
+ ("OPENROUTER_API_KEY", ""), ("OPENROUTER_API_KEY", "sk-or-b"), # clear, then a new key
+ ("GITHUB_TOKEN", "ghp_" + "b" * 36)):
+ config_env._save_env_credential(key, value)
+ body = {"name": "Acme LLM", "base_url": "http://10.0.0.5:8080/v1", "model": "acme-70b"}
+ endpoint = config_env.upsert_custom_endpoint(CustomEndpointUpdate(**body))["id"]
+ config_env.upsert_custom_endpoint(CustomEndpointUpdate(id=endpoint, **{**body, "model": "acme-70b-v2"}))
+ assert done == ["openrouter", "openrouter", "custom"]
# ---- feature disabled ----
diff --git a/tui_gateway/methods_complete.py b/tui_gateway/methods_complete.py
index b3b767d7964..a1a6bc518fc 100644
--- a/tui_gateway/methods_complete.py
+++ b/tui_gateway/methods_complete.py
@@ -369,12 +369,15 @@ def _(rid, params: dict) -> dict:
# Save the key to ~/.hermes/.env via the unified credential lifecycle so any stale config.yaml mirror of
# the previous key (model.api_key, custom_providers[*].api_key) is rotated in the same action (#62269).
env_var = pconfig.api_key_env_vars[0]
+ from hermes_cli.config import load_env
from hermes_cli.credential_lifecycle import save_provider_env_credential # also rotates stale config.yaml mirrors
+ previous = load_env().get(env_var)
# Under the profile scope the save publishes into the addressed profile's secret scope (and the
# shared os.environ only for the launch profile), so the refreshed inventory below sees it.
save_provider_env_credential(env_var, api_key)
- from hermes_cli.observability.shared_metrics_setup import record_provider_setup_done
- record_provider_setup_done(_resolve_session_platform(), slug, background=True)
+ if api_key != previous: # a same-key re-save connects nothing new
+ from hermes_cli.observability.shared_metrics_setup import record_provider_setup_done
+ record_provider_setup_done(_resolve_session_platform(), slug, background=True)
# The launch profile's boot record may still say "nothing configured"; the gated picker's own chat
# waits on setup.status, so the fresh key must move the record (+ setup.ready). reconcile_record
# leaves it alone when the bound home is another profile's.
diff --git a/website/docs/developer-guide/relay-shared-metrics.md b/website/docs/developer-guide/relay-shared-metrics.md
index 5e5773050fc..3a5e6f46809 100644
--- a/website/docs/developer-guide/relay-shared-metrics.md
+++ b/website/docs/developer-guide/relay-shared-metrics.md
@@ -443,7 +443,7 @@ database and the count is not reported.
| Metric | Dimensions | Question it answers |
|---|---|---|
| `hermes.tool_unavailable.count` | provider, model, tool name (shipped built-ins only) | Which toolsets should be on by default: the model called a tool Hermes ships that this session did not enable. Any other unknown name (plugin, MCP, hallucinated) stays a `model_tool_quality` `unknown_tool` issue only. Background reviews and delegated children, whose toolsets are narrowed on purpose, are excluded. |
-| `hermes.provider_setup.count` | provider (catalog name; custom endpoints read `custom`), surface (`cli_setup`, `cli_model`, `tui`, `desktop`, `dashboard`), event (`started`, `completed`, `failed`, `abandoned`), failure class (`auth`, `network`, `no_models`, `cancelled`, `other`; `none` unless failed) | Where connecting a provider breaks down. `started` counts once a provider is picked; the flow's end is recorded by the surface that ran it. In the CLI pickers Esc ends the flow `failed`/`cancelled`; Back (Left arrow) keeps it open, so picking the same provider again continues it (one `started`), while picking another provider or leaving the command ends it `cancelled`. A flow nobody finished leaves a local marker that the next setup start or Hermes start in the profile reports as `abandoned` (its process is gone, or it has been pending over an hour); an OAuth device code left to expire is also `abandoned`. API keys saved from a form (TUI/Desktop/dashboard) and custom endpoints start and complete in one action. Never a key, token, base URL or error text. Leaving the provider picker before choosing one is not counted. |
+| `hermes.provider_setup.count` | provider (catalog name; custom endpoints read `custom`), surface (`cli_setup`, `cli_model`, `tui`, `desktop`, `dashboard`), event (`started`, `completed`, `failed`, `abandoned`), failure class (`auth`, `network`, `no_models`, `cancelled`, `other`; `none` unless failed) | Where connecting a provider breaks down. `started` counts once a provider is picked; the flow's end is recorded by the surface that ran it. In the CLI pickers Esc ends the flow `failed`/`cancelled`; Back (Left arrow) keeps it open, so picking the same provider again continues it (one `started`), while picking another provider or leaving the command ends it `cancelled`. A flow nobody finished leaves a local marker that the next setup start or Hermes start in the profile reports as `abandoned` (its process is gone, or it has been pending over an hour); an OAuth device code left to expire is also `abandoned`. A new or changed provider API key saved from a form (TUI/Desktop/dashboard) and a newly added custom endpoint start and complete in one action; clearing a key, re-saving the same key, editing an existing endpoint, ecosystem tokens (`GITHUB_TOKEN`, `GH_TOKEN`, `HF_TOKEN`) and keys a tool's settings panel also asks for (e.g. `GEMINI_API_KEY`, `XAI_API_KEY`, `DEEPINFRA_API_KEY`) are not counted from the generic key form. Never a key, token, base URL or error text. Leaving the provider picker before choosing one is not counted. |
| `hermes.feature_adoption.count` | feature (`memory`, `skills_created`, `delegation`, `cron`, `gateway_platform`, `desktop`, `tui`, `mcp`, `plugins`, `browser`, `voice`, `kanban`, `projects`, `bot_mode`, `curator`), days since install (`same_day`, `1d_to_7d`, `7d_to_30d`, `30d_to_90d`, `gte_90d`, `unknown`) | How long after install each major feature is first really used. Once per feature per install, latched in the local database, derived from the counters above (a foreground memory write, a created skill, a successful MCP/plugin/browser/TTS/kanban tool call, a Desktop/TUI/gateway task, a cron run, a curator run) plus direct first-use reports for Bot Mode messages and project creation. The age is the owning profile's (its first session). |
| `hermes.feature_disabled.count` | kind (`toolset`, `skill`, `plugin`, `platform`, `setting`, `memory`, `curator`, `compression`), name, surface (`cli_tools`, `cli_config`, `cli_slash`, `tui`, `desktop`, `dashboard`), event (`disabled`, `re_enabled`) | What users turn off. Diffed at the config write itself: a default-on toolset removed, a skill or plugin added to its disabled list, a default-`true` setting set false (and each moved back). Names are public only when shipped — toolset key, bundled/catalog skill, bundled/catalog plugin (messaging-platform plugins report as `platform`), `DEFAULT_CONFIG` key path (never a value) — else `custom`. Uninstalling a catalog skill counts as `disabled`. Only user entry points record (`hermes tools` / `config` / `skills` / `plugins`, chat slash commands, TUI/Desktop, dashboard); setup and migrations do not. At most once per (kind, name, event) per day. |
<!-- ---- end v5 signals ---- -->