Back to Blocks
PXL-682Running
Urgent

📊 Consistent calorie totals across all your devices

Estimate5 points
Labels
data1-circesyncBug

What we're fixing:

After your meals sync between your iPhone, iPad, and Mac, the total calories for the day should be exactly the same on all devices. Currently, different devices can show different calorie totals for the same day—sometimes varying by several calories—and the numbers can even change when you swipe between days without making any edits. This task identifies why the day-level calorie calculation is inconsistent and ensures all devices show the same stable total after syncing.


Problem

After syncing meals and meal items between devices, the day's total energy value is inconsistent and unstable:

  • Different values on different devices: One device shows 7752 kcal, another shows 7759 kcal for the same day
  • Values changing without user action: Swiping the day back and forth caused the value to change: 7752 → 7758 → 7759 → 7754
  • Only affects energy: Macros and micros appear to be consistent across devices
  • Meal-level totals are correct: The nutrient bar in the meal headers shows the same values on both devices

Observations

What's Consistent

  • Individual meal energy values match between devices
  • Macro totals (protein, carbs, fat) are stable
  • Micro nutrient totals are stable
  • The issue only affects the day-level energy total

What's Inconsistent

  • Day-level total energy calculation
  • Value changes spontaneously when:
    • Swiping between days
    • Waiting a few moments
    • No user edits being made

Hypotheses

1. Rounding/Precision Issues

The energy total might be calculated differently in different places:

  • Summing meal energy values (already rounded)
  • Recalculating from macros (protein × 4 + carbs × 4 + fat × 9)
  • Different rounding strategies causing drift

2. Sync/State Management Race Condition

  • Background calculations updating while UI is refreshing
  • CoreData context conflicts between sync and UI layer
  • Cached values not being invalidated properly after sync

3. Macro-to-Energy Conversion Inconsistency

  • Some foods might store pre-calculated energy values
  • Others calculate energy from macros on-the-fly
  • Differences in which approach is used in different contexts

4. Incomplete Sync State

  • Some meal items might not be fully synced/hydrated
  • Related food data might be missing temporarily
  • Calculations might be running with incomplete data

Technical Context

Relevant Files to Investigate:

  • Day energy calculation logic
  • Meal item energy aggregation
  • Sync merge logic for meals/items
  • CoreData relationship loading (faulting issues?)

Questions to Answer:

  1. Where is day-level energy calculated? Multiple places?
  2. Is it stored or always calculated on-demand?
  3. How do we ensure all meal items are loaded when calculating?
  4. Are there any background recalculations that could cause UI updates?

Expected Behavior

  • Day-level energy total should be identical on all devices after sync completes
  • Value should be stable and not change unless user edits data
  • Calculation should be deterministic regardless of when/where it runs
  • Should match the sum of individual meal energy values shown in headers

Acceptance Criteria

  • Both devices show identical energy totals after sync (within 1 kcal tolerance for rounding)
  • Energy value remains stable when swiping between days
  • Energy value doesn't change spontaneously without user action
  • Day total matches sum of meal header values exactly
  • Root cause identified and documented
  • Fix verified across multiple sync scenarios

Impact

Severity: High - This affects the core accuracy of the app's primary metric User Trust: Users rely on these numbers for tracking; inconsistency erodes confidence Data Integrity: Suggests potential broader issues with sync or calculation logic

Created Dec 1, 2025, 6:01 PM · Updated Jan 6, 2026, 1:01 PM