Skip to content

The agent that grows with you

feat(telemetry): decision-data docs, consent copy, smoke coverage and install-age for new installs

teknium13d62ae223373
diff --git a/hermes_cli/observability/shared_metrics_snapshot.py b/hermes_cli/observability/shared_metrics_snapshot.py
index 95aa2147079..1a439ac6547 100644
--- a/hermes_cli/observability/shared_metrics_snapshot.py
+++ b/hermes_cli/observability/shared_metrics_snapshot.py
@@ -87,27 +87,35 @@ _first_session_at: dict[str, float] = {}
def _first_session_started_at() -> float | None:
- home = str(get_hermes_home())
- if home not in _first_session_at:
- try:
- with contextlib.closing(
- sqlite3.connect(f"file:{get_hermes_home() / 'state.db'}?mode=ro", uri=True, timeout=1)
- ) as connection:
- row = connection.execute("SELECT MIN(started_at) FROM sessions").fetchone()
- except sqlite3.Error:
- return None
- if not row or row[0] is None:
- return None
- _first_session_at[home] = float(row[0])
- return _first_session_at[home]
+ """Epoch of the profile's first session; ``now`` when it has none yet (a brand-new install).
+
+ Raises ``sqlite3.Error`` when state.db exists but cannot be read.
+ """
+ home = get_hermes_home()
+ if str(home) in _first_session_at:
+ return _first_session_at[str(home)]
+ database = home / "state.db"
+ if not database.exists():
+ return time.time()
+ with contextlib.closing(
+ sqlite3.connect(f"file:{database}?mode=ro", uri=True, timeout=1)
+ ) as connection:
+ row = connection.execute("SELECT MIN(started_at) FROM sessions").fetchone()
+ if not row or row[0] is None:
+ return time.time()
+ _first_session_at[str(home)] = float(row[0])
+ return _first_session_at[str(home)]
def install_age_bucket() -> str:
- """How long ago this profile's first-ever session started, bucketed; ``unknown`` if none yet."""
+ """How long ago this profile's first-ever session started, bucketed; ``unknown`` if unreadable."""
from .shared_metrics_fields import install_age_bucket as bucket
- first = _first_session_started_at()
- return "unknown" if first is None else bucket(time.time() - first)
+ try:
+ first = _first_session_started_at()
+ except sqlite3.Error:
+ return "unknown"
+ return bucket(time.time() - first)
def collect_install_snapshot(config: dict[str, Any]) -> dict[str, str]:
diff --git a/hermes_cli/setup.py b/hermes_cli/setup.py
index 331a4f8aa10..09240768e23 100644
--- a/hermes_cli/setup.py
+++ b/hermes_cli/setup.py
@@ -523,9 +523,10 @@ _SEND_CONSENT_EXPLAINER = (
def setup_telemetry(config: dict):
"""Configure the local shared-metrics subscriber and optional sending."""
print_header("Shared Metrics")
- _info("Shared metrics contain only bounded counters: activity, outcomes, error",
- "classes, model routes and built-in tool names. Never prompts, files or error text.",
- "Collection is local. Sending them to Nous is a separate opt-in.")
+ _info("Shared metrics contain only bounded counters: activity, session length,",
+ "outcomes, error classes, model routes and token totals, built-in tool, command",
+ "and catalog names, and bucketed setup counts. Never prompts, files, paths or",
+ "error text. Collection is local. Sending them to Nous is a separate opt-in.")
shared_metrics = _sub_dict(_sub_dict(config, "telemetry"), "shared_metrics")
current = shared_metrics.get("enabled") is True
shared_metrics["enabled"] = prompt_yes_no("Enable local shared metrics?", default=current)
diff --git a/scripts/smoke_nemo_relay_shared_metrics.py b/scripts/smoke_nemo_relay_shared_metrics.py
index cc0feed31ca..a0c26ec3219 100644
--- a/scripts/smoke_nemo_relay_shared_metrics.py
+++ b/scripts/smoke_nemo_relay_shared_metrics.py
@@ -302,8 +302,11 @@ def _validate_store(database_path: Path) -> list[dict[str, Any]]:
by_name.setdefault(counter["name"], []).append(counter)
if set(by_name) != {
"hermes.client.active",
+ "hermes.install.milestone",
"hermes.install.snapshot",
"hermes.model_route.count",
+ "hermes.model_tokens.sum",
+ "hermes.session.count",
"hermes.skill.lifecycle.count",
"hermes.skill.load.count",
"hermes.task_run.finished",
@@ -334,6 +337,7 @@ def _validate_store(database_path: Path) -> list[dict[str, Any]]:
"model": MODEL_CANARY,
"outcome": "success",
"provider": "custom",
+ "ttft_bucket": "lt_500ms",
},
"value": 2,
"packaged_value": 2,
@@ -383,6 +387,17 @@ def _validate_store(database_path: Path) -> list[dict[str, Any]]:
[snapshot] = by_name["hermes.install.snapshot"]
if snapshot["value"] != 1 or snapshot["dimensions"]["memory_provider"] != "builtin":
raise AssertionError(f"Unexpected install snapshot: {snapshot}")
+ [session] = by_name["hermes.session.count"]
+ if (session["dimensions"]["turn_count_bucket"], session["dimensions"]["last_outcome"]) != (
+ "1", "success",
+ ):
+ raise AssertionError(f"Unexpected session summary: {session}")
+ tokens = {c["dimensions"]["token_type"]: c["value"] for c in by_name["hermes.model_tokens.sum"]}
+ if tokens != {"input": 20, "output": 2}:
+ raise AssertionError(f"Unexpected token sums: {by_name['hermes.model_tokens.sum']}")
+ milestones = {c["dimensions"]["milestone"] for c in by_name["hermes.install.milestone"]}
+ if not {"first_task_started", "first_task_success", "first_tool_success"} <= milestones:
+ raise AssertionError(f"Missing install milestones: {sorted(milestones)}")
[tool] = by_name["hermes.tool_call.count"]
expected_tool_dimensions = {
"approval_outcome": "not_required",
@@ -486,8 +501,11 @@ def _validate_packages(
metrics.setdefault(metric["name"], []).append(metric)
if set(metrics) != {
"hermes.client.active",
+ "hermes.install.milestone",
"hermes.install.snapshot",
"hermes.model_route.count",
+ "hermes.model_tokens.sum",
+ "hermes.session.count",
"hermes.skill.lifecycle.count",
"hermes.skill.load.count",
"hermes.task_run.finished",
@@ -516,6 +534,7 @@ def _validate_packages(
"model": MODEL_CANARY,
"outcome": "success",
"provider": "custom",
+ "ttft_bucket": "lt_500ms",
} or model["value"] != 2:
raise AssertionError(
f"Unexpected model metric: {metrics['hermes.model_route.count']}"
diff --git a/tests/hermes_cli/test_relay_shared_metrics_runtime.py b/tests/hermes_cli/test_relay_shared_metrics_runtime.py
index 51f36ecc34f..360b309402d 100644
--- a/tests/hermes_cli/test_relay_shared_metrics_runtime.py
+++ b/tests/hermes_cli/test_relay_shared_metrics_runtime.py
@@ -2761,3 +2761,65 @@ def test_install_snapshot_is_daily_and_carries_only_bucketed_counts(
"profile_count_bucket": snapshot["profile_count_bucket"], "skill_count_bucket": "0",
"terminal_backend": "local",
}
+
+
+def _stored_values(tmp_path, metric: str) -> list[tuple[dict[str, Any], int]]:
+ from hermes_cli.observability.shared_metrics import SharedMetricsStore
+
+ root = tmp_path / "hermes-home" / "telemetry" / "shared_metrics"
+ return [
+ (counter["dimensions"], counter["value"])
+ for counter in SharedMetricsStore(root / "metrics.sqlite3", root / "outbox").counter_snapshot()
+ if counter["metric_name"] == metric
+ ]
+
+
+def test_sessions_summarize_on_close_and_milestones_latch_once_per_install(direct_runtime, tmp_path):
+ """Each closed session yields one bucketed summary; delegated children do not; an install
+ milestone is recorded the first time only, however many sessions reach it."""
+ for session_id, turns in (("s1", 3), ("s2", 1)):
+ for turn in range(turns):
+ task = f"{session_id}-t{turn}"
+ lifecycle.invoke_hook("pre_llm_call", session_id=session_id, task_id=task, platform="cli")
+ relay_shared_metrics.finish_task_run(
+ session_id=session_id, task_id=task, platform="cli", result={"completed": True},
+ )
+ lifecycle.finalize_session(session_id=session_id)
+
+ sessions = _stored_values(tmp_path, "hermes.session.count")
+ assert sorted((d["turn_count_bucket"], d["last_outcome"], v) for d, v in sessions) == [
+ ("1", "success", 1), ("3_to_5", "success", 1),
+ ]
+ milestones = {d["milestone"]: v for d, v in _stored_values(tmp_path, "hermes.install.milestone")}
+ assert milestones["first_task_started"] == 1
+ assert milestones["first_task_success"] == 1
+
+
+def test_token_usage_is_summed_per_model_and_auxiliary_task(direct_runtime, tmp_path):
+ base = {"session_id": "s1", "task_id": "t1", "provider": "anthropic", "model": "claude-sonnet"}
+ for request_id in ("r1", "r2"):
+ lifecycle.invoke_hook("pre_api_request", **base, api_request_id=request_id)
+ lifecycle.invoke_hook(
+ "post_api_request", **base, api_request_id=request_id,
+ usage={"input_tokens": 100, "output_tokens": 10, "cache_read_tokens": 40},
+ )
+ for aux_task in ("compression", "acme-private-task"):
+ lifecycle.invoke_hook(
+ "post_auxiliary_call", aux_task=aux_task, provider="openrouter", model="small/model",
+ usage={"input_tokens": 7, "output_tokens": 3},
+ )
+ relay_shared_metrics.finish_task_run(
+ session_id="s1", task_id="t1", platform="cli", result={"completed": True},
+ )
+ lifecycle.finalize_session(session_id="s1")
+
+ sums = {
+ (d["call_role"], d["aux_task"], d["token_type"]): v
+ for d, v in _stored_values(tmp_path, "hermes.model_tokens.sum")
+ }
+ assert sums == {
+ ("primary", "none", "input"): 200, ("primary", "none", "output"): 20,
+ ("primary", "none", "cache_read"): 80,
+ ("auxiliary", "compression", "input"): 7, ("auxiliary", "compression", "output"): 3,
+ ("auxiliary", "other", "input"): 7, ("auxiliary", "other", "output"): 3,
+ }
diff --git a/website/docs/developer-guide/relay-shared-metrics.md b/website/docs/developer-guide/relay-shared-metrics.md
index 75e9baeb345..ee0984ed7e9 100644
--- a/website/docs/developer-guide/relay-shared-metrics.md
+++ b/website/docs/developer-guide/relay-shared-metrics.md
@@ -236,23 +236,53 @@ remains in the task's tool-count bucket.
Successful skill mutations emit `hermes.skill.lifecycle` marks with only a
bounded action and provenance. Successful loads emit `hermes.skill.load`
marks with bounded provenance, first-use or reuse state, reuse-after-patch
-state, and a use-count bucket. Hermes derives reuse and patch-generation
-continuity transactionally in its existing `skills/.usage.json` state; skill
-names and exact counts or generations never enter Relay metrics events,
-SQLite dimensions, or packages. A use after a new patch is counted once as
+state, a use-count bucket and `skill_name`: the skill's name only when it is a
+skill Hermes ships (`skills/` or `optional-skills/`), otherwise `custom`. Hermes
+derives reuse and patch-generation continuity transactionally in its existing
+`skills/.usage.json` state; local or agent-created skill names and exact counts
+or generations never enter Relay metrics events, SQLite dimensions, or packages. A use after a new patch is counted once as
`reused_after_patch`; later uses remain ordinary reuse until another patch.
Task-outcome attribution after a patch remains deferred until its window and
multi-skill semantics are defined.
Once per rolling 24 hours, the first activation also emits a
`hermes.install.snapshot` mark describing how the profile is configured: the
-memory provider (a bundled provider name, `builtin`, or `plugin`) and bucketed
-counts of MCP servers, enabled plugins, installed skills, enabled cron jobs and
-profiles. Server, plugin, skill, job and profile names are never read into the
-event. The same compare-and-set latch as `hermes.client.active` keeps it to one
+memory provider (a bundled provider name, `builtin`, or `plugin`), bucketed
+counts of MCP servers, enabled plugins, installed skills, enabled cron jobs,
+profiles and connected messaging platforms, the main provider id, the terminal
+backend (`local`, `docker`, `ssh`, ... or `other`), the display language (a
+shipped locale or `other`) and `install_age_bucket`: how long ago the profile's
+first-ever session started. Install age is what lets the backend tell a new user
+from an existing one who just opted in. Server, plugin, skill, job and profile
+names are never read into the event. The same compare-and-set latch as `hermes.client.active` keeps it to one
row per install per day, and the producer checks the latch before walking the
skills tree.
+### Decision-data metrics
+
+These answer product questions the activity counters cannot: what makes people
+stay, where new users drop off, which surfaces and models carry real usage, and
+which extensions are worth investing in. Every dimension is a closed enum, a
+bucket, a provider/model identifier (as on model routes) or a public name Nous
+itself ships.
+
+| Metric | Dimensions | Question it answers |
+|---|---|---|
+| `hermes.session.count` | entrypoint, surface, platform, turn/failed-turn buckets, active-duration bucket, last outcome | How deep is real usage per surface; do sessions end right after a failure? |
+| `hermes.install.milestone` | milestone, install age bucket | How long from install to first success, first gateway message, first cron run, first delegation, first created skill, first long session? Recorded once per install. |
+| `hermes.setup.completed` | surface (`cli`/`desktop`), provider | Which providers people choose at setup, and on which surface. |
+| `hermes.model_tokens.sum` | call role, model, provider, auxiliary task, token type | Token volume per model/provider, prompt-cache share, and what auxiliary work (compression, titles, vision, ...) costs. The value is a token sum, not an event count. |
+| `hermes.model_route.count` `ttft_bucket` | time to first token | Perceived latency per provider/model. |
+| `hermes.compression.count` | trigger, outcome, context-fill bucket | How often compaction runs, how full contexts get, and whether it fails. |
+| `hermes.model_switch.count` | from/to provider, surface | Which providers people leave and move to. |
+| `hermes.fallback.count` | from/to provider, error class | How often fallback providers rescue a turn, and from what. |
+| `hermes.slash_command.count` | command, surface | Which built-in commands are used (`/retry`, `/undo`, `/new` are friction signals). Skill and plugin commands report `skill`/`plugin`. |
+| `hermes.extension.install.count` | kind, source, name, outcome | Which catalog skills, MCP servers and plugins get installed. `name` is a bundled/optional skill, `optional-mcps/` or `plugin-catalog/` entry, otherwise `custom`. |
+
+Sessions are summarized when they close (finalize, reset or process exit);
+delegated child sessions are not counted separately. Milestones latch in the
+local database, so each fires once per install however many processes reach it.
+
Local state is written under:
```text