Skip to content

The agent that grows with you

fix(dashboard): count distinct models over the merged row set

Zac Lanzon0cc2bcdcee73
diff --git a/hermes_cli/web_routers/analytics.py b/hermes_cli/web_routers/analytics.py
index d77175edf21..f0ee7e12f3c 100644
--- a/hermes_cli/web_routers/analytics.py
+++ b/hermes_cli/web_routers/analytics.py
@@ -386,8 +386,7 @@ def _get_models_analytics(days: int = 30, profile: Optional[str] = None):
]
totals = _rows(db, """
- SELECT COUNT(DISTINCT model) as distinct_models,
- SUM(input_tokens) as total_input,
+ SELECT SUM(input_tokens) as total_input,
SUM(output_tokens) as total_output,
SUM(cache_read_tokens) as total_cache_read,
SUM(reasoning_tokens) as total_reasoning,
@@ -397,6 +396,10 @@ def _get_models_analytics(days: int = 30, profile: Optional[str] = None):
SUM(COALESCE(api_call_count, 0)) as total_api_calls
FROM sessions WHERE started_at > ? AND model IS NOT NULL AND model != ''
""", cutoff)[0]
+ # Counted over the same merged row set the cards come from, so a model
+ # reached only through auxiliary usage is in the header as well as on
+ # the page (#89631).
+ totals["distinct_models"] = len({row["model"] for row in rows})
return {"models": models, "totals": totals, "period_days": days}
finally:
diff --git a/tests/hermes_cli/test_models_analytics_dedup.py b/tests/hermes_cli/test_models_analytics_dedup.py
index 8eda4f77581..1f1dd9264dc 100644
--- a/tests/hermes_cli/test_models_analytics_dedup.py
+++ b/tests/hermes_cli/test_models_analytics_dedup.py
@@ -77,3 +77,22 @@ def test_aux_only_model_still_gets_its_own_row(db, analytics):
assert ("gemini-3-flash", "gemini") in pairs
assert ("gpt-5.6-terra", "openai-codex") in pairs
+
+
+def test_distinct_models_counts_aux_only_models(db, analytics):
+ """The header count and the card list are two views of one row set.
+
+ ``totals.distinct_models`` was a ``COUNT(DISTINCT model)`` over ``sessions``
+ alone, so a model reached only through auxiliary usage drew a card the
+ header never counted (#89631).
+ """
+ _session(db, "s1", "gpt-5.6-terra", "openai-codex")
+ db.record_auxiliary_usage(
+ "s1", "title_generation", model="gpt-5.4-mini", billing_provider="openai-codex",
+ input_tokens=50, output_tokens=5,
+ )
+
+ result = analytics()
+
+ assert {m["model"] for m in result["models"]} == {"gpt-5.6-terra", "gpt-5.4-mini"}
+ assert result["totals"]["distinct_models"] == len({m["model"] for m in result["models"]})