feat: historical TPP backfill (Story 20.5)#106
Conversation
Add HistoricalTPPBackfillService that computes approximate TPP values from existing raw poll history and rollup data on first launch. - Raw poll backfill: pairs consecutive polls from last 24h, applies same delta/reset/confidence logic as PassiveTPPEngine - Rollup backfill: approximates delta from peak-min spread in hourly buckets for older data (week/month ranges) - Delta-only records for periods with utilization changes but no tokens - Two-layer idempotency: preference fast-path + DB slow-path - Force re-run via Settings "Re-run TPP Backfill" button - Fire-and-forget wiring in AppDelegate after log parser scan - 10 test cases covering all acceptance criteria
- Remove duplicate .week rollup query in processRollups — .month already includes all .week data (raw <24h + 5min 1-7d + hourly 7-30d), so iterating both produced duplicate DB records for the 0-7d window - Always set tppBackfillCompleted=true after runBackfill completes, even when force=true and totalMeasurements=0 (prevents repeated launch-path backfill attempts when no historical data exists) - DB slow-path idempotency check now queries both .passiveBackfill and .rollupBackfill sources; previously only checked .passiveBackfill, which would miss installs where only rollup records were stored - Change backfillServiceRef to private in AppDelegate (was internal, inconsistent with all other service refs) - Add 2 regression tests covering the force+empty preference fix and the rollup-only slow-path DB detection
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (18)
📝 WalkthroughWalkthroughThis PR implements historical TPP (token throughput) backfill functionality, adding a new service that processes raw polls and rollup data to generate historical TPP measurements, tracks completion state via preferences, and wires the service through the app's UI hierarchy with a force re-run button in Settings. Changes
Sequence DiagramsequenceDiagram
participant App as AppDelegate
participant BFS as HistoricalTPPBackfillService
participant Prefs as PreferencesManager
participant HDS as HistoricalDataService
participant LP as ClaudeCodeLogParser
participant Storage as TPPStorageService
App->>BFS: runBackfillIfNeeded()
BFS->>Prefs: tppBackfillCompleted
alt Already completed
BFS-->>App: return early
else First run or force=true
BFS->>Storage: getMeasurements (check existing)
alt Has existing records
BFS->>Prefs: set tppBackfillCompleted=true
BFS-->>App: return
else Empty or force=true
Note over BFS: Phase 1: Raw Polls
BFS->>HDS: getRecentPolls()
BFS->>LP: queryTokenAggregates(window)
BFS->>Storage: storeMeasurements(models + deltas)
Note over BFS: Phase 2: Rollups
BFS->>HDS: getHistoricalRollups()
BFS->>LP: queryTokenAggregates(window)
BFS->>Storage: storeMeasurements(rollup-backed)
BFS->>Prefs: set tppBackfillCompleted=true
BFS-->>App: return measurement count
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Summary
Story
20.5: Historical TPP Backfill (Nice-to-Have)
Test plan
Summary by CodeRabbit
New Features
Tests