Skip to content

fix(ble): read the 5/MG GET_DATA_RANGE newest-page clock field-exact (experimental, untested on a strap) - #2824

Open
LeonardSEO wants to merge 1 commit into
ryanbr:mainfrom
LeonardSEO:fix/5mg-data-range-newest-clock
Open

LeonardSEO wants to merge 1 commit into
ryanbr:mainfrom
LeonardSEO:fix/5mg-data-range-newest-clock

Conversation

@LeonardSEO

Copy link
Copy Markdown

Experimental: not tested on a strap. This changes what the Apple 5/MG sync path trusts, so I do not expect it to be merged without a strap log confirming it.

What this PR does

The 5/MG GET_DATA_RANGE SUCCESS body carries the last-written page's clock at body offset 57 (cmdOff + 60, frame byte 70), with 0 and 0xFFFFFFFF as "no clock".

  • New DataRange.pageClockNewestUnix(from:cmdOff:) (Swift + Kotlin twin) reads that field directly. Golden vectors pin a normal reply, the sentinel and a short frame on both platforms.
  • Both platforms use it for 5/MG instead of the every-offset scan; WHOOP 4.0 keeps the scan.
  • Apple: the 5/MG reply now passes feedsSync: true, so the newest timestamp feeds strapNewestTs and the backfill window, which Android already does today from the scan. The 4.0-only GET_CLOCK correlation (Values not computing until a week later #1598) is unaffected.

Source: the field and its confirmation come from LeonardSEO/wearable5.0 (FINDINGS §3), checked on 589 complete SUCCESS replies from 21 public capture sessions (NOOP issue attachments, Asherlc/dofek, tanarchytan/whoop-rs): the u32 at @57 is a plausible Unix time in all 589, and when the backlog is 0 it equals the trim-side clock in 286 of 286. The test vectors are wearable5.0's synthetic golden vectors, built to that layout.

Type of change

  • Bug fix

How it was tested

  • DataRangeTests / DataRangeScanTest: wearable5.0's golden vectors (normal reply, 0xFFFFFFFF sentinel, short frame), and pagesBehind on the same frames.
  • swift test in Packages/WhoopProtocol: 817 tests pass (1 skipped, as on main).
  • ./gradlew testFullDebugUnitTest: 6689 tests, all pass apart from the 2 RecoveryDriversTest half-tie cases that fail the same way on unmodified main.
  • Tools/i18n_audit.py --ci, Tools/doc_comment_lint.py, docs/protocol-examples checks and Tools/parity_ledger.py --refresh-derived (derived snapshots included): pass.
  • Tools unit tests, the parity acceptance suite and the R-R contract: pass apart from the 4 test_check_source_references cases (/var vs /private/var temp path on macOS) that fail the same way on unmodified main.
  • Apple: the macOS app (Strand) builds with this change on my development branch; StrandTests and the iOS target were not run locally for this branch. app-build.yml covers both.

Not tested on hardware. The decode is checked against captures, not against a live 5/MG run of this build. What would confirm it: a 5/MG strap log on Apple showing Strap newest banked record: … matching the last night, and auto-continue/"Pending sync" behaving as on Android.

Checklist

  • Swift package tests pass for any package I touched
  • Android unit tests pass if I touched android/ (apart from the 2 RecoveryDriversTest half-tie cases that fail the same way on unmodified main)
  • No new build warnings introduced (Android: none; Apple warnings not checked per branch)
  • UI changes use only StrandDesign / Palette / Metrics tokens
  • 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

Refs #1992

🤖 Generated with Claude Code

…t to sync on Apple

The clock of the last-written page sits at body offset 57 (cmdOff + 60), confirmed on 589 real replies in LeonardSEO/wearable5.0 FINDINGS §3, with 0 and 0xFFFFFFFF as sentinels. Both platforms read it directly for 5/MG; Apple now feeds it to sync as Android already does. Golden vectors from wearable5.0. Not tested on a strap.

Refs ryanbr#1992
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