Skip to content

Web dashboard Cache read/write cards sum entire history instead of current period #583

Description

@Llldmiao

Bug Description

The web dashboard (codeburn web -p 30days) shows incorrect values for the Cache read and Cache write stat cards. They display totals from the entire history.daily array (up to 365 days of backfill), rather than only the data within the user-selected period (e.g. 30 days).

Steps to Reproduce

  1. Run codeburn report -p 30days in the terminal
  2. Run codeburn web -p 30days and open the web dashboard
  3. Compare the "cached" value in the terminal with the "Cache read" card in the web UI

Expected Behavior

Both views should show the same Cache read value for the same period (30 days).

Actual Behavior

  • Terminal (report -p 30days): shows 1391.1M cached
  • Web (web -p 30days): shows Cache read: 2.07B

The web value is ~1.5x larger because it sums over ~365 days of history data.

Root Cause

In the web frontend (dist/dash/assets/index-*.js), the Cache read/write cards compute their values by reducing over the entire e.history.daily array:

l = (e?.history.daily) ?? []
o = l.reduce((b,x) => b + x.cacheWriteTokens, 0)  // Cache write card
c = l.reduce((b,x) => b + x.cacheReadTokens, 0)    // Cache read card

However, history.daily is populated from BACKFILL_DAYS = 365 days of cached data (for the trend chart), not limited to the current period. Meanwhile, other cards (Cost, Calls, Sessions, Tokens in/out) correctly use e.current which is properly scoped to the selected period.

Suggested Fix

The frontend should use e.current.tokens.cacheRead and e.current.tokens.cacheWrite (which are correctly scoped to the period in buildMenubarPayload) instead of summing history.daily.

Alternatively, filter history.daily to only include dates within the selected period before summing.

Environment

  • codeburn version: 0.9.14
  • OS: macOS (Darwin 25.3.0)
  • Node: v24.13.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions