Repository navigation
oura: extract the history-drain/resume-cursor decisions into a pure, tested core (#291 follow-up) - #306
Merged
Conversation
…tested core (#291 follow-up) The #91 drain guards + resume-cursor logic lived untested inline in OuraLiveSource (app-target BLE) — which is exactly why it silently regressed when the Oura BLE stack was refactored (#291: "lost when refactoring"). Move the DECISIONS into a pure OuraHistoryDrain in OuraProtocol so they're pinned by unit tests, not just on-device observation: - drain-to-zero + stall guard (bytes_left must shrink; stop after 3 flat summaries) + 300s deadline guard, keeping banked progress on a forced stop - stored-ring-time high-water mark + reboot flag (a real sample older than the seek) - resume-cursor commit (advance only if forward AND resolves; reboot -> 0 full pull) - loaded-cursor plausibility-ceiling sanitize OuraLiveSource keeps ALL I/O — anchor resolution, persistence, logging, the historyCursorAdvanced emit — and now delegates every decision to the drain core. Behaviour-preserving: each site maps 1:1 to the extracted logic (verified by diff). Also de-versions the [cursor-fix v1] log marker to [cursor-fix]. 14 new OuraHistoryDrainTests + the existing 91 pass under swift test (105/105, run on Linux — OuraProtocol is pure). OuraLiveSource compile: app-build.
ryanbr
added a commit
that referenced
this pull request
Jul 12, 2026
…latforms CI-test the parity (#286 follow-up) (#307) dataRangeNewestUnix decodes strapNewestTs, which gates automatic sync (isFutureDatedNewest -> BackfillPolicy), so it must stay byte-identical Swift/ Kotlin. #286 left it inline in app-target BLEManager/WhoopBleClient with a Kotlin test only — a Swift-side edit could silently drift the parity (the same gap the Oura #306 follow-up closed). Move the pure scan into WhoopProtocol.DataRange (Swift, builds+tests on Linux) and com.noop.protocol.DataRange (Kotlin), byte-identical twins. BLEManager and WhoopBleClient keep their signatures as thin wrappers that pass their own futureSkew constant, so all call sites + the existing DataRangeScanTest are unchanged. Adds DataRangeTests (Swift) mirroring the Kotlin fixtures — the real WHOOP 4.0 offset-8 frames + the future/skew cases. WhoopProtocol swift test 259/259 incl. 4 new DataRangeTests (run on Linux); Android compileFullDebugKotlin + DataRangeScanTest green. BLEManager compile: app-build.
DX23876
pushed a commit
to DX23876/noop
that referenced
this pull request
Jul 22, 2026
…tested core (ryanbr#291 follow-up) (ryanbr#306) The ryanbr#91 drain guards + resume-cursor logic lived untested inline in OuraLiveSource (app-target BLE) — which is exactly why it silently regressed when the Oura BLE stack was refactored (ryanbr#291: "lost when refactoring"). Move the DECISIONS into a pure OuraHistoryDrain in OuraProtocol so they're pinned by unit tests, not just on-device observation: - drain-to-zero + stall guard (bytes_left must shrink; stop after 3 flat summaries) + 300s deadline guard, keeping banked progress on a forced stop - stored-ring-time high-water mark + reboot flag (a real sample older than the seek) - resume-cursor commit (advance only if forward AND resolves; reboot -> 0 full pull) - loaded-cursor plausibility-ceiling sanitize OuraLiveSource keeps ALL I/O — anchor resolution, persistence, logging, the historyCursorAdvanced emit — and now delegates every decision to the drain core. Behaviour-preserving: each site maps 1:1 to the extracted logic (verified by diff). Also de-versions the [cursor-fix v1] log marker to [cursor-fix]. 14 new OuraHistoryDrainTests + the existing 91 pass under swift test (105/105, run on Linux — OuraProtocol is pure). OuraLiveSource compile: app-build.
DX23876
pushed a commit
to DX23876/noop
that referenced
this pull request
Jul 22, 2026
…latforms CI-test the parity (ryanbr#286 follow-up) (ryanbr#307) dataRangeNewestUnix decodes strapNewestTs, which gates automatic sync (isFutureDatedNewest -> BackfillPolicy), so it must stay byte-identical Swift/ Kotlin. ryanbr#286 left it inline in app-target BLEManager/WhoopBleClient with a Kotlin test only — a Swift-side edit could silently drift the parity (the same gap the Oura ryanbr#306 follow-up closed). Move the pure scan into WhoopProtocol.DataRange (Swift, builds+tests on Linux) and com.noop.protocol.DataRange (Kotlin), byte-identical twins. BLEManager and WhoopBleClient keep their signatures as thin wrappers that pass their own futureSkew constant, so all call sites + the existing DataRangeScanTest are unchanged. Adds DataRangeTests (Swift) mirroring the Kotlin fixtures — the real WHOOP 4.0 offset-8 frames + the future/skew cases. WhoopProtocol swift test 259/259 incl. 4 new DataRangeTests (run on Linux); Android compileFullDebugKotlin + DataRangeScanTest green. BLEManager compile: app-build.
simoncad7
pushed a commit
to simoncad7/noop
that referenced
this pull request
Aug 17, 2026
…tested core (ryanbr#291 follow-up) (ryanbr#306) The ryanbr#91 drain guards + resume-cursor logic lived untested inline in OuraLiveSource (app-target BLE) — which is exactly why it silently regressed when the Oura BLE stack was refactored (ryanbr#291: "lost when refactoring"). Move the DECISIONS into a pure OuraHistoryDrain in OuraProtocol so they're pinned by unit tests, not just on-device observation: - drain-to-zero + stall guard (bytes_left must shrink; stop after 3 flat summaries) + 300s deadline guard, keeping banked progress on a forced stop - stored-ring-time high-water mark + reboot flag (a real sample older than the seek) - resume-cursor commit (advance only if forward AND resolves; reboot -> 0 full pull) - loaded-cursor plausibility-ceiling sanitize OuraLiveSource keeps ALL I/O — anchor resolution, persistence, logging, the historyCursorAdvanced emit — and now delegates every decision to the drain core. Behaviour-preserving: each site maps 1:1 to the extracted logic (verified by diff). Also de-versions the [cursor-fix v1] log marker to [cursor-fix]. 14 new OuraHistoryDrainTests + the existing 91 pass under swift test (105/105, run on Linux — OuraProtocol is pure). OuraLiveSource compile: app-build.
simoncad7
pushed a commit
to simoncad7/noop
that referenced
this pull request
Aug 17, 2026
…latforms CI-test the parity (ryanbr#286 follow-up) (ryanbr#307) dataRangeNewestUnix decodes strapNewestTs, which gates automatic sync (isFutureDatedNewest -> BackfillPolicy), so it must stay byte-identical Swift/ Kotlin. ryanbr#286 left it inline in app-target BLEManager/WhoopBleClient with a Kotlin test only — a Swift-side edit could silently drift the parity (the same gap the Oura ryanbr#306 follow-up closed). Move the pure scan into WhoopProtocol.DataRange (Swift, builds+tests on Linux) and com.noop.protocol.DataRange (Kotlin), byte-identical twins. BLEManager and WhoopBleClient keep their signatures as thin wrappers that pass their own futureSkew constant, so all call sites + the existing DataRangeScanTest are unchanged. Adds DataRangeTests (Swift) mirroring the Kotlin fixtures — the real WHOOP 4.0 offset-8 frames + the future/skew cases. WhoopProtocol swift test 259/259 incl. 4 new DataRangeTests (run on Linux); Android compileFullDebugKotlin + DataRangeScanTest green. BLEManager compile: app-build.
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.
Follow-up to #291. Regression-proofs the #91 fix.
Why
The #91 drain guards + resume-cursor logic lived untested, inline in
OuraLiveSource(app-target BLE) — which is exactly why it silently regressed when the Oura BLE stack was refactored (#291: "lost when refactoring"). This moves the decisions into a pure, unit-tested type so it can't happen a third time.What
New
OuraHistoryDrain(inOuraProtocol, pure) owns the decisions:OuraLiveSourcekeeps all I/O — anchor resolution, persistence, logging, thehistoryCursorAdvancedemit — and now delegates every decision todrain. Behaviour-preserving: each of the ~7 sites maps 1:1 to the extracted logic. Also de-versions the[cursor-fix v1]marker →[cursor-fix].Verification
OuraHistoryDrainTests+ the existing 91 pass — I ranswift testlocally on Linux (OuraProtocol is pure): 105/105. (Writing the tests already caught one flawed test premise — a 'not forward' case that was actually the reboot path — which is precisely the value here.)OuraLiveSourcecompile: app-build (app-target Swift). No Kotlin twin — Oura is Swift-only/experimental.