Skip to content

#113: Cost screen — replace table-only view with a real chart - #123

Merged
anilmurty merged 4 commits into
mainfrom
feature/113-cost-chart
Jun 18, 2026
Merged

anilmurty merged 4 commits into
mainfrom
feature/113-cost-chart

Conversation

@anilmurty

Copy link
Copy Markdown
Contributor

Closes #113.

Stacked PR. Base is feature/112 (uPlot + URL state); also merges in
feature/110 (framing) since the Cost chart needs both. The diff therefore
includes the framing module (#110) until #117/#121 merge — review the
#113-titled commit for the new work, or re-review after the parents land. I'll
retarget the base to main as the foundations merge.

What changed

  • Chart leads, table follows. uPlot spend-over-time chart (default 7d), with
    the precise daily table preserved below.
  • Toggles, URL-synced ([feature] Vendor uPlot for offline charting + move filter state into the URL #112): window 24h/7d/30d/90d (?since=), group-by
    total / model / agent (?group_by=). Splits keep the top-5 keys + "other".
  • Trend chip ▲/▼ % vs the previous equivalent period, from
    /api/v1/cost/compare.
  • Run-rate: a single dashed mean-per-day line + a "~$X over 30 days"
    projection, explicitly labelled not a forecast (no moving averages /
    seasonality — within [feature] Cost screen — replace the table-only view with a real chart #113 scope).
  • Plan-tier framing ([feature] Extract plan-tier-aware rendering into core/framing.py #110): subscription / local switch the axis + totals to
    token framing and surface the framing qualifier above the chart; api / unknown
    show dollars. The JS formatter mirrors core/framing.render_dollar — it reads
    the server's decision, doesn't re-derive it.
  • States: low-key loading shimmer, clean "No spend in this window" empty
    state, inline error + retry.
  • Endpoint extension (no new route): /api/v1/cost now returns a daily
    series (per date+agent+model) so the chart can split by model/agent — the
    grouped rows collapse that dimension. Dates use AT TIME ZONE 'UTC' (Rule 1).

Tests

New assertion that /api/v1/cost returns the daily series; offline test green;
module JS validated with node --check; ASGI smoke confirms the series + the
by-model split. Full suite: 578 passed; ruff/mypy clean.

Note

Per repo convention (architecture doc: no Playwright/Cypress for v1) this is
verified via the offline + API tests; a visual pass via tj serve is
recommended before merge.

anilmurty and others added 2 commits June 17, 2026 16:39
Replace the table-only Cost view with a uPlot chart that leads, table below.

- Spend-over-time line/area chart (default 7d). Window toggle 24h/7d/30d/90d
  and group-by total/model/agent, both URL-synced (#112). Multi-series split
  keeps the top-5 keys + an "other" bucket.
- Trend chip (▲/▼ % vs previous period) from /api/v1/cost/compare.
- Single linear run-rate: dashed mean-per-day line + a plain-language "~$X over
  30 days" projection (explicitly not a forecast — no moving averages).
- Plan-tier framing (#110): subscription/local switch the axis + totals to
  token framing; the framing qualifier renders above the chart; api/unknown
  show dollars. Formatting mirrors core/framing.render_dollar.
- Loading shimmer, empty ("No spend in this window"), and inline error+retry.
- The precise daily table is preserved below the chart.
- Extend /api/v1/cost with a daily `series` (per date+agent+model) so the chart
  can split by model/agent — the grouped `rows` collapse that dimension. No new
  endpoint. Dates use AT TIME ZONE 'UTC' (Rule 1).

Tests: new assertion that /cost returns the daily series; offline test green;
JS syntax validated; ASGI smoke confirms the series + model split.

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 with nits

Reviewed the #113-specific commit 9964b9d only — the rest of the PR diff is #110 + #112 work I already approved on #117 / #119 / #121.

Acceptance criteria — all 10 met:

  1. ✓ Chart leads (uPlot, 7d default), precise daily table preserved below.
  2. ✓ Window toggle (?since=) and group-by toggle (?group_by=) URL-synced via #112's machinery.
  3. ✓ Trend chip ▲/▼ % from /api/v1/cost/compare.
  4. ✓ Linear run-rate only: dashed mean-per-day line + "~$X over 30 days" with "linear run-rate, not a forecast" caveat. No moving averages.
  5. ✓ Plan-tier framing — JS reads the server's pricing_mode rather than re-deriving the rules.
  6. ✓ Loading shimmer, "No spend in this window" empty state, inline error+retry all present.
  7. ✓ Theme via CSS custom properties; useEffect cleanup correct (plot.destroy() + removeEventListener).
  8. ✓ No new endpoint — extends /api/v1/cost with a daily series field.
  9. ✓ Daily table not regressed.
  10. ✓ Rule 1 honored (AT TIME ZONE 'UTC'). No new f-string SQL, no datetime.now(), no CDN URLs.

Nits / discussion points (non-blocking):

  • cost.py:26-30 — _daily_series always computes the (date, agent, model) breakdown regardless of the table's group_by. Documented choice, but adds one extra GROUP BY scan per /cost call. For 90d on a busy DB this is the most expensive part of the response. Consider ?series=true gating later if it shows up in profiling.
  • Payload scaling: top-5 + "other" bucketing happens client-side in buildCostSeries. Full series cardinality crosses the wire — ~225KB at 90d × 5 agents × 5 models. Defensible for v1; server-side top-5 would shrink it.
  • Plan-tier framing: JS derives useTokens from framing.pricing_mode rather than the explicit framing.display_rule field. Both work today since they're consistent, but the spec wanted display_rule as the switch so the server stays the single source of truth if the rules ever diverge from raw pricing_mode. Worth a tiny follow-up.
  • test_cost_includes_daily_series_for_chart uses if data["series"]: — passes silently if empty. Asserting non-empty after _ingest_sample_span would be stronger.
  • Polling: cadence lowered from 10s → 30s. Sensible for the heavier payload; worth calling out in the PR description.

Note on merge order: this PR's base is feature/112-uplot-url-state, so it can't merge until #117 + #121 land first. Plan to retarget to main once they do, per PR body. Tracking that.

Good work — chart looks faithful to the spec. Visual pass via tj serve recommended before merge as the PR body suggests.

Base automatically changed from feature/112-uplot-url-state to main June 18, 2026 05:14
@anilmurty
anilmurty marked this pull request as ready for review June 18, 2026 05:19
@anilmurty
anilmurty merged commit aec5102 into main Jun 18, 2026
8 checks passed
@anilmurty
anilmurty deleted the feature/113-cost-chart branch June 18, 2026 05:19
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.

[feature] Cost screen — replace the table-only view with a real chart

1 participant