fix(analytics): a snapshot row with one unknown monthly cost stores a partial total_usage as known #1423
Description
Found by both independent reviews of #1287. The bug predates that PR. Related: #151 (zero-vs-absent conflation).
Problem: buildSnapshots in internal/analytics/collector.go (around lines 186-194) sets usageKnown as soon as any purchase in a snapshot row has a MonthlyCost. In a row that mixes a recurring purchase with one whose MonthlyCost is nil (for example all-upfront), the stored total_usage is the partial sum, and it is marked as known. Commitment is handled correctly: commitmentUnknown is set when any UpfrontCost is nil.
Effect: #1287 makes the rollup views return NULL whenever any input is unknown, but a partial value stored as known gets past that. Nothing reads total_usage today (QueryMonthlyTotals selects savings, coverage and count only), so no user sees a wrong number yet.
Fix: treat usage the same way as commitment. One nil MonthlyCost in the row makes total_usage unknown (nil). A known 0 stays 0. Add a regression test with a mixed row, and with a row where every cost is known.
Activity
IAmJSD commentedon Oct 26, 2026
Claiming: working on this