fix(sleep): persist import edits and recalculate sleep debt#838
fix(sleep): persist import edits and recalculate sleep debt#838DX23876 wants to merge 3 commits into
Conversation
ryanbr
left a comment
There was a problem hiding this comment.
Good diagnosis — the CachedSleepSession-has-no-deviceId root cause is right, and resolving the owner against the same union the reads use is the correct shape.
-
Parity. Android has the same stale-debt bug, at
SleepModelLogic.kt:194(imported.debtMin[d.day] ?: fallback) and again at:209fortrendDebtHours. An edited night there still reads the export's original debt. Needs the twin in this PR, or a stated reason not to. -
Say that the owner-resolution half is Swift-only on purpose. Android's
updateSleepSessionTimestakes aSleepSessionthat carries its owndeviceId, so that bug cannot exist there. Worth a line in the PR body, otherwise the missing Android change reads as an oversight rather than a deliberate one. -
Question, not a blocker: on an edited day you drop the imported debt entirely and fall back to
need − asleep. Would adjusting the imported value by the duration delta keep more of the export's accuracy than replacing it with our approximation?
Also worth noting no CI covers Strand/ or StrandTests, so your local run is the only verification this has.
|
Thanks, that was a helpful catch. I pushed the Android twin and changed the edited-day calculation to keep the imported baseline and apply the asleep-duration delta instead of replacing it with Both the Android tile and trend now use:
The owner-resolution half remains Swift-only intentionally: Android's For verification, the macOS build and |
What this PR does
sleep_debt_minbaseline after an edit and adjusts it by the exact asleep-duration delta:max(0, importedDebt + originalImportedAsleep - editedAsleep).SleepSessionalready carries its owningdeviceId, so that failure mode cannot occur there.Android behavior changes only where required for sleep-debt parity. No BLE, protocol, migration, or generated-project behavior changed.
Type of change
How it was tested
StrandTestspassed in GitHub Actions on macOS 15. The local equivalent passed 967 tests, with 1 expected Xiaomi fixture skip.NOOPiOSsimulator build passed in the same GitHub Actions run on macOS 26.python3 Tools/i18n_audit.py --ci upstream/mainpassed for Android and all Apple catalogs.git diff --checkpassed.assembleFullDebugpassed in GitHub Actions. Its unit-test compilation is currently blocked by three untouchedDeviceRegistryDaotest fakes that predate this PR and do not implement newly required DAO members; this PR does not mix that independent test-harness repair into the sleep fix.Checklist
StrandTestspass.Strand.xcodeproj/) or secrets/keystores committed.