fix: trigger score pipeline after health sync for recent dates with no prior backend summary#55
Draft
Copilot wants to merge 2 commits into
Draft
fix: trigger score pipeline after health sync for recent dates with no prior backend summary#55Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
…no prior summary existed When a user has HealthKit sleep data for recent dates (within 14 days) but the backend has no summary for those dates (e.g. because the app was not opened and health data was never uploaded), the previous code called triggerOnDemandPipelinesIfNeeded with a nil resolvedSummary, which returned immediately without triggering the score pipeline. The health data was then uploaded by syncRecentDateIfNeeded, but no score was ever computed. Fix: after syncRecentDateIfNeeded uploads health data and the summary is refreshed, check whether the score pipeline was not already triggered (onDemandTriggerResult.attemptedScore == false) and a summary is now available (resolvedSummary != nil). If both conditions hold, call triggerOnDemandPipelinesIfNeeded again so the backend can compute the score and subsequently surface recommendations. Agent-Logs-Url: https://github.com/SleepFocus/SleepFocus_Frontend/sessions/721ff11d-c1ae-4ce7-a851-c0e6963ec073 Co-authored-by: austinkimchi <40729751+austinkimchi@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix sleep score not triggered for 14-day range
fix: trigger score pipeline after health sync for recent dates with no prior backend summary
Apr 12, 2026
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.
When the app hasn't been opened for multiple days, recent dates (within 14 days) with HealthKit data but no backend summary never get scored — blocking recommendations from appearing.
Root cause
triggerOnDemandPipelinesIfNeededis called beforesyncRecentDateIfNeededinHomeSummaryStore.load(). When the backend has no entry for a date,resolvedSummaryisnil, and the function exits early:Health data is then uploaded by
syncRecentDateIfNeeded, but the score pipeline is never triggered — so the backend has data but never computes a score.Fix
After
syncRecentDateIfNeededuploads health data and the summary is refreshed, trigger the score pipeline if:!onDemandTriggerResult.attemptedScore)resolvedSummary != nil)This preserves existing behavior for dates where a summary was already present (pipeline triggered before sync,
attemptedScore == true) and correctly handles the case where health data needed uploading first.