Skip to content

fix(daily-cache): discard pre-v5 caches to drop stale provider rollups#297

Merged
iamtoruk merged 1 commit intomainfrom
fix/daily-cache-force-rebuild
May 10, 2026
Merged

fix(daily-cache): discard pre-v5 caches to drop stale provider rollups#297
iamtoruk merged 1 commit intomainfrom
fix/daily-cache-force-rebuild

Conversation

@iamtoruk
Copy link
Copy Markdown
Member

Found while smoke-testing the recent stack against main. PR #296 bumped `DAILY_CACHE_VERSION` from 4 to 5 but left `MIN_SUPPORTED_VERSION` at 2. The migration path only fills in missing default fields; it does not recompute the per-day providers / categories / models rollups because the raw sessions are not retained in the cache.

Effect: the macOS menubar's `current.providers.cursor` showed the orphan-bucket subtotal instead of the full Cursor cost for any historical day whose daily entry was computed before #296 landed.

Live-test on a real machine:

```

Against a v4 cache migrated to v5:

menubar-json --period all -> providers.cursor = $3.78
report --provider cursor -p all -> overview.cost = $4.08

After clearing daily-cache.json:

menubar-json --period all -> providers.cursor = $4.08 (matches)
```

The $0.30 gap was the workspace projects whose costs were no longer aggregated under the `cursor` label by the new code.

Fix: raise `MIN_SUPPORTED_VERSION` to 5 so any cache with `version < DAILY_CACHE_VERSION` is renamed to `.bak` and the cache is recomputed from scratch on next run.

Test plan

  • vitest: 46 files / 654 tests pass.
  • Test for the migration case updated to assert the new discard-and-bak behavior.
  • Live verify: `menubar-json --period all` and `report --provider cursor -p all` now reconcile.

PR #296 (Cursor per-project breakdown) bumped DAILY_CACHE_VERSION
from 4 to 5 but left MIN_SUPPORTED_VERSION at 2. The migration
path (isMigratableCache + migrateDays) only fills in missing
default fields; it does NOT recompute the providers / categories
/ models rollups from session data, because raw sessions are not
retained in the cache. So a v4 cache migrated to v5 carried
forward its old per-day provider totals (single 'cursor' bucket)
for the full retention window.

Effect on users post-#296: the macOS menubar's
`current.providers.cursor` would show the orphan-bucket subtotal
instead of the full Cursor cost for any historical day whose
daily entry was computed before #296 landed. Live-test on my
machine showed cursor=$3.78 against a migrated v4 cache vs
cursor=$4.08 (correct) after the daily cache was discarded — the
$0.30 gap was the workspace projects whose costs were no longer
aggregated under the 'cursor' label by the new code.

Fix: raise MIN_SUPPORTED_VERSION to 5 so any cache with
version < DAILY_CACHE_VERSION is renamed to `.bak` and the cache
is recomputed from scratch on next run. The recompute is the same
operation that backfills the cache for a new user, so the cost is
a one-time cold-path hit (~3s on the test machine).

Test for the migration case updated to assert the new
discard-and-bak behavior. Full suite: 46 files / 654 tests pass.
@iamtoruk iamtoruk merged commit d142bd9 into main May 10, 2026
3 checks passed
@iamtoruk iamtoruk deleted the fix/daily-cache-force-rebuild branch May 10, 2026 23:06
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