Skip to content

Fix 5 Lens UI bugs (#132–#136) - #137

Merged
anilmurty merged 1 commit into
mainfrom
fix/lens-bugs-132-136
Jun 18, 2026
Merged

anilmurty merged 1 commit into
mainfrom
fix/lens-bugs-132-136

Conversation

@anilmurty

Copy link
Copy Markdown
Contributor

Closes #132, #133, #134, #135, #136. Verified live across all four windows + first-load.

#132 — First-load lands on Overview (was blank + Status highlighted)

getRoute() now defaults to overview (the single source of the default), and
the render-time location.hash = '#/overview' redirect — which raced the
initial render and left the content blank while the sidebar highlighted Status —
is replaced by a cosmetic history.replaceState in an effect. Bare URL now
renders Overview with the sidebar highlighting it, no hard-refresh needed.

#133 + #136 — Spend chart spans the full window, with consistent labels

  • /api/v1/cost returns a window-bucketed series — hourly for ≤2-day
    windows, daily otherwise — as epoch buckets, plus series_bucket and
    window_start/window_end.
  • The chart builds a continuous, zero-filled grid across the full window and
    pins the x scale to it, so 7d/30d/90d render distinctly and idle periods
    show as $0.
  • Tick increments are constrained to the bucket unit (no more duplicate
    "Jun 11 / Jun 11" labels), and labels use one consistent format —
    "6 PM" (hourly) / "Jun 15" (daily) — never 6/15/26 mixed with 6/16.

#134 — Run-rate is cycle-relative

Replaced the fixed ×30 (circular at a 30d window, undershooting at 90d) with
daily_rate × days-remaining-in-calendar-cycle, captioned "~$X by end of
{month}"
per lens-architecture §10. Keeps "linear run-rate, not a forecast".

#135 — Cache "at ceiling" now detected

classifyFinding no longer gates at_ceiling on input volume — a fully-cached
model has tiny uncached input, so 100% efficacy was misclassified as
"No candidates". It now renders the positive "✓ Already optimized — 100% (or
86%…) cache efficacy"
state. The efficacy ceiling is exposed on the cache
finding so the UI reads it instead of hardcoding 0.80.

Verified live (tj serve, seeded data)

  • Bare URL → Overview (sidebar highlighted, content populated).
  • 24h → hourly ticks; 7d → 7 daily ticks; 30d → weekly over the month; 90d →
    weekly over the quarter — all distinct, full-window, zero-filled.
  • Run-rate caption "~$X by end of June".
  • Cache tile green "✓ 86% cache efficacy / Already optimized".

Tests

  • Integration: window-series shape (bucket + series_bucket + window bounds);
    hourly bucketing for short windows.
  • tests/unit/test_lens_ui_regression.py guards for each fix (overview default,
    full-window range, time-axis formatter, cycle-relative caption, cache ceiling
    not volume-gated).
  • Full suite green (695); ruff check tokenjam/ + mypy clean.

#132 — First-load lands on Overview:
- getRoute() defaults to 'overview' (single source of the default), and the
  render-time `location.hash = '#/overview'` redirect (which raced the initial
  render → blank content + Status highlighted) is replaced by a cosmetic
  history.replaceState in an effect. Empty hash now renders Overview with the
  sidebar highlighting it.

#133 + #136 — Spend chart spans the full window with consistent labels:
- /api/v1/cost returns a window-bucketed series (hourly for ≤2d windows, daily
  otherwise) as epoch buckets, plus series_bucket + window_start/end.
- The chart builds a continuous, zero-filled grid across the FULL window and
  pins the x scale to it, so 7d/30d/90d render distinctly and idle periods show
  as $0. Tick increments are constrained to the bucket unit (no duplicate day
  labels), and labels use one consistent format — "6 PM" (hourly) / "Jun 15"
  (daily), never "6/15/26" mixed with "6/16".

#134 — Run-rate is cycle-relative:
- Replace the fixed ×30 (circular at a 30d window, undershooting at 90d) with
  daily_rate × days-remaining-in-calendar-cycle, captioned "~$X by end of
  {month}", per lens-architecture §10. Keeps "linear run-rate, not a forecast".

