Fix supplements auto-adding to daily totals without being taken#217
Merged
Conversation
Supplements were being added to daily totals for every active supplement regardless of whether the user had actually marked it taken. Both the /today endpoint and /today/streak-history summed nutrients from all is_active supplements, missing the "taken today" check. Now both paths join SupplementLog and only credit nutrients for supplements the user logged as taken on the relevant day. The streak history credits each day from that day's logs instead of blanket-applying one set across all 30 days. The Supplements tab UI is updated to aggregate and describe only supplements taken today.
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.
Problem
Supplement nutrients (calories, sat fat, fiber, sugar, protein) were being added to the user's daily totals for every active supplement, regardless of whether the user had actually marked it as taken today. The "did I actually take this today" gate was missing — the code assumed any
is_activesupplement was consumed.This is what produced the screenshot the user reported: totals showing supplement-derived nutrients on a day where nothing was logged as taken.
Root cause
backend/luma/api/today.pyhad two spots that summednutrients_per_doseover allis_activesupplements with no reference toSupplementLog:/today— added all active supplement nutrients unconditionally./today/streak-history— computed one supplement total and blanket-applied it to every one of the 30 days, which also meant a newly-added supplement retroactively altered past days.The
SupplementLogtable and a workingPOST/DELETE /health/supplements/{id}/logflow already existed (the list endpoint already returnstaken_today); the totals calculation simply ignored it.Fix
/today: joinSupplementLogand only credit nutrients for active supplements logged as taken within today's local-timezone window./today/streak-history: build a per-day map of supplement contributions from that day's logs, so each day reflects only what was actually taken (and supplement-only days still count).frontend/src/routes/health.tsx: the Supplements tab now aggregates and labels only supplements taken today ("Taken Today"), and the helper copy/empty states reflect that only supplements you mark as taken are integrated into daily totals.Verification
test_health_logging.pypasses (3 passed);mypy luma/api/today.py --ignore-missing-importsclean; module imports clean.pnpm type-checkclean,pnpm lint0 errors,pnpm test97 passed.https://claude.ai/code/session_01BLk2x7KN3NanY7HMGwH4ZR
Generated by Claude Code