Repository navigation
Fix 4 Lens UI bugs (#126–#129) - #130
Conversation
#126 — Downsize (typed slot) now always renders: - Optimize tab renders a Downsize section first; a null downgrade slot shows a "no candidates in this window" state instead of vanishing. - Overview recoverable band always includes a Downsize tile. #127 — Recoverable tiles get four honest states (classifyFinding): - actionable / at_ceiling / no_findings / not_ready, read from richer finding signals instead of `estimated_recoverable_usd in (None, 0)`. - "at ceiling" (e.g. cache already ≥80% efficacy) is positive, never a warning, and never says "raise X toward Y". "no findings" shows the window length. "not ready" is reserved for disabled/skipped analyzers. #128 — Spend chart hover + non-hostile drill-through: - uPlot cursor tooltip (date + framed value, themed) on both the Overview hero and the Cost screen. - The chart is no longer a click-target; drill-through moves to an explicit, focusable "View Cost details →" link in the header. #129 — Honest run-rate + axis polish: - Run-rate uses the window length as the denominator (spend / window_days × 30), per lens-architecture §10 — not the data range, which overstated sparse windows. - "not a forecast" qualifier added to the Overview caption (parity with Cost). - Y-axis ticks carry a compact `$` formatter ($0/$25/$1.5k), not "$0.0000". Tests: integration test that /optimize always carries the `downgrade` key; tests/unit/test_lens_ui_regression.py static-guards each fix in index.html (no JS runner in the Python CI job). Verified live via tj serve across Overview + Optimize. Full suite green (689); ruff clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
anilmurty
left a comment
There was a problem hiding this comment.
Review: ✅ Approve
All four bugs cleanly addressed in one well-scoped PR. CI green on 3.10/3.11/3.12 + TS.
Per-bug verification:
#126 — Downsize rendering ✓
- Recoverable tile reads from
opt.downgradetyped slot (index.html:1936), notfindings. - Optimize section order pinned:
order = ['downsize', 'cache', ...](:2096). Null-downgrade branch still renders an honest "no candidates in this window" section. ?finding=downsizedeep-link scrolls + highlights correctly (:2089-2092).- Integration test asserts
"downgrade" in data.
#127 — Tile state distinction ✓
- New
classifyFinding()(:1782) returns 4 distinct states:actionable/at_ceiling/no_findings/not_ready. - At-ceiling renders positive:
class="rec-tile ok", green--success,✓ {metric}, "Already optimized — nothing to recover" (:1968). no_findingssurfaces window length: "Nothing actionable in the last ${since}" (:1975).- At-ceiling never says "raise toward Y" anymore (only reached when
efficacy >= 0.80). - Trim's gold-standard copy preserved.
#128 — Chart tooltip + drill ✓
- New
chartTooltipPlugin()(:845) renders themed crosshair tooltip with date + value per series via uPlotsetCursorhook; skips the dashed run-rate line. Themed via CSS vars. - Overview hero changed from
<a class="band-hero">→<div class="chart-card">(:1937); drill moved to an explicit<a class="drill-link" href="#/cost?...">View Cost details →</a>(:1944) — keyboard-accessible. - Tooltip applied inside
SpendChartitself (:910) so the Cost screen chart inherits identical behavior.
#129 — Run-rate + polish ✓
windowDays(since)parses7d/24h/ date-range (:838).runRateProjection = (windowTotal / max(windowDays, 1/24)) * 30(:850). Both Cost (:1316) and Overview (:1916) call it. The buggyys.reduce(...) / ys.lengthis gone in both spots.- Overview caption now reads
(linear run-rate, not a forecast)(:1958), matching Cost. fmtAxisUsd()(:856) emits$0/$25/$1.5kwith no trailing zeros. Plumbed throughSpendChartviaaxisFmtY.
Test quality — test_lens_ui_regression.py: Tight, not loose. Asserts the literal buggy substrings are gone ("ys.reduce((a, b) => a + b, 0) / ys.length" not in html, 'class="chart-card band-hero"' not in html, "(linear run-rate)<" not in html) AND that the new function names are present (classifyFinding, chartTooltipPlugin, windowDays, runRateProjection, fmtAxisUsd). Section order pinned. Smart workaround for the CI-without-JS-runner constraint — pins the fix without over-pinning impl details.
Quality checks: Rule 18 preserved (no new external HTTP loads). No SQL or Python timestamp changes. Adjacent screens (Status/Traces/Alerts/Drift/Budget) untouched — diff is concentrated on SpendChart, the Overview hero band, recoverable tiles, and the Optimize downsize branch. No collateral damage.
Nits (non-blocking):
runRateProjectionrecomputeswindowDays(since)while callers also compute it inline — minor duplication.chartTooltipPluginskips the run-rate series by string-matchinglabel === 'run-rate'; brittle if that label string ever changes. Local-only, harmless today.
Ship it.
- runRateProjection is now the single windowDays source: callers derive the per-day rate via runRateProjection(total, since, 1) instead of recomputing windowDays inline. - chartTooltipPlugin skips the run-rate series via an _isRunRate flag on the series, not a brittle label-string match. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Thanks! Both nits addressed in the latest commit:
|
Two bugs surfaced by the v0.4.0 pre-release test pass against an install with the daemon running, plus the testing-infra MD files that caught them. ## Bugs fixed **`tj cost` cache columns silently 0 with daemon up.** PR Metabuilder-Labs#149 added `cache_tokens` + `cache_write_tokens` to the DB row, API response, and CLI rendering — but missed the `ApiBackend` shim that the CLI uses when `tj serve` is running. The shim dropped the cache fields on the floor, so they defaulted to 0 even though the JSON response carried the real values. Two-line addition to mirror the wider contract. **`tj optimize` silently skips the Downsize section when no candidates exist.** The Optimize web tab fixed this in PR Metabuilder-Labs#130 (issue Metabuilder-Labs#126) by rendering an explicit "no candidates" state. The CLI render path was overlooked. When other analyzers find content (cache, script, trim, …), the catch-all "No candidates flagged" message doesn't fire either, so Downsize disappears without explanation — reviewers think the analyzer didn't run. Now mirrors the UI: explicit "Downsize: no candidates in this window — sessions don't match the smaller-model shape" empty state. Guarded by the positional `findings` filter so `tj optimize cache` (asking for just cache) doesn't add Downsize noise. ## Testing infrastructure (new) - `tests/manual-pre-release-runner.md` — generic instructions for a sub-agent: find the release-specific checklist, walk each step, capture output, write a structured log to `tests/results/`. - `tests/manual-pre-release-v0.4.0.md` — focused 12-step checklist for the v0.4.0 release. Each step has the structured shape the runner expects (Setup / Test / Expected / Assertions). - `.gitignore`: `tests/results/` — per-run logs are local artifacts, not committed. ## Verification - `pytest tests/unit/ tests/integration/`: 659 passed. - Live with daemon: `tj cost --since 30d --group-by model` now shows `CACHE R 698.8M`, `1530.9M`, etc. instead of `0`. - Live with daemon: `tj optimize --since 30d` prints "① Downsize: no candidates in this window …" when downsize finds nothing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Closes #126, #127, #128, #129. One PR — all four are in
tokenjam/ui/index.html.#126 — Downsize (typed slot) was silently dropped
report.downgradeis a typed slot, not infindings. When it'snull(nocandidates — common for heavy users whose sessions don't match the small-shape
heuristic) the Optimize tab rendered nothing and the Overview said "not ready".
in this window" state when the slot is null.
#127 — "not ready" conflated three outcomes
New
classifyFindingreturns one of four honest states, read from richerfinding signals (not
usd in (None,0)):never a warning, never "raise X toward Y"
state that keeps the "not ready" wording)
#128 — chart had no tooltip and was a hostile click-target
and the Cost screen.
explicit focusable "View Cost details →" link in the header.
#129 — run-rate overstated + axis polish
spend / window_days × 30)per
lens-architecture§10, not the data range (which overstated sparsewindows ~2.3×). New pure
windowDays/runRateProjectionhelpers.$formatter ($0/$25/$1.5k), not$0.0000.Verified live
tj serveagainst seeded data (sparse 7d window + downsize candidates + ahigh-efficacy cache model): the run-rate reads
~$21.26(= 4.96/7×30, was~$50), the Downsize section renders first and highlights on the
?finding=downsizedeep-link, Script shows "No candidates / nothing actionablein the last 7d", and the y-axis shows compact
$.Tests
/api/v1/optimizealways carries thedowngradekey.tests/unit/test_lens_ui_regression.pystatic-guards each fix in the servedsource (no JS test runner in the Python CI job) — e.g. the buggy
/ ys.lengthrun-rate denominator and theband-heroclick-target areasserted gone.
ruffclean; offline test still passing.