Skip to content

fix: paginate cost tab tables + correct Cost Saved formatting#6

Merged
0bserver07 merged 1 commit into
mainfrom
fix/cost-pagination-and-saved
Apr 25, 2026
Merged

fix: paginate cost tab tables + correct Cost Saved formatting#6
0bserver07 merged 1 commit into
mainfrom
fix/cost-pagination-and-saved

Conversation

@0bserver07
Copy link
Copy Markdown
Owner

Bugs reported

the table here dont have fucking pagiantion, wtf, http://127.0.0.1:8095/project/.../tab=cost ... where is the pagination on here?

  • 132 retries (RetryAlertsPanel)
  • High step count + Outlier Commands sections
  • Most Expensive Commands

why is the $$ not currency formatted
Cost Saved: $2346042618

Fixes

1. Cost Saved was rendering raw `cost_saved_base_units`

Backend stores `self.read * 0.9 - self.created * 0.25` in `stats/aggregator.py`. Rates in `infra/costs.py` are `$/million tokens` — the multiplication produces a value in token-rate units that needs ÷ 1,000,000 to become real dollars.

Frontend was passing the raw value through `formatCost`. `$2,346,042,618` is the raw token-rate-units; the actual cost saved is `$2,346.04`.

2. Pagination on three tables

Real Prev/Next + N/page selector (10 / 25 / 50 / 100). Defaults: 25.

  • CommandCostList (Most Expensive Commands) — was rendering all 50 rows in one dump.
  • OutlierCommandsTable (high tool / high step) — replaced the "Show all (N)" / "Show first 50" toggle that just dumped every row when expanded.
  • RetryAlertsPanel — was rendering all 132+ signals at once.

Page resets to 1 on filter / page-size change.

3. `formatCost` picks up locale formatting at $1k+

`$2,346.04` instead of `$2346`.

Verification

  • `npm run typecheck` ✓ clean
  • `npm run build` ✓ clean
  • 420 backend tests still pass

🤖 Generated with Claude Code

- CommandCostList, OutlierCommandsTable, RetryAlertsPanel all gain
  proper pagination controls (Prev/Next + N/page selector). Outlier
  table replaces the "Show all (N)" toggle that dumped every row.
- CacheRoiCard's Cost Saved was rendering raw `cost_saved_base_units`
  (e.g. $2,346,042,618 for chimera). Backend stores cost as
  `tokens × $/M-rate` without the /1M divisor (rates live in
  infra/costs.py as $/million). Convert to dollars before format.
- formatCost picks up a >=$1k branch with locale-aware thousands
  separators so big numbers don't fall through to toFixed(0) without
  commas.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@0bserver07 0bserver07 merged commit 0553ef7 into main Apr 25, 2026
9 checks passed
@0bserver07 0bserver07 deleted the fix/cost-pagination-and-saved branch April 25, 2026 18:29
0bserver07 added a commit that referenced this pull request May 20, 2026
- CommandCostList, OutlierCommandsTable, RetryAlertsPanel all gain
  proper pagination controls (Prev/Next + N/page selector). Outlier
  table replaces the "Show all (N)" toggle that dumped every row.
- CacheRoiCard's Cost Saved was rendering raw `cost_saved_base_units`
  (e.g. $2,346,042,618 for chimera). Backend stores cost as
  `tokens × $/M-rate` without the /1M divisor (rates live in
  infra/costs.py as $/million). Convert to dollars before format.
- formatCost picks up a >=$1k branch with locale-aware thousands
  separators so big numbers don't fall through to toFixed(0) without
  commas.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0bserver07 added a commit that referenced this pull request May 20, 2026
Adds two new marts that unblock HANDOFF §"What's left" items #1 and #6
and §"What I'd do next" item #1:

* tool_mart — (day, project_id, provider, tool_name) rollup. Fans each
  billable event out across the source message's tools_json with 1/N
  cost + token attribution (mirrors stats.aggregator._ToolCostCollector
  §1.3). Migrates routes/cost.py tool_costs block off the aggregator
  path and short-circuits four optimize patterns when the implicated
  tool wasn't called in window (low_read_edit_ratio, junk_reads,
  bash_output_limits, ghost_agents).

* command_mart — (day, project_id, command_name) rollup. Walks back from
  each event to the most recent preceding role='user' message in the
  same session, parses the slash command (or 'freeform') from
  content_text, and aggregates cost + tokens. Foundational for future
  per-command analytics; not yet wired into a route consumer beyond
  the optimize early-exit hooks.

Both marts follow the additive-mart pattern (INSERT ON CONFLICT DO
UPDATE) with the post-upsert session_count recompute for the affected
keys (HANDOFF §"`session_count` correctness across windows").

Schema:
- Migration v007_lower_grain_marts.sql is additive — no existing tables
  touched. CURRENT_VERSION = 7.

Tests:
- test_tool.py + test_command.py: idempotency, watermark advance,
  session_count correctness across refresh windows, 1/N attribution,
  malformed tools_json, slash-command parsing.
- test_optimize_uses_tool_mart.py: short-circuit + empty-mart fallback
  for the four migrated detectors.
- test_cost_tool_mart_overlay.py: tool_mart-overlay path + empty-mart
  fallback for /api/cost-data tool_costs block.
- Integration e2e + perf regression updated for the two new marts.

Empty-mart fallback preserved per route — JSON contracts unchanged
whether marts are populated or empty.

Tests: 1598 → 1630 passing (+32), 2 skipped, 11 deselected, 0
regressions. ruff check stackunderflow/ on changed files: clean.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant