Skip to content

Fix 4 Lens UI bugs (#126–#129) - #130

Merged
anilmurty merged 2 commits into
mainfrom
fix/lens-bugs-126-129
Jun 18, 2026
Merged

anilmurty merged 2 commits into
mainfrom
fix/lens-bugs-126-129

Conversation

@anilmurty

Copy link
Copy Markdown
Contributor

Closes #126, #127, #128, #129. One PR — all four are in tokenjam/ui/index.html.

#126 — Downsize (typed slot) was silently dropped

report.downgrade is a typed slot, not in findings. When it's null (no
candidates — common for heavy users whose sessions don't match the small-shape
heuristic) the Optimize tab rendered nothing and the Overview said "not ready".

  • Optimize tab now renders a Downsize section first, with a "no candidates
    in this window" state when the slot is null.
  • Overview always includes a Downsize tile.

#127 — "not ready" conflated three outcomes

New classifyFinding returns one of four honest states, read from richer
finding signals (not usd in (None,0)):

  • actionable — recoverable waste found (carries the number)
  • at_ceiling — already optimized (e.g. cache ≥80% efficacy) → positive, ✓,
    never a warning, never "raise X toward Y"
  • no_findings — ran, nothing actionable → shows the window length
  • not_ready — disabled / missing dep / skipped on the fast path (the only
    state that keeps the "not ready" wording)

#128 — chart had no tooltip and was a hostile click-target

  • uPlot cursor tooltip (date + framed value, themed) on the Overview hero
    and the Cost screen.
  • The chart is no longer wrapped in a click handler; drill-through is an
    explicit focusable "View Cost details →" link in the header.

#129 — run-rate overstated + axis polish

  • Run-rate denominator is now the window length (spend / window_days × 30)
    per lens-architecture §10, not the data range (which overstated sparse
    windows ~2.3×). New pure windowDays / runRateProjection helpers.
  • "not a forecast" qualifier added to the Overview caption (parity with Cost).
  • Y-axis uses a compact $ formatter ($0 / $25 / $1.5k), not $0.0000.

Verified live

tj serve against seeded data (sparse 7d window + downsize candidates + a
high-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=downsize deep-link, Script shows "No candidates / nothing actionable
in the last 7d", and the y-axis shows compact $.

Tests

  • Integration: /api/v1/optimize always carries the downgrade key.
  • tests/unit/test_lens_ui_regression.py static-guards each fix in the served
    source (no JS test runner in the Python CI job) — e.g. the buggy
    / ys.length run-rate denominator and the band-hero click-target are
    asserted gone.
  • Full suite green (689); ruff clean; offline test still passing.

#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 anilmurty left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.downgrade typed slot (index.html:1936), not findings.
  • Optimize section order pinned: order = ['downsize', 'cache', ...] (:2096). Null-downgrade branch still renders an honest "no candidates in this window" section.
  • ?finding=downsize deep-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_findings surfaces 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 uPlot setCursor hook; 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 SpendChart itself (:910) so the Cost screen chart inherits identical behavior.

#129 — Run-rate + polish ✓

  • windowDays(since) parses 7d / 24h / date-range (:838). runRateProjection = (windowTotal / max(windowDays, 1/24)) * 30 (:850). Both Cost (:1316) and Overview (:1916) call it. The buggy ys.reduce(...) / ys.length is gone in both spots.
  • Overview caption now reads (linear run-rate, not a forecast) (:1958), matching Cost.
  • fmtAxisUsd() (:856) emits $0 / $25 / $1.5k with no trailing zeros. Plumbed through SpendChart via axisFmtY.

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):

  • runRateProjection recomputes windowDays(since) while callers also compute it inline — minor duplication.
  • chartTooltipPlugin skips the run-rate series by string-matching label === '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]>
@anilmurty

Copy link
Copy Markdown
Contributor Author

Thanks! Both nits addressed in the latest commit:

  1. windowDays duplication — callers now derive the per-day rate via runRateProjection(windowTotal, since, 1) (then × 30 for the projection), so windowDays is computed in exactly one place. Math is unchanged.
  2. Brittle run-rate skip — the run-rate series now carries an _isRunRate: true flag and the tooltip skips on that, not on the 'run-rate' label string.

@anilmurty
anilmurty merged commit a9e5089 into main Jun 18, 2026
4 checks passed
@anilmurty
anilmurty deleted the fix/lens-bugs-126-129 branch June 18, 2026 16:35
HoomanDgtl pushed a commit to HoomanDigital/tokenjam that referenced this pull request Jun 20, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Overview/Optimize: Downsize analyzer not rendered (typed slot ignored)

1 participant