Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(dashboard): align token savings headline denominator (#1653)

Chris Yau646e70551436
diff --git a/headroom/dashboard/templates/dashboard.html b/headroom/dashboard/templates/dashboard.html
index 1aa01f8cb..389bf03be 100644
--- a/headroom/dashboard/templates/dashboard.html
+++ b/headroom/dashboard/templates/dashboard.html
@@ -2565,26 +2565,14 @@
// --- Headline savings percent ---
//
- // Active ratio (saved / attempted) is the right metric when we have
- // a working denominator. Some backend-routed paths don't yet
- // populate `proxy_attempted_tokens` consistently — in that case
- // the active number reads 0% even when compression is happening,
- // so fall back to the whole-request ratio (`proxy_savings_percent`)
- // instead of showing a misleading zero. Issue #455.
get headlineSavingsPercent() {
- const attempted = this.stats.tokens?.proxy_attempted_tokens || 0;
- const active = this.stats.tokens?.active_savings_percent || 0;
- if (attempted > 0 && active > 0) return active;
- return this.stats.tokens?.proxy_savings_percent || 0;
+ return this.stats.tokens?.savings_percent
+ ?? this.stats.tokens?.proxy_savings_percent
+ ?? 0;
},
get headlineSavingsTitle() {
- const attempted = this.stats.tokens?.proxy_attempted_tokens || 0;
- const active = this.stats.tokens?.active_savings_percent || 0;
- if (attempted > 0 && active > 0) {
- return 'Of compressible tokens attempted';
- }
- return 'Of whole pre-compression request (attempted-tokens metric unavailable)';
+ return 'Of total wire input tokens';
},
// --- Expandable Rows ---
diff --git a/tests/test_dashboard_token_savings.py b/tests/test_dashboard_token_savings.py
new file mode 100644
index 000000000..6c8b02569
--- /dev/null
+++ b/tests/test_dashboard_token_savings.py
@@ -0,0 +1,27 @@
+"""Regression tests for dashboard token savings copy."""
+
+from __future__ import annotations
+
+import re
+
+from headroom.dashboard import get_dashboard_html
+
+
+def _getter_body(html: str, name: str) -> str:
+ match = re.search(rf"get {name}\(\) \{{(?P<body>.*?)\n\s*\}},", html, re.S)
+ assert match is not None
+ return match.group("body")
+
+
+def test_token_savings_headline_uses_total_wire_denominator() -> None:
+ html = get_dashboard_html()
+
+ headline_body = _getter_body(html, "headlineSavingsPercent")
+ assert "stats.tokens?.savings_percent" in headline_body
+ assert "stats.tokens?.proxy_savings_percent" in headline_body
+ assert "stats.tokens?.active_savings_percent" not in headline_body
+ assert "stats.tokens?.proxy_attempted_tokens" not in headline_body
+
+ title_body = _getter_body(html, "headlineSavingsTitle")
+ assert "Of total wire input tokens" in title_body
+ assert "Of compressible tokens attempted" not in title_body