feat(sleep): split same-day sleep into sessions + Day carousel (#59)#83
Merged
saksham2001 merged 7 commits intoJul 16, 2026
Merged
Conversation
…am2001#59) Ring history holding a nap plus the main night on one waking day was merged into a single ~16h SleepSession with a broken hypnogram. Split sleep into distinct sessions and page between them on the Day view. - SleepSegmentation.segment + SleepService.reconcileWakingDay derive a day's sessions from its stage blocks (a >=60 min gap in recorded sleep starts a new session); idempotent. - persistSleepTimeline accumulates a packet's blocks, then reconciles. - migrateSleepSessionSegmentsIfNeeded (sleepSessionSegment.v1) one-time re-splits legacy merged days. - Sleep > Day: horizontal carousel + dots + per-session caption; single-session days render unchanged. - SleepInsights.collapseByDay: aggregate views count each day once, so a nap never skews the nightly average or "nights tracked". - sleepForDate returns the day's longest session. - 11 new tests (segmentation, reconcile idempotency, migration). Closes saksham2001#59
This was referenced Jul 12, 2026
…are aggregates Follow-up review of this branch surfaced four issues; fix them before merge: - reconcileWakingDay reused day-rows by positional index after sorting by startAt, so an out-of-order sync (a nap arriving before the night it precedes) silently flipped a row's identity — misattributing anything keyed to that SleepSession.id (e.g. a coach summary). Match each segment to the existing row whose prior time-range overlaps it instead. - reconcileWakingDay inserted a DerivedUpdateRow (and bumped syncedAt) per segment on every call, unconditionally — re-syncing an unchanged day spammed the audit table. Emit the change signal only when a row's bounds or block set actually changed. - durationConsistency computed variance over non-collapsed sessions against a collapsed mean, so a nap spuriously inflated the SD and flipped the "Variable nights" chip. Collapse first. - aggregateCoach and the aggregate hero counted naps as extra "nights tracked" while their averages collapsed by day. Collapse the count too.
…le's change signal on block re-point
…leepTimeline to skip full-table scans
…nd change-gated reconcile
saksham2001
approved these changes
Jul 16, 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.
Closes #59.
Problem
When a day held more than one sleep (a nap plus the main night), ring history for that waking day was merged into a single ~16 h
SleepSessionwith a broken hypnogram — the "UI breaks" reported in the issue.What this does
Splits sleep into distinct sessions and lets you page between a day's sessions on the Sleep → Day view.
SleepSegmentation.segment+SleepService.reconcileWakingDay— derive a day's sessions from its stage blocks; a run of ≥ 60 min with no recorded sleep starts a new session. Idempotent.persistSleepTimeline— accumulate a packet's blocks, then reconcile the day into sessions.migrateSleepSessionSegmentsIfNeeded(sleepSessionSegment.v1) — one-time re-split of legacy merged days, gated + off the render path.SleepInsights.collapseByDay— Week/Month/Year count each day once, so a nap never skews the nightly average or "nights tracked".sleepForDatereturns the day's longest session.Tests
11 new tests (segmentation,
reconcileWakingDayidempotency, migration). FullSleepServiceTestssuite: 23 passing.Notes
Two follow-ups build on this branch: day navigation (browse past days) and a dev-only seed update for multi-session demo data.