Skip to content

fix(insights): rank the Rest outcome on the Rest score, strap-only nights included - #2940

Open
matthiasthomas wants to merge 2 commits into
ryanbr:mainfrom
matthiasthomas:fix/insights-rest-outcome
Open

matthiasthomas wants to merge 2 commits into
ryanbr:mainfrom
matthiasthomas:fix/insights-rest-outcome

Conversation

@matthiasthomas

Copy link
Copy Markdown

What this PR does

Makes the "Rest" outcome in Insights and the Insights Hub the Rest score on both platforms, for the same nights.

Android picked DailyMetric.efficiency for the outcome it labels "Rest". That is a different metric, normally a 0–1 fraction shown as a whole percent, so group means read about "1%" and deltas rounded to zero. The Rest ↔ Charge relationship and Rest experiments read the same column.

Apple ranked the right metric but read only the imported sleep_performance series. A strap-only wearer had no Rest effects, relationship or experiments, while Today and Trends showed a Rest score for the same nights. The comment calls this import-only because there was "no daily column"; it landed in v1.80, two days before v2.6.0 added on-device Rest, and was later copied into the Hub.

Fix: both platforms resolve Rest through resolvedSeries: the import wins, else the on-device composite, else the composite derived from the day's totals. A night without a Rest score is absent and never falls back to efficiency.

Scope:

  • Charge, HRV and RHR are unchanged. On Apple the two private copies of the outcome read became one, Repository.insightsOutcomeDays.
  • The dose model is unaffected: its documented outcomes are Charge and HRV.
  • The Surface pages-behind on the sync chip while backfilling (#689/#815 follow-up) #833 snapshot stays correct. The engine derives Rest from the daily row it persists in the same transaction, so a re-scored night moves refreshSeq.
  • Android's Insights still use the 800-day window, for every outcome.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation
  • CI / tooling

How it was tested

  • New tests: InsightsRestOutcomeTests (Swift) and InsightsRestOutcomeTest (Kotlin) cover imported, computed and derived nights after a strap re-add, a night without Rest, the other three outcomes, and a ranked effect end to end. The Swift side also pins that a re-scored night drops the snapshot.
  • Without the fix: the Rest tests fail on both platforms. With it all pass.
  • Full StrandTests (macOS): 2,272 tests. The only failures are the two timezone tests fix(dates): show day-keyed dates on their own day in every time zone #2723 fixes; they also fail without this change. NOOPiOS builds.
  • Full testFullDebugUnitTest: 6,643 tests, 2 failures, both in RecoveryDriversTest, which also fail locally without these changes.
  • Checks: doc-comment lint, i18n audit, parity ledger and ratchet pass.
  • Not verified: not tried in a running app. Android's InsightsScreen outcome enum is private, so its half is checked as source. No BLE path is touched.

Checklist

  • Swift package tests pass for any package I touched (swift test in Packages/<name>): n/a, no package touched
  • Android unit tests pass if I touched android/: all but the 2 RecoveryDriversTest failures above
  • No new build warnings introduced
  • UI changes use only StrandDesign tokens: n/a, no styling change
  • No hardcoded hex frame bytes; protocol facts live in the schema / decoders
  • Follows the conventions in docs/CONTRIBUTING.md
  • I did not commit generated output (Strand.xcodeproj/) or any secrets/keystores

Related issues

None found.

🤖 Generated with Claude Code

matthiasthomas and others added 2 commits November 23, 2026 19:58
Insights and the Insights Hub picked DailyMetric.efficiency for the outcome
they label "Rest". That is a different metric from the sleep_performance
score Apple's Insights ranks, and normally a 0-1 fraction formatted as a
whole percent, so group means read about "1%" and deltas rounded to zero.
The Rest/Charge correlation and Rest experiments read the same column.

Both screens now read Rest through resolvedSeries with the active strap id,
the read Trends, Today and Health already use, so the outcome is 0-100 and
a night without a Rest score is absent. The dose model is unaffected: its
documented outcomes are Charge and HRV.

Apple's Insights still reads only the imported series, so strap-only nights
have a Rest outcome on Android and none there. That is left unchanged here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Insights and the Insights Hub read the imported sleep_performance series
alone, so a strap-only wearer had no Rest effects, Rest/Charge relationship
or Rest experiments while Today and Trends showed a Rest score. That read
predates on-device Rest (it landed two days before v2.6.0) and was copied
into the Hub later.

Both screens now load every outcome through one shared read. Rest goes
through resolvedSeries, the same read Android's Insights uses: the import
wins, else the on-device composite, else the composite derived from the
day's totals. Charge, HRV and RHR are unchanged.

The ryanbr#833 snapshot stays correct: the engine derives Rest from the daily row
it persists in the same transaction, so a re-scored night moves refreshSeq.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
n1c pushed a commit to n1c/noop that referenced this pull request Nov 26, 2026
…n the Rest score, strap-only nights included

ryanbr#2940

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CZyrZuBf2575a3s8MZTqNZ
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