Skip to content

Commit 27d1df3

Browse files
committed
fix(dashboard): show lifetime cache impact after restart
1 parent a26acb6 commit 27d1df3

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

headroom/dashboard/templates/dashboard.html

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ <h3 class="mb-3 text-sm font-medium text-gray-300">Live Activity</h3>
469469
</div>
470470

471471
<!-- Prefix Cache Impact: current process only -->
472-
<template x-if="cacheSessionActive">
472+
<template x-if="hasPrefixCacheImpact">
473473
<div class="bg-surface rounded-lg p-4 border border-border mb-6">
474474
<div class="flex justify-between items-center mb-3">
475475
<div class="text-sm font-medium text-gray-300">Prefix Cache Impact</div>
@@ -516,6 +516,13 @@ <h3 class="mb-3 text-sm font-medium text-gray-300">Live Activity</h3>
516516
<div class="text-xs text-gray-500" x-show="!cacheSessionActive">no activity since restart</div>
517517
</div>
518518
</div>
519+
<template x-if="lifetimeCacheReadTokens > 0 || lifetimeCacheSavingsUsd > 0">
520+
<div class="rounded-lg border border-emerald-500/20 bg-emerald-500/5 p-3 mb-4">
521+
<div class="text-xs text-gray-500 uppercase tracking-wide mb-1">Cache Reads (lifetime)</div>
522+
<div class="text-2xl font-light tabular-nums text-emerald-400" x-text="formatNumber(lifetimeCacheReadTokens)"></div>
523+
<div class="text-xs text-emerald-400/70" x-text="'$' + formatCurrency(lifetimeCacheSavingsUsd) + ' saved'"></div>
524+
</div>
525+
</template>
519526
<!-- Cache efficiency bar (session-scoped; hidden until traffic arrives) -->
520527
<div x-show="cacheSessionActive">
521528
<div class="flex justify-between text-xs text-gray-500 mb-1">
@@ -2478,6 +2485,20 @@ <h3 class="mb-3 text-sm font-medium text-gray-300">Live Activity</h3>
24782485
return (this.stats.prefix_cache?.totals?.requests || 0) > 0;
24792486
},
24802487

2488+
get lifetimeCacheReadTokens() {
2489+
return this.stats.persistent_savings?.lifetime?.cache_read_tokens || 0;
2490+
},
2491+
2492+
get lifetimeCacheSavingsUsd() {
2493+
return this.stats.persistent_savings?.lifetime?.cache_savings_usd || 0;
2494+
},
2495+
2496+
get hasPrefixCacheImpact() {
2497+
return this.cacheSessionActive
2498+
|| this.lifetimeCacheReadTokens > 0
2499+
|| this.lifetimeCacheSavingsUsd > 0;
2500+
},
2501+
24812502
get cacheSavingsPercent() {
24822503
const t = this.stats.prefix_cache?.totals || {};
24832504
const total = (t.cache_read_tokens || 0) + (t.cache_write_tokens || 0);

tests/test_dashboard_cache_ttl_playwright.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,26 +194,32 @@ def test_dashboard_per_project_setup_url_uses_current_origin() -> None:
194194
_install_dashboard_routes(page)
195195

196196
page.goto("http://127.0.0.1:8788/dashboard", wait_until="load")
197+
page.get_by_role("button", name="Lifetime").click()
197198
expect(
198199
page.get_by_text(
199-
"ANTHROPIC_BASE_URL: http://127.0.0.1:8788/p/<project-name>", exact=True
200+
"Route project traffic through http://127.0.0.1:8788/p/<project-name>",
201+
exact=True,
200202
)
201203
).to_be_visible()
202204
expect(
203205
page.get_by_text(
204-
"ANTHROPIC_BASE_URL: http://127.0.0.1:8787/p/<project-name>", exact=True
206+
"Route project traffic through http://127.0.0.1:8787/p/<project-name>",
207+
exact=True,
205208
)
206209
).to_have_count(0)
207210

208211
page.goto("http://headroom.local:9393/dashboard", wait_until="load")
212+
page.get_by_role("button", name="Lifetime").click()
209213
expect(
210214
page.get_by_text(
211-
"ANTHROPIC_BASE_URL: http://headroom.local:9393/p/<project-name>", exact=True
215+
"Route project traffic through http://headroom.local:9393/p/<project-name>",
216+
exact=True,
212217
)
213218
).to_be_visible()
214219
expect(
215220
page.get_by_text(
216-
"ANTHROPIC_BASE_URL: http://127.0.0.1:8787/p/<project-name>", exact=True
221+
"Route project traffic through http://127.0.0.1:8787/p/<project-name>",
222+
exact=True,
217223
)
218224
).to_have_count(0)
219225

0 commit comments

Comments
 (0)