Skip to content

Overview total ignores --project/--exclude while every detail panel applies them #865

Closed

Description

@GodCC6

What happens

With --project / --exclude, the top Overview panel counts the filtered-out projects while every detail panel below it obeys the filter, so the two cannot be reconciled.

npx codeburn report -p week \
  --exclude Projects/ai-invest-copilot \
  --exclude writing/publishing/automation \
  --exclude Projects/novel-writing-publish \
  --exclude ai/invest/copilot

Overview reported $7,962.65; the By Project rows summed to ~$5,503.70 — a ~$2,458.95 gap, which is the excluded projects' spend almost exactly. By Activity and By Model both summed into the same $5,500–5,600 band, so the detail panels agreed with each other and only the headline was off.

Re-measured later with --format json (the rolling -p week window had moved on, so absolute figures differ):

Overview total By Project sum gap
filtered $8,004.30 $5,575.45 +$2,428.85
unfiltered (control) $8,095.19 $8,166.12 −$70.93

Calls are off by the same mechanism (84,458 vs. the filtered corpus's 56,492). The small negative gap in the unfiltered control is a separate, pre-existing effect — the durable path counts whole local days out of the cache while the live parse filters turns by exact timestamp, so they differ at a rolling range's boundary.

Environment

  • codeburn --version: 0.9.19
  • Providers involved: claude (dominant), codex, opencode
  • Session history: ~/.claude/projects 1.2G, ~/.codex/sessions 2.3G, opencode 20M
  • daily-cache.v15.json: 93 days, 15 of them with no per-project split
  • macOS, Node 25.9.0

Not a parsing bug, so no JSONL snippet — it reproduces from the cache alone.

Root cause

buildDurablePeriod() in src/usage-aggregator.ts unions two sources for the headline:

  1. today — fp(await parseAllSessions(...)), where fp = filterProjectsByName(...): filtered.
  2. history — getDaysInRange(cache, ...), merged by unionDaysForPeriod(): never project-filtered.

Provider filtering does narrow the historical days (pf === 'all' ? allDays : allDays.map(d => sliceDayToProvider(d, pf))) — there was just no project-level counterpart, so cached days were counted whole regardless of the name filters. buildJsonReport() takes totalCostUSD straight from durable.data, which is why the headline overstates, while By Project reads the correctly-filtered durable.liveProjects.

DailyEntry.projects exists since cache v15, so the historical days can be sliced — which is what the PR below does.

The part that needs your call

ProjectDayStats is { cost, calls, savingsUSD, sessions, path? }. Cost / calls / sessions / savings slice exactly, but there is no per-project split for tokens, models or categories, and days recorded before v15 have no split at all. Two decisions fall out of that, and I'd rather you set the policy than have me pick silently:

  1. tokens / models / categories under a project filter. Take them from the (already project-filtered) live parse — exact per project, consistent with the By Model / By Activity panels, but bounded by source retention, so a filtered lifetime query stops counting tokens from days whose logs are gone? Or keep the day-level values, which stay complete but overstate by exactly the excluded projects?
  2. days with no project split at all (pre-v15, or a pre-v15 provider slice carried into a v15 day — 15 of 93 days, $2,214.63, on my cache). Leave them out of a filtered total and state the amount, or fold them in? Leaving them out understates by a stated figure; folding them in keeps --project X claiming spend that provably isn't X's. The second reading is closer to the never-lose-history invariant, which is why I don't want to decide it unilaterally.

Adjacent, same root cause

The menubar / status provider list has the same gap: usage-aggregator.ts:632-635 builds unfilteredProviderDays from getDaysInRange(cache, ...) (unfiltered) plus getTodayAllDays() (filtered), so per-provider costs still ignore --project/--exclude for historical days. Not touched in the PR, since narrowing it also changes which providers appear in the list at all.

Process note

I opened #864 with a fix before reading CONTRIBUTING.md properly, so this issue is filed after the fact rather than before the work — sorry for doing it backwards. Before You Start asks for an issue comment and maintainer sign-off before writing code for a feature or new provider; I read this as a bug fix rather than a feature, but since it carries the two policy questions above it clearly should have started here.

For transparency about that PR's history: its first push had two things your guidelines rule out, both since fixed by force-push — an AI co-author trailer on the commit (removed; block-claude-coauthor passes locally now), and an accidental src/data/* pricing-snapshot diff picked up from npm run build (reverted; the PR is now 5 files, +500/−4).

If you'd prefer a different approach on either policy question, or want the PR closed and reworked, just say so and I'll follow your lead.

Activity

  1. iamtoruk commented on Aug 3, 2026

    @iamtoruk
    Member

    Fixed by #864 (merged in 2de4d10). buildDurablePeriod now slices the cache-sourced historical days to the active --project/--exclude filter via the new sliceDayToProject, so the Overview total reconciles with By Project / By Activity / By Model. Days with no per-project split (pre-v15 cache) are reported as a footnoted unattributedCostUSD rather than silently folded in. Verified end to end: filtered Overview == By Project sum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions