Repository navigation
fix(oura): stop HR-only sleep from double-counting a ring-bounded night - #3
Merged
Merged
Conversation
On an Oura wake-day the ring's native-resting sleep window and the upstream HR-only fallback both produced sessions. In the field (2026-09-24) the HR-only spine built a 934-min block across a whole daytime beside the ring's night, the day scored 1,379 min (matched=2), and the ryanbr#899 overlap heal (>= 30 min overlap, longest wins) then deleted the adjacent real 09-23 night on every pass. The HR-only spine is now a fallback only: for an Oura owner it is skipped when the ring supplies at least one native-resting sleep window for that wake day (gate reason `oura-resting-sleep`). Manual edits alone, days without ring evidence, and WHOOP keep the existing behaviour. With nothing re-banking the stale block, the heal's fresh-witness rule drops it in favour of the re-scored night (pinned with the field timestamps). versionCode 539. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
What this PR does
Stops Oura nights from being double-counted and a real night from being deleted.
On an Oura wake-day the ring's native-resting sleep window and the upstream HR-only fallback both produced sessions. Field log (build 536, 2026-09-26):
hr-only spine day=2026-09-24 … longestMin=934built a block from Wed 10:44 to Thu 02:18, across a whole daytime, beside the ring's resting-window night.sleep day=2026-09-24 totalSleepMin=1379 … matched=2: both were scored (~23 h).Dedup(#1284): dropped [1790147107 -> 1790177240] min=502 … kept [1790174640 -> 1790230739] min=934, repeated on every pass: the Publish the command result code on Apple, as Android already does (#894) ryanbr/noop#899 overlap heal (≥ 30 min overlap, longest wins) deleted the real Tue→Wed night (03:05–11:27) because the bogus block overlapped it by 43 min.Fix: in
IntelligenceEngine.resolveSleepEvidence, the HR-only spine is a fallback only. For an Oura owner it is skipped when the ring supplies at least one native-resting sleep window for that wake day (new gate reasonoura-resting-sleep). Manual edits alone, days with no ring evidence, and WHOOP keep the existing behaviour. Once nothing re-banks the stale block, the heal's fresh-witness rule drops it in favour of the re-scored night.Android-only (the ring's resting-window hints exist only in this fork). versionCode 539.
Type of change
How it was tested
OuraSleepEvidencePrecedenceTest(5): ring resting sleep suppresses the HR-only fallback (failed before the fix, passes after); the fallback still runs with no ring evidence, with only a manual edit, and on WHOOP; the field-timestamp heal keeps the night and drops the stale block.OuraSleepRestorationTest,SleepStagerHrOnly*andIntelligenceEngineJacocoBudgetTestpass.RecoveryDriversTestfloat assertions.hr-only gate … reason=oura-resting-sleepon ring nights and no 900+ min sessions.Related issues
Refs #2
🤖 Generated with Claude Code