Skip to content

WHOOP 4 v24: decode the record tail - #90

Merged
abdulsaheel merged 4 commits into
OpenStrap:mainfrom
magnetarQ:5-pr-protocol-v24-tail
Nov 29, 2026
Merged

abdulsaheel merged 4 commits into
OpenStrap:mainfrom
magnetarQ:5-pr-protocol-v24-tail

Conversation

@magnetarQ

@magnetarQ magnetarQ commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What it adds. parseV24Status(inner) in new lib/src/v24_status.dart: a probable temperature (u16@72), three optical control words (74-79),
activity state (80 bits 4-5), a measurement-window byte (82), a motion byte (85), a session byte (87) and a cumulative step-like counter (read as u32@88).
v24NextSlot1Descriptor() rebuilds the R11 slot-1 descriptor. R24.toMap() is untouched.

Evidence, your corpus (decode_parity_cases.json, 629 distinct v24 frames): the words carry slot indices 0/1/2, inner 80 bits 4-5 equal inner 30 bits 5-6,
u32@88 never decreases (3,153 to 6,248 in 8 h 19 min), u16@72 is 348-354. The tests use only these frames and edits of them.

Evidence, our strap (one WHOOP 4.0, one wearer, harvard 41.17.6.0, 85,331 v24 records on five sampled dates, 22,420 R11 frames):

  • word 1 rebuilds the whole slot-1 descriptor of the next record in 22,419/22,419 pairs (8 drive codes; the drive lookup comes from the same data)
  • words 2/3: 960/960 configured-on slot observations were active and matched; 32 more were active while configured off (16 frames, at the end of a window)
  • flags 0x10 / 0x40 = more than 40 of 50 lane A / B samples at 524287 in the same record: 22 / 34 positives, 0 exceptions

Step-like counter. Seven hand-counted walks by one person (truth 624): counter 755 (+21 %), livePedometer() at analytics a438df4, unmodified, on the same
R10 accelerometer 848 (+36 %). Windows: counter from phase start to 3 s after its end (it lags; 749 at the exact end), livePedometer over the exact phase at 104 Hz.
Upper arm: the counter is closer in all 5. Wrist: livePedometer is closer on the long walk (228 vs 252 for 207), the counter with the hand in a pocket
(74 vs 83 for 61). Seven walks by one person do not rank the two methods. 30 s of arm shaking gave 62 counts with no walking. The error is not constant (+5 % to +41 % by gait;
the first increment comes 8-20 s after the phase marker). High half always 0 (max 9,045), so u16 is equally consistent.

Temperature: probable, not calibrated. This bears on the note in records.dart about inner[72] and inner[88]: we think 72 is a temperature in tenths of a degree C;
88 is the counter above. On that scale it reads 34.8-35.4 in all 629 of your corpus frames. From our notes, it plateaus at 33.3-33.4 on an upper arm and read 23.0 after
36 min off the body on a table, in a room of about 21.5 (the AC setting, not measured). The whole range seen is 20.6-43.8; the highest values are from around charging.
A second, also unverified, slow field (event 63 body u16@7) tracks it (r 0.94, 156 pairs; mean offset 2.1, up to 5.9). There is no reference thermometer, so the API name
stays temperatureCandidateRaw until someone checks it against one.

Possible SpO2 (needs checking). Byte 82 may be the strap's own SpO2 %. Values of 77-100 occurred only with drive codes 11/6 (482 records), i.e. in
~30 s windows with slots 2/3 on, about every 19 min. That matches the WHOOP 5 SpO2 candidate described in OpenStrap/edge#675 (30 s bursts every 1,200 s).
In 3 comparisons with an Apple Watch it was within 1-2 points. That is far too few to validate it,
so the API stays neutral: percentLikeValue is returned only for 11/6 and 77-100, any other pair gives null, and the raw byte is always kept. A
fingertip oximeter over several nights would settle it; OpenStrap/edge#675 proposed the bar for showing
SpO2 (at least 10 nights / 30 reference pairs, error within 2 points).

Not claimed: temperature scale or accuracy, physical units of drive/lane values, that byte 82 is SpO2 (never checked against an oximeter; see above),
the meaning of byte 87, rollover or reset of the counter. Raw captures are not attached (health data).

dart analyze clean, dart test 812 passed, 4 skipped (on dc699ce).

🤖 Generated with Claude Code

Summary by Sourcery

Decode and expose the WHOOP 4 v24 record tail without changing the existing R24 map schema.

New Features:

  • Add an opt-in decoder for WHOOP 4 v24 record-tail status fields, including temperature and activity candidates, optical slot controls, measurement and motion values, and a cumulative step-like counter.
  • Provide reconstruction of the next R11 slot-1 descriptor from decoded v24 optical controls.
  • Expose the v24 status decoder through the package API.

Enhancements:

  • Preserve the existing R24 map output while offering the newly decoded fields through a separate typed view.
  • Add slot-specific drive mappings, clipping indicators, configuration helpers, and guarded percent-like value interpretation.

Tests:

  • Add corpus-based and synthetic coverage for v24 tail parsing, field correlations, slot configuration, descriptor reconstruction, clipping flags, validation, and unknown drive handling.

