Repository navigation
Conversation
Reviewer's GuideAPIExpose the opt-in v24 tail decoder and descriptor-reconstruction helper as public package API without changing R24.toMap().
Define the public status and slot-control data structures, including documented interpretations and derived values for the decoded tail.
TestsVerify tail decoding, derived slot values, descriptor reconstruction, and rejection behavior against corpus records and edited fixtures.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 18 minutes. View limit details
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. |
There was a problem hiding this comment.
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
| final int stepLikeCounter; | ||
|
|
||
| const V24Status({ | ||
| required this.temperatureCandidateRaw, |
There was a problem hiding this comment.
🟡 Medium · 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.
Prompt for AI agents
In `lib/src/v24_status.dart` at line 153:
**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`.| /// Slots 2 and 3 are both configured on. Configuration only: see | ||
| /// [V24SlotControl.configuredOff]. | ||
| bool get slotsConfiguredOn => | ||
| !slots[1].configuredOff && !slots[2].configuredOff; |
There was a problem hiding this comment.
🟡 Medium · 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.
Prompt for AI agents
In `lib/src/v24_status.dart` at line 165:
**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.| /// The word's high nibble of byte 1, unshifted (0x10, 0x20, 0x40, 0x80). | ||
| final int flags; | ||
|
|
||
| const V24SlotControl({ |
There was a problem hiding this comment.
🟡 Medium · 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.
Prompt for AI agents
In `lib/src/v24_status.dart` at line 56:
**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`.| test('the temperature candidate stays in 348-354', () { | ||
| for (final b in records) { | ||
| final t = parseV24Status(b)!.temperatureCandidateRaw; | ||
| expect(t, inInclusiveRange(348, 354)); |
There was a problem hiding this comment.
🟡 Medium · 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.
Prompt for AI agents
In `test/v24_status_test.dart` at line 82:
**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.
What it adds.
parseV24Status(inner)in newlib/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):
Step-like counter. Seven hand-counted walks by one person (truth 624): counter 755 (+21 %),
livePedometer()at analytics a438df4, unmodified, on the sameR10 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
temperatureCandidateRawuntil someone checks it against one.Percent-like value.
percentLikeValueis returned only for drive codes 11/6 and a byte of 77-100, the only combination seen with such values (482 records).Any other pair gives null; the raw byte is always kept.
Not claimed: temperature scale or accuracy, physical units of drive/lane values, that byte 82 is SpO2 (never checked against an oximeter),
the meaning of byte 87, rollover or reset of the counter. Raw captures are not attached (health data).
dart analyzeclean,dart test812 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:
Enhancements:
Tests: