Skip to content

[codex] fix date range aggregation accuracy#130

Merged
ya-nsh merged 1 commit into
mainfrom
codex/sanity-data-flows
May 17, 2026
Merged

[codex] fix date range aggregation accuracy#130
ya-nsh merged 1 commit into
mainfrom
codex/sanity-data-flows

Conversation

@ya-nsh

@ya-nsh ya-nsh commented May 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • Make aggregation average daily tokens/cost over the explicit selected date range instead of only active days.
  • Thread the selected range through CLI, MCP, TUI, and terminal renderer flows so sparse periods report correct totals and deltas.
  • Harden MCP date range validation for invalid dates, non-positive days, and since-after-until inputs.
  • Fix inclusive range labels in live and PNG output so single-day windows render as 1 DAYS.

Root Cause

aggregate() inferred totalDays from the first and last active usage day. For sparse selected ranges, that made averages and compare deltas too high because inactive days inside the requested window were ignored.

Validation

  • PATH="/Users/yansh/.bun/bin:$PATH" bun run test passed: 12 successful Turbo tasks.
  • PATH="/Users/yansh/.bun/bin:$PATH" bun run check passed: 10 successful Turbo tasks.
  • Fixture-backed data invariant audit passed across Claude Code, Codex old/current, Cursor, and merged aggregation totals.
  • Manual Computer/Chrome inspection of the live single-day dashboard showed the corrected 1 DAYS header and clean layout.
  • PATH="/Users/yansh/.bun/bin:$PATH" bun run lint still fails on existing unrelated lint debt: unused symbols and script console warnings outside this change scope.

Notes

Turbo still emits the existing bun.lock parse/not-found warning in this worktree, but test and check tasks complete successfully.

@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@ya-nsh has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 35 minutes and 54 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ffc973ef-1485-4dc3-8b7c-9994c2780974

📥 Commits

Reviewing files that changed from the base of the PR and between 7a52932 and 7a7a3e0.

📒 Files selected for processing (22)
  • packages/cli/src/cli.ts
  • packages/cli/src/data-loader.ts
  • packages/core/src/aggregation/aggregate.ts
  • packages/core/src/aggregation/aggregation.test.ts
  • packages/core/src/aggregation/compare.test.ts
  • packages/core/src/aggregation/compare.ts
  • packages/mcp/src/resources/overview.ts
  • packages/mcp/src/server.test.ts
  • packages/mcp/src/shared/date-range.test.ts
  • packages/mcp/src/shared/date-range.ts
  • packages/mcp/src/tools/compare-periods.ts
  • packages/mcp/src/tools/get-cost-breakdown.ts
  • packages/mcp/src/tools/get-efficiency-advice.ts
  • packages/mcp/src/tools/get-streaks-and-habits.ts
  • packages/mcp/src/tools/get-usage-summary.ts
  • packages/renderers/src/live/__tests__/live-server.test.ts
  • packages/renderers/src/live/template.ts
  • packages/renderers/src/png/__tests__/terminal-card.test.ts
  • packages/renderers/src/png/terminal-card.ts
  • packages/renderers/src/terminal/dashboard-model.ts
  • packages/renderers/src/terminal/tab-views/provider-view.ts
  • packages/tui/src/lib/data.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/sanity-data-flows

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

const { data, warnings } = await loadProviderData(providers, range);
const merged = mergeProviderData(data);
const stats = aggregate(merged, range.until);
const stats = aggregate(merged, range.until, range);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compare-periods still constructs currentRange/previousRange directly instead of going through the new validation path, so invalid dates or since > until can flow into aggregation here and return misleading stats rather than an MCP error. Please route these ranges through the shared validator or equivalent before loading/aggregating.

@ya-nsh ya-nsh force-pushed the codex/sanity-data-flows branch from 424d591 to 7a7a3e0 Compare May 17, 2026 10:27
@ya-nsh ya-nsh marked this pull request as ready for review May 17, 2026 10:28
@ya-nsh ya-nsh merged commit 9dadccf into main May 17, 2026
2 checks passed
@ya-nsh ya-nsh deleted the codex/sanity-data-flows branch May 17, 2026 10:29
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