#135 — Cache "at ceiling" detected:
- classifyFinding no longer gates at_ceiling on input volume (a fully-cached
  model has tiny uncached input). 100% efficacy now renders the positive
  "✓ Already optimized" state, not "No candidates". The efficacy ceiling is
  exposed on the cache finding so the UI reads it instead of hardcoding.

Tests: window-series shape (bucket/window bounds) + hourly bucketing for short
windows; regression guards for each fix in index.html. Verified live across
all four windows + first-load + at-ceiling. Full suite green (695); ruff
(tokenjam/) + mypy 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 five bugs addressed cleanly. Tight diff (+200/-71). CI green on 3.10/3.11/3.12 + TS.

Per-bug verification:

  • #132 ✓ getRoute() defaults to 'overview' (index.html:783, 786); render-time hash redirect replaced with cosmetic history.replaceState inside useEffect (:2207-2210). No hashchange re-fire, no race.

  • #133 ✓ cost.py:_window_series returns hourly buckets (≤2d windows) or daily buckets (longer), plus series_bucket + window_start/end metadata. SQL uses parameterized date_trunc($1, ...) (Rule 7 honored — comment even calls this out). UI buildCostSeries zero-fills the full grid (:1289-1308); SpendChart pins scales.x.range to the window bounds (:961); tick incrs constrain spacing to bucket units (:967-970).

  • #134 ✓ New cycleRemaining() (:855-861) computes days to end-of-calendar-month. Projection: runRate × cyc.days. Caption: "~$X by end of ${cyc.label}". Both * 30 and "over 30 days" removed (regression-test grep enforces).

  • #135 ✓ classifyFinding Cache branch (index.html:1843-1850) removes the CACHE_MIN_INPUT volume gate. Ceiling read from fd.efficacy_ceiling with 0.80 constant as safe fallback. Backend exposes efficacy_ceiling on CacheEfficacyFinding (cache_efficacy.py:74); report_to_dict serializes via asdict. Round-trip in runner.py reads with default.

  • #136 ✓ fmtAxisTime(epoch, bucket) (:879-883) returns "6 PM" (hourly) or "Jun 15" (daily) using toLocaleTimeString/toLocaleDateString with timeZone: 'UTC' matching the UTC-aligned buckets. Single format per axis.

Quality checks clean: no f-string SQL (bucket bound as $1); utcnow() used in cost.py (Rule 9); no external HTTP loads (Rule 18); the +3 lines in cache_efficacy.py and +1 in runner.py are purely additive. Tests look good — test_lens_ui_regression.py has static-grep guards for each fix, test_api.py asserts the new response shape (series_bucket, window_start/end).

On your flagged judgment call (90d projects smaller than 7d): Concur. Window-average is what the spec says; the new "~$X by end of June" framing is interpretable at every window selection without the circular 30d artifact. Stable-across-window projections would be a deliberate spec change — worth a separate issue, not a blocker here.

Two non-blocking follow-ups worth filing:

  1. cycleRemaining() uses the calendar month, not the user's configured [budget.<provider>] cycle_start_day. With cycle_start_day = 15, the "by end of June" caption would be off by half a month. The existing budget-projection analyzer honors per-provider cycle days — symmetric treatment would be nicer for honesty parity.

  2. xs.length > 5000 guard in buildCostSeries is good defense but at hourly bucketing a 200d window would silently hit it (returns null → empty state). Fine today since the window picker tops out at 90d; worth noting if/when longer windows or finer bucketing ship.

Ship it.

@anilmurty

Copy link
Copy Markdown
Contributor Author

Thanks! Both follow-ups filed (keeping this PR as the approved bug-fix scope):

And agreed on the 90d-vs-7d projection: window-average per the spec; a recency-weighted variant would be a deliberate §10 change, separate issue.

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] First-load lands on /#/overview URL but sidebar highlights Status and content is blank

1 participant