Skip to content

The agent that grows with you

fix(telemetry): Desktop provider-connection forms count Gemini/xAI/DeepInfra keys again (M13)

teknium13ba7c850ba6e
diff --git a/apps/desktop/src/api/config.ts b/apps/desktop/src/api/config.ts
index d17f4a4d2e8..9548b7f2d1b 100644
--- a/apps/desktop/src/api/config.ts
+++ b/apps/desktop/src/api/config.ts
@@ -208,12 +208,19 @@ export function getEnvVars(profile?: null | string): Promise<Record<string, EnvV
})
}
-export function setEnvVar(key: string, value: string, profile?: ProfileScope): Promise<{ ok: boolean }> {
+// `providerSetup`: the caller is connecting a model provider, so shared metrics count the save as a
+// provider setup even when a tool panel uses the same key (Gemini, xAI...).
+export function setEnvVar(
+ key: string,
+ value: string,
+ profile?: ProfileScope,
+ { providerSetup = false }: { providerSetup?: boolean } = {}
+): Promise<{ ok: boolean }> {
return window.hermesDesktop.api<{ ok: boolean }>({
...capabilityScoped(profile),
path: '/api/env',
method: 'PUT',
- body: { key, value }
+ body: providerSetup ? { key, provider_setup: true, value } : { key, value }
})
}
diff --git a/apps/desktop/src/app/settings/model-settings.tsx b/apps/desktop/src/app/settings/model-settings.tsx
index 1c6d7ebe45d..2f6e70d569c 100644
--- a/apps/desktop/src/app/settings/model-settings.tsx
+++ b/apps/desktop/src/app/settings/model-settings.tsx
@@ -677,7 +677,7 @@ export function ModelSettings({ onMainModelChanged, scopeProfile, subpage }: Mod
setError('')
try {
- await setEnvVar(keyEnv, apiKeyDraft.trim(), scopeProfile)
+ await setEnvVar(keyEnv, apiKeyDraft.trim(), scopeProfile, { providerSetup: true })
setApiKeyDraft('')
// Pick a sensible default for the freshly-activated provider (mirrors
diff --git a/apps/desktop/src/store/onboarding.ts b/apps/desktop/src/store/onboarding.ts
index 3368a801a0d..64913e8cdce 100644
--- a/apps/desktop/src/store/onboarding.ts
+++ b/apps/desktop/src/store/onboarding.ts
@@ -1069,7 +1069,7 @@ export async function saveOnboardingApiKey(
// provider probes, self-hosted endpoints). We now save the value as-is and
// let the user proceed; an actually-bad key surfaces later at chat time.
try {
- await setEnvVar(envKey, trimmed, ctx.scope)
+ await setEnvVar(envKey, trimmed, ctx.scope, { providerSetup: true })
if (generation !== flowGeneration) {
return { ok: false }
diff --git a/hermes_cli/observability/shared_metrics_setup.py b/hermes_cli/observability/shared_metrics_setup.py
index bb11d1179ad..9a2d2e1097f 100644
--- a/hermes_cli/observability/shared_metrics_setup.py
+++ b/hermes_cli/observability/shared_metrics_setup.py
@@ -253,25 +253,26 @@ def record_provider_setup_done(surface: str, provider: Any, *, hermes_home: Any
logger.debug("Provider setup not recorded", exc_info=True)
-def provider_for_api_key_env(env_var: Any) -> str | None:
+def provider_for_api_key_env(env_var: Any, *, connecting: bool = False) -> str | None:
"""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."""
+ key save cannot tell connecting a provider from configuring a tool, so unless the caller says it is
+ ``connecting`` one, 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(
+ if not connecting and (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, value: Any, previous: Any, surface: str) -> None:
+def record_api_key_saved(env_var: Any, value: Any, previous: Any, surface: str, *, connecting: bool = False) -> 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:
@@ -279,7 +280,7 @@ def record_api_key_saved(env_var: Any, value: Any, previous: Any, surface: str)
if not isinstance(value, str) or not value.strip() or value == previous:
return
- if enabled() and (provider := provider_for_api_key_env(env_var)):
+ if enabled() and (provider := provider_for_api_key_env(env_var, connecting=connecting)):
record_provider_setup_done(surface, provider, background=True)
except Exception:
logger.debug("API key setup not recorded", exc_info=True)
diff --git a/hermes_cli/web_models.py b/hermes_cli/web_models.py
index 33747afa7c2..29f1fd3572b 100644
--- a/hermes_cli/web_models.py
+++ b/hermes_cli/web_models.py
@@ -19,6 +19,9 @@ class EnvVarUpdate(BaseModel):
# Bearer for the OPENAI_BASE_URL connectivity probe (auth-gated /v1/models otherwise looks
# "reachable but empty"); ignored by plain PUT /api/env.
api_key: str = ""
+ # Sent by the Desktop's provider-connection forms: a key a tool panel also asks for (Gemini,
+ # xAI...) then still counts as a provider setup in shared metrics.
+ provider_setup: bool = False
class EnvVarDelete(BaseModel):
key: str
diff --git a/hermes_cli/web_routers/config_env.py b/hermes_cli/web_routers/config_env.py
index 6758abaabb6..94c1b2eb35a 100644
--- a/hermes_cli/web_routers/config_env.py
+++ b/hermes_cli/web_routers/config_env.py
@@ -335,10 +335,10 @@ async def set_env_var(body: EnvVarUpdate, profile: Optional[str] = None):
if is_redacted_credential_preview(body.value):
raise HTTPException(status_code=400, detail=REDACTED_CREDENTIAL_WRITE_DETAIL)
with _env_write_errors("PUT /api/env failed"):
- return await scoped_to_thread(body.profile or profile, lambda: _save_env_credential(body.key, body.value))
+ return await scoped_to_thread(body.profile or profile, lambda: _save_env_credential(body.key, body.value, body.provider_setup))
-def _save_env_credential(key: str, value: str) -> Any:
+def _save_env_credential(key: str, value: str, provider_setup: bool = False) -> Any:
"""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
@@ -346,7 +346,7 @@ def _save_env_credential(key: str, value: str) -> Any:
previous = load_env().get(key)
result = save_provider_env_credential(key, value)
- record_api_key_saved(key, value, previous, web_setup_surface())
+ record_api_key_saved(key, value, previous, web_setup_surface(), connecting=provider_setup)
return result
diff --git a/tests/hermes_cli/test_shared_metrics_signals.py b/tests/hermes_cli/test_shared_metrics_signals.py
index 1dcd12bf1af..eb9162aecde 100644
--- a/tests/hermes_cli/test_shared_metrics_signals.py
+++ b/tests/hermes_cli/test_shared_metrics_signals.py
@@ -320,10 +320,12 @@ def test_web_forms_count_only_a_new_provider_key_or_endpoint(marks, monkeypatch)
("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)
+ config_env._save_env_credential("GEMINI_API_KEY", "gm-a") # Keys page: could be the TTS tool's key
+ config_env._save_env_credential("GEMINI_API_KEY", "gm-b", provider_setup=True) # a provider-connection form
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"]
+ assert done == ["openrouter", "openrouter", "gemini", "custom"]
# ---- feature disabled ----
diff --git a/website/docs/developer-guide/relay-shared-metrics.md b/website/docs/developer-guide/relay-shared-metrics.md
index 0b04539c2e3..7d5c7dbd025 100644
--- a/website/docs/developer-guide/relay-shared-metrics.md
+++ b/website/docs/developer-guide/relay-shared-metrics.md
@@ -449,7 +449,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. A built-in the session enabled but deferred behind `tool_search` (reachable through `tool_call`) is not unavailable. Background reviews, delegated children and cron jobs, 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`. 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.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 (the Desktop's onboarding and model settings mark their saves as a provider connection, so those count). 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 skill created at the user's request (not by Hermes' background review), a successful MCP/plugin/browser/TTS/kanban tool call, a Desktop/TUI/gateway task, a cron run, a manual curator run; the scheduled curator pass does not count) 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, even when a migration runs inside one of them (`hermes config migrate`, a profile created from the dashboard). A setting whose value is a `${VAR}` template is not compared. The diff and the record run on a background thread after the write, outside every config lock. At most once per (kind, name, event) per day. |
<!-- ---- end v5 signals ---- -->