fix: resolve sleep stage overlap and correct time asleep#1722
Conversation
PR Validation ResultsChange Detection
✅ All checks passed. Thank you! |
There was a problem hiding this comment.
Code Review
This pull request addresses issue #1379 by implementing a sweep-line flattening algorithm on the mobile client to resolve overlapping sleep data sources into a single, non-overlapping timeline based on stage priority. It also updates the server-side sleep duration and 'time asleep' calculations to consistently count only deep, light, and rem stages, excluding awake, in-bed, and unknown stages. Feedback was provided to add defensive null/undefined checks in the server's sumAsleepSeconds function to prevent TypeErrors, and to use shared workspace time utilities for date parsing and validation on the mobile client.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Tip
Help us review and merge your PR faster!
Please ensure you have completed the Checklist below.
For Frontend changes, please run
pnpm run validateto check for any errors.PRs that include tests and clear screenshots are highly preferred!
Note: AI-generated descriptions must be manually edited for conciseness. Do not paste raw AI summaries.
Description
What problem does this PR solve?
Multiple sources of sleep data were causing duplicate data when syncing through healthkit.
How did you implement the solution?
Merge the overlapping samples that were duplicates. When two sources disagree, the more specific stage wins. Existing data will need to be resync'ed.
Linked Issue: Closes #1379
How to Test
PR Type
Checklist
All PRs:
New features only:
Frontend changes (
SparkyFitnessFrontend/):pnpm run validateand it passes.en) translation file.Backend changes (
SparkyFitnessServer/):rls_policies.sqlfor any new user-specific tables.UI changes (components, screens, pages):
Mobile changes (
SparkyFitnessMobile/):Screenshots
Click to expand
Before
After
Notes for Reviewers