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): distinguish unavailable RTK from zero stats in Docker (#1900)

Rod Boev87f6e93c14a9
diff --git a/headroom/dashboard/templates/dashboard.html b/headroom/dashboard/templates/dashboard.html
index 3f16bc9c3..f5aa65d3c 100644
--- a/headroom/dashboard/templates/dashboard.html
+++ b/headroom/dashboard/templates/dashboard.html
@@ -220,7 +220,7 @@
<div class="mt-1 text-xs text-gray-500 leading-relaxed">
<span x-text="'Proxy ' + formatNumber(stats.tokens?.proxy_compression_saved || 0) + ' (' + proxyShareOfTotal.toFixed(1) + '%)'"></span>
<span class="mx-1 text-gray-600">/</span>
- <span x-text="cliFilteringLabel + ' ' + formatNumber(cliFilteringSaved) + ' this session (' + cliFilteringSessionPctDisplay.toFixed(1) + '%)'"></span>
+ <span x-text="cliFilteringAvailable ? (cliFilteringLabel + ' ' + formatNumber(cliFilteringSaved) + ' this session (' + cliFilteringSessionPctDisplay.toFixed(1) + '%)') : (cliFilteringLabel + ' not installed')"></span>
</div>
<div class="mt-1 text-xs text-gray-600 leading-relaxed">
<span x-text="'Of total wire: ' + (stats.tokens?.savings_percent || 0).toFixed(2) + '%'" title="Savings as fraction of all input tokens including frozen prefix"></span>
@@ -1056,11 +1056,15 @@
<span class="text-sm text-gray-400">Before Compression</span>
<span class="font-mono text-sm" x-text="formatNumber(stats.tokens?.total_before_compression || 0)"></span>
</div>
- <div class="flex justify-between items-center">
+ <div class="flex justify-between items-center" x-show="cliFilteringAvailable">
<span class="text-sm text-gray-400" x-text="cliFilteringLabel + ' Filtered (this session)'"></span>
<span class="font-mono text-sm text-emerald-400" x-text="formatNumber(cliFilteringSaved)"></span>
</div>
- <div class="flex justify-between items-center" x-show="cliFilteringLifetime > 0">
+ <div class="flex justify-between items-center" x-show="!cliFilteringAvailable">
+ <span class="text-sm text-gray-400" x-text="cliFilteringLabel + ' Filtered (this session)'"></span>
+ <span class="font-mono text-sm text-gray-600">not installed</span>
+ </div>
+ <div class="flex justify-between items-center" x-show="cliFilteringAvailable && cliFilteringLifetime > 0">
<span class="text-sm text-gray-500" x-text="cliFilteringLabel + ' Filtered (lifetime)'"></span>
<span class="font-mono text-sm text-emerald-400/70" x-text="formatNumber(cliFilteringLifetime)"></span>
</div>
@@ -1430,7 +1434,7 @@
<div class="mt-2 text-xs text-gray-500">Based on persisted weekly buckets</div>
</div>
- <template x-if="historyStats.cli_filtering">
+ <template x-if="historyStats.cli_filtering && historyCliFilteringAvailable">
<div class="bg-surface rounded-lg p-4 border border-border">
<div class="text-xs text-gray-500 uppercase tracking-wide mb-1"
x-text="(historyStats.cli_filtering?.label || cliFilteringLabel) + ' Lifetime Saved'"></div>
@@ -2592,6 +2596,18 @@
return (p === null || p === undefined) ? this.cliFilteringShareOfTotal : p;
},
+ get cliFilteringAvailable() {
+ const ct = this.stats.context_tool;
+ if (ct && typeof ct.available === 'boolean') return ct.available;
+ return true;
+ },
+
+ get historyCliFilteringAvailable() {
+ const hf = this.historyStats?.cli_filtering;
+ if (hf && typeof hf.available === 'boolean') return hf.available;
+ return true;
+ },
+
// --- Headline savings percent ---
//
get headlineSavingsPercent() {
diff --git a/tests/test_rtk_docker_availability.py b/tests/test_rtk_docker_availability.py
new file mode 100644
index 000000000..1b293acdf
--- /dev/null
+++ b/tests/test_rtk_docker_availability.py
@@ -0,0 +1,45 @@
+"""Tests for RTK/context-tool availability detection in Docker environments."""
+
+from __future__ import annotations
+
+from unittest.mock import patch
+
+from headroom.proxy.helpers import (
+ _context_tool_zero_payload,
+ _read_rtk_lifetime_stats,
+)
+
+
+class TestRtkNotInstalledPayload:
+ """When rtk binary is absent, the payload must report installed=False."""
+
+ def test_zero_payload_marks_not_installed(self) -> None:
+ payload = _context_tool_zero_payload(tool="rtk", installed=False)
+ assert payload["installed"] is False
+ assert payload["total_commands"] == 0
+ assert payload["tokens_saved"] == 0
+
+ def test_read_rtk_returns_not_installed_when_binary_missing(self) -> None:
+ with patch("headroom.rtk.get_rtk_path", return_value=None):
+ result = _read_rtk_lifetime_stats()
+ assert result is not None
+ assert result["installed"] is False
+ assert result["tokens_saved"] == 0
+
+ def test_installed_payload_marks_installed(self) -> None:
+ payload = _context_tool_zero_payload(tool="rtk", installed=True)
+ assert payload["installed"] is True
+
+
+class TestDashboardAvailabilityFlag:
+ """The stats endpoint must surface context_tool.available for the dashboard."""
+
+ def test_available_false_when_tool_not_installed(self) -> None:
+ stats = {"installed": False, "tokens_saved": 0}
+ available = bool(stats.get("installed", False))
+ assert available is False
+
+ def test_available_true_when_tool_installed(self) -> None:
+ stats = {"installed": True, "tokens_saved": 42}
+ available = bool(stats.get("installed", False))
+ assert available is True