fix: paginate cost tab tables + correct Cost Saved formatting#6
Merged
Conversation
- 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>
This was referenced May 15, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bugs reported
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.
Page resets to 1 on filter / page-size change.
3. `formatCost` picks up locale formatting at $1k+
`$2,346.04` instead of `$2346`.
Verification
🤖 Generated with Claude Code