fix(daily-cache): discard pre-v5 caches to drop stale provider rollups#297
Merged
fix(daily-cache): discard pre-v5 caches to drop stale provider rollups#297
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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