Summary by CodeRabbit

  • New Features
    • Added optional support for decoding WHOOP 4 v24 historical status records, including activity state, motion, step-like counts, temperature-related data, and optical sensor configuration.
    • Added checks for whether sensor slots are configured and whether a measurement value meets the supported criteria. Existing record-map output remains unchanged.

@sourcery-ai

sourcery-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Expose the opt-in v24 tail decoder and descriptor-reconstruction helper as public package API without changing R24.toMap().

  • lib/openstrap_protocol.dart L38-41
  • lib/src/v24_status.dart L111-230

Define the public status and slot-control data structures, including documented interpretations and derived values for the decoded tail.

  • lib/src/v24_status.dart L1-110

Tests

Verify tail decoding, derived slot values, descriptor reconstruction, and rejection behavior against corpus records and edited fixtures.

  • test/v24_status_test.dart L1-195

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The library now exports an opt-in decoder for WHOOP 4 v24 status tails. The decoder validates record length, type, version, and slot indices, then exposes decoded fields and derived values. Tests cover corpus records, constructed inputs, descriptor encoding, and invalid records.

Changes: v24 status decoding

Layer / File(s) Summary
Define, decode, and validate v24 status
lib/src/v24_status.dart, lib/openstrap_protocol.dart, test/v24_status_test.dart
Adds slot-control and status types, the v24 parser, derived getters, and slot-1 descriptor generation. The barrel exports the new API. Tests check corpus and constructed records, derived values, descriptor bytes, and parser rejection conditions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Suggested reviewers: abdulsaheel

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="lib/src/v24_status.dart" line_range="153" />
<code_context>
+  final int stepLikeCounter;
+
+  const V24Status({
+    required this.temperatureCandidateRaw,
+    required this.slots,
+    required this.activityState,
</code_context>
<issue_to_address>
**Short slot lists throw**

When a caller constructs `V24Status` with fewer than three slots and reads either getter, `slotsConfiguredOn` and `percentLikeValue` index `slots[1]` and `slots[2]` without checking the list length, so reading either property throws a `RangeError` instead of returning a result.

Reject lists with fewer than three entries in the constructor before either getter can index them.

Also at `lib/src/v24_status.dart:165-166`, `lib/src/v24_status.dart:172-176`.
</issue_to_address>

### Comment 2
<location path="lib/src/v24_status.dart" line_range="165" />
<code_context>
+  /// Slots 2 and 3 are both configured on. Configuration only: see
+  /// [V24SlotControl.configuredOff].
+  bool get slotsConfiguredOn =>
+      !slots[1].configuredOff && !slots[2].configuredOff;
+
+  /// [measurementWindowByte] when it is 77-100 AND slots 2/3 carry drive codes
</code_context>
<issue_to_address>
**Unknown slot codes appear on**

When either slot 2 or slot 3 has a drive code whose on/off meaning has not been established, `slotsConfiguredOn` treats every code other than 12 as on, even when `driveParam` leaves the code unknown, so callers receive a positive configuration result without evidence that both slots are on.

Have `slotsConfiguredOn` report on only when both slots have established on-codes.
</issue_to_address>

### Comment 3
<location path="lib/src/v24_status.dart" line_range="56" />
<code_context>
+  /// The word's high nibble of byte 1, unshifted (0x10, 0x20, 0x40, 0x80).
+  final int flags;
+
+  const V24SlotControl({
+    required this.slotIndex,
+    required this.laneACode,
</code_context>
<issue_to_address>
**Hand-built controls corrupt descriptors**

When a caller constructs a slot-1 control with lane codes outside 0–3, `v24NextSlot1Descriptor` multiplies those lane codes and serializes the results without range checks, so it returns a descriptor with invalid or truncated lane parameters.

Validate lane-code ranges at construction or reject invalid controls before rebuilding the descriptor.

Also at `lib/src/v24_status.dart:224-228`.
</issue_to_address>

### Comment 4
<location path="test/v24_status_test.dart" line_range="82" />
<code_context>
+    test('the temperature candidate stays in 348-354', () {
+      for (final b in records) {
+        final t = parseV24Status(b)!.temperatureCandidateRaw;
+        expect(t, inInclusiveRange(348, 354));
+      }
+    });
</code_context>
<issue_to_address>
**Temperature extraction can be skipped**

When the decoder returns a constant within the observed range, when `parseV24Status` returns a fixed value such as 348 instead of reading the temperature bytes, the `temperature candidate stays in 348-354` test still passes because it only checks that range, so a broken field extraction goes unnoticed.

Add a synthetic record with distinct bytes at offsets 72-73 and assert the exact little-endian value is returned.
</issue_to_address>

Sourcery assessment

Approval pending. 4 findings to address first.

Blocking findings: lib/src/v24_status.dart:153, lib/src/v24_status.dart:165, lib/src/v24_status.dart:56, test/v24_status_test.dart:82


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread lib/src/v24_status.dart Resolved
Comment thread lib/src/v24_status.dart Resolved
Comment thread lib/src/v24_status.dart Resolved
Comment thread test/v24_status_test.dart Resolved
@abdulsaheel
abdulsaheel merged commit f38adc4 into OpenStrap:main Nov 29, 2026
2 checks passed
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.

2 participants