Skip to content

feat(sleep): manual entry + HR-led fallback; fix(wear) + v25 features - #32

Merged
abdulsaheel merged 1 commit into
mainfrom
feat/sleep-rescue-and-wear-fix
Jun 30, 2026
Merged

feat(sleep): manual entry + HR-led fallback; fix(wear) + v25 features#32
abdulsaheel merged 1 commit into
mainfrom
feat/sleep-rescue-and-wear-fix

Conversation

@abdulsaheel

Copy link
Copy Markdown
Collaborator

Lands the sleep-detection rescue + wear-time fix. Also carries the two v25 commits (irregular-rhythm screen, HRR, BRV, auto-workout, coach read-only SQL) that this work was built on and that weren't yet on main.

Sleep rescue (Approaches 1 & 2)

For nights auto-detection misses (restless sleeper, loose band, gaps):

  • Manual entrysleep_override table (db v20), durable across finalization + algo bumps. User-given window is staged via analytics' forcedWindow path. Force re-derives even a locked day; no-raw clobber guard.
  • HR-led fallback — when accel-led detection finds nothing, propose the nocturnal HR dip (low-confidence) and prompt to confirm/edit.
  • sleep_source (auto / auto_fallback / manual / confirmed) threaded to the UI: manual-entry card, confirm banner, edit affordance.

Wear fix

Worn-time/coverage was defined as hr>0 — but PPG only locks on a still wrist with good contact (~sleep), so a 24 h-worn day showed ~7-8 h. Now record presence (gap-detected) in the worn_min scalar, _wearBlock, and the repo fallback.

kAlgoVersion 26 → 28.

Tests

flutter test --concurrency=1102 passing; flutter analyze clean (only pre-existing infos). Pairs with analytics PR #14.

🤖 Generated with Claude Code

Sleep rescue (Approaches 1 & 2) for nights auto-detection misses:
- sleep_override table (db v19->v20): durable manual/confirmed windows, stored
  separately from derived output so they survive finalization AND algo bumps.
- thread override + HR-led fallback + sleep_source through calendarDays ->
  prepareDerivationPayload -> prepareSleepSessionCandidate -> engine.
- finalization override: force re-derive an overridden day even when locked;
  skip the auto cache for it; no-raw clobber guard keeps a good manual result
  once raw is pruned (>14d).
- app_state setSleepOverride / confirmSleep / clearSleepOverride.
- Sleep screen: manual-entry card (no-sleep night), fallback confirm banner,
  manual badge (edit / use auto), and an edit affordance on auto nights.

Wear fix:
- worn-time / coverage / on-off segments were defined as hr>0, but PPG only
  locks on a still wrist with good contact (~sleep), so a 24h-worn day showed
  ~7-8h. Wear is now RECORD presence with gap detection. Fixed in the worn_min
  scalar, _wearBlock, and the repo fallback.

kAlgoVersion 26 -> 28 so affected days restage.
@abdulsaheel
abdulsaheel force-pushed the feat/sleep-rescue-and-wear-fix branch from 267ac3a to 14829be Compare June 30, 2026 18:15
@abdulsaheel
abdulsaheel merged commit 003150a into main Jun 30, 2026
@abdulsaheel
abdulsaheel deleted the feat/sleep-rescue-and-wear-fix branch June 30, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant