Skip to content

Conversation

@dtsong
Copy link
Owner

@dtsong dtsong commented Jan 23, 2026

Summary

  • New /costs page with cost breakdown by time, repo, and model
  • Time range selector (7d/30d/90d)
  • Charts: daily cost trend, cost per review, by repo (bar), by model (pie)
  • Outliers table identifying expensive reviews

Changes

  • dashboard/src/app/costs/page.tsx — costs page with data aggregation
  • dashboard/src/components/CostChart.tsx — reusable chart components
  • dashboard/src/lib/supabase.tsCostByRepo, CostByModel interfaces
  • dashboard/src/app/page.tsx — "Costs" nav link

Test plan

  • TypeScript types match existing schema
  • Follows existing dashboard patterns
  • Python test suite unaffected

Closes #9

🤖 Generated with Claude Code

- Costs page at /costs with daily/weekly/monthly time range selector
- Charts: cost trend, cost per review, cost by repo, cost by model
- Outliers table showing expensive reviews (>2x average)
- Summary cards: total spend, review count, avg cost/review
- Navigation link from main dashboard

Implements #9

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

AI Code Review

Summary

The PR adds a comprehensive costs dashboard with data visualization and analysis features. The code is generally well-structured but has several potential issues with error handling, type safety, and edge cases.

Confidence: 0.00 (low)
This PR may require human review

Strengths

  • Well-structured component architecture with reusable chart components
  • Comprehensive data visualization covering multiple cost dimensions
  • Good use of TypeScript interfaces for type safety
  • Responsive design with proper grid layouts
  • Includes outlier detection for identifying expensive reviews
  • Follows existing codebase patterns and conventions

Issues Found

Major (3)

dashboard/src/app/costs/page.tsx:31 - logic

Database query lacks error handling - if the query fails, data will be null but the code assumes it succeeded
Suggestion: Add proper error handling for the database query to handle failures gracefully

dashboard/src/app/costs/page.tsx:85 - logic

Outliers calculation has a logical flaw - when avgCost is 0, the filter condition avgCost > 0 prevents any outliers from being found, but reviews could still have non-zero costs
Suggestion: Fix the outliers logic to handle the case where average cost is 0 but individual reviews have costs

dashboard/src/components/CostChart.tsx:119 - logic

Pie chart label extraction assumes model names follow a specific format with hyphens, which could break with different model naming conventions
Suggestion: Make the model name extraction more robust and handle various naming formats

Minor (3)

dashboard/src/app/costs/page.tsx:49 - logic

Date extraction using split('T')[0] is fragile and could break with different date formats
Suggestion: Use proper date parsing to extract the date part more reliably

dashboard/src/lib/supabase.ts:45 - testing

New TypeScript interfaces CostByRepo and CostByModel are defined but not used in the current implementation
Suggestion: Either use these interfaces in the code or remove them if they're not needed yet

dashboard/src/app/costs/page.tsx:47 - performance

Multiple reduce operations iterate over the same reviews array, which could be inefficient for large datasets
Suggestion: Consider combining the reduce operations into a single pass for better performance

Suggestion (2)

dashboard/src/app/costs/page.tsx:43 - style

Inline styles make the component harder to maintain and test
Suggestion: Consider extracting styles to CSS modules or styled components for better maintainability

dashboard/src/app/costs/page.tsx:152 - logic

Hard-coded limit of 8 repositories in the chart could hide important cost data
Suggestion: Consider making this configurable or showing all repositories with costs above a threshold

Concerns

  • Lack of error handling for database operations could cause the page to crash
  • Multiple data aggregation operations could be performance bottlenecks with large datasets
  • Hardcoded assumptions about data formats (dates, model names) could break with different data

Questions

  • Are the CostByRepo and CostByModel interfaces intended for future use, or should they be implemented now?
  • Should there be loading states for individual chart components during data processing?
  • Is there a maximum expected number of reviews this page should handle efficiently?
  • Should the outliers threshold (2x average) be configurable?

Model: claude-sonnet-4-20250514 | Cost: $0.0403 |
Tokens: 5833 in / 1518 out

@dtsong dtsong merged commit a432ca9 into main Jan 23, 2026
2 of 3 checks passed
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.

[Phase 5.2] Cost Attribution Dashboard

2 participants