Skip to content

Prevent sleep detection across unobserved sensor gaps - #78

Draft
SalmaanRauf wants to merge 3 commits into
OpenStrap:mainfrom
SalmaanRauf:codex/sleep-gap-continuity
Draft

SalmaanRauf wants to merge 3 commits into
OpenStrap:mainfrom
SalmaanRauf:codex/sleep-gap-continuity

Conversation

@SalmaanRauf

@SalmaanRauf SalmaanRauf commented Sep 27, 2026 •

Copy link
Copy Markdown

Summary

  • Require distributed heart-rate coverage before bridging a sparse gravity interval.
  • Keep short-period smoothing from reconnecting sleep runs across a hard recording gap.
  • Make the sustained-wake test fixture timezone explicit.

Verification

  • Two synthetic gap regressions fail on the previous pin and pass with this change.
  • 78 focused analytics tests pass; one optional real-capture fixture test is skipped because its file is unavailable.
  • Dart analysis of the changed files reports no issues.

This changes sleep-window detection only. It does not establish stage accuracy or RR timing.

Summary by Sourcery

Prevent sleep-window detection from bridging unobserved recording gaps while retaining valid sleep continuity across short sensor holes.

Bug Fixes:

  • Prevent sleep detection from merging periods across recording gaps that exceed the observed-data threshold.
  • Preserve sleep sessions across short, bounded sensor holes while marking the missing interval as unobserved.

Enhancements:

  • Bound heart-rate-based bridging to valid, non-empty intervals within the supported sparse-gap duration.

Tests:

  • Add regressions covering long recording gaps, short sensor holes, and sustained wake behavior with an explicit timezone.

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Sep 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

Sleep detection now avoids inferring continuous sleep across unobserved intervals by requiring dense HR coverage for sparse-gap bridging and by preventing smoothing from crossing hard recording gaps. Regression coverage exercises both failure modes, and a fixture uses an explicit timezone.

Flow diagram for gap-safe sleep period detection

flowchart TD
    A[_hrSleepBandAcross] --> B{Dense HR coverage across gravity gap?}
    B -->|No| C[Do not bridge sleep runs]
    B -->|Yes| D[Evaluate mean HR against sleep band]
    D --> E{Sleep-band condition passes?}
    E -->|No| C
    E -->|Yes| F[_mergePeriods]
    F --> G{Observed gap within maxGapMin?}
    G -->|No| H[Preserve recording-gap split]
    G -->|Yes| I[Merge compatible sleep periods]
Loading

File-Level Changes

Change Details Files
Require continuous heart-rate evidence before joining sleep periods across sparse gravity gaps.
  • Reject gaps outside the permitted bridge duration or without at least two HR samples.
  • Require HR samples to cover both endpoints and remain within the configured spacing throughout the interval.
  • Use the covered samples to calculate the sleep-band mean heart rate.
lib/src/onehz/sleep/advanced_stager.dart
Preserve hard recording-gap boundaries during short-period smoothing.
  • Only consider neighboring periods for smoothing when both observed gaps are within the maximum gap threshold.
  • Use already-merged periods for predecessor checks and retain non-bridged current periods.
lib/src/onehz/sleep/advanced_stager.dart
Add regressions for sleep bridging across missing sensor data.
  • Verify a short rest before a long recording outage is not merged into the following night.
  • Verify endpoint-only HR samples cannot corroborate a sparse motion gap.
test/onehz/advanced_stager_test.dart
Make the sustained-wake fixture timezone-independent.
  • Pass an explicit zero timezone offset to the sleep segmentation fixture.
test/onehz/sleep_test.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

…ve edge hr so it split every 20-90 min hole and lost the sleep around it. the 90 min cap already stops the next-night merge
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.

2 participants