Commit graph

1 commit

Author SHA1 Message Date
Focused Instability
2a4d300841
feat(dashboard): surface compression-vs-cache net impact in Prefix Cache panel (#913)
## Summary

Closes #911, and delivers the dashboard half of the question in #855
("how do I understand the cache impact — can we add it to the
dashboard?").

`GET /stats` already exposes `prefix_cache.compression_vs_cache`
(`tokens_saved_by_compression`, `tokens_lost_to_cache_bust`,
`cache_bust_count`, `net_tokens`) and `prefix_cache.prefix_freeze`
(`busts_avoided`, `tokens_preserved`, `compression_foregone_tokens`,
`net_benefit_tokens`) — built in `headroom/proxy/cost.py` — but the
dashboard never rendered them.

This adds a **Compression vs Cache** section to the existing Prefix
Cache Impact panel:

- **Saved by Compression** — tokens removed before send
- **Lost to Cache Busts** — tokens lost, with observed bust count
- **Net** — color-coded emerald when positive, red when negative, with a
matching "Net positive / Net negative" headline pill
- **Prefix Freeze Net** — net benefit of freeze decisions (preserved
minus compression foregone), with busts avoided

The section is gated on data presence (hidden until any underlying
counter is non-zero), styled to match the existing TTL bucket cards,
works in light and dark mode, and carries `data-testid` hooks.

Frontend-only: no backend changes; the stats endpoint already serves
every field.

## Testing

New `tests/test_dashboard_cache_net_playwright.py` (mirrors the TTL
playwright test): pins the rendered values, the negative-net red
styling, and the hidden-when-empty behavior. 3/3 pass locally under
chromium.

Note for reviewers: the harness matches stubbed routes on URL **path**,
because the dashboard now fetches `/stats?cached=1` — full-URL
`endswith("/stats")` checks miss it and the request escapes to the real
network. The pre-existing `test_dashboard_cache_ttl_playwright.py` has
this exact bitrot (plus stale text assertions) and currently fails when
playwright is actually installed — playwright isn't installed in CI so
it silently skips. Left out of scope here; can file separately.

`ruff check` and `ruff format --check` clean.

Refs #855.

Co-authored-by: integration-check <integration@local>
2026-06-12 23:43:49 -05:00