Skip to content

labrador: WHOOP MG identity, R17 parser, R16 recognition - #54

Open
DropTabl wants to merge 1 commit into
OpenStrap:mainfrom
DropTabl:feat/mg-ecg-parser
Open

labrador: WHOOP MG identity, R17 parser, R16 recognition#54
DropTabl wants to merge 1 commit into
OpenStrap:mainfrom
DropTabl:feat/mg-ecg-parser

Conversation

@DropTabl

@DropTabl DropTabl commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

WHOOP MG (Maverick) Labrador ECG on the wire: identity, the live R17 parser, and
recognition of the historical R16 raw record. Parsing only — no lifecycle, no
policy, no storage. The consuming feature lands separately in edge.

What this adds

Gen5HelloInfo.isMaverick (lib/src/control.dart) — helloRevision == 1 && opticalDiscriminator < 38, the official MAVERICK interval. Never read through a
non-revision-1 layout. A physical MG reports 0; an ordinary WHOOP 5.0 reports 82
and stays isWhoop5.

cmdAbortHistorical(seq, {profile}) (lib/src/commands.dart) — gen5 callers
pad the bodyless opcode 20 through the normal framer ([35][seq][20][00]). The
gen4 default is byte-identical to before.

lib/src/labrador.dart (new)

  • LabradorR17 — the live type-43 revision-17 packet. Type 47 is accepted only
    with allowStored. Bounds: fixed fields through offset 25, count <= 100,
    26 + 2*count bytes, no fixed total length, and the tail is preserved
    unnamed. Samples are signed i16 LE with no rescale, no sign flip and no lead
    claim; variabilityRaw is null on 0xffff and carries no unit.
  • LabradorFlags (bits 0-3) and LabradorUnreadableMask (bits 0-3 + reasons).
  • LabradorR16Raw — the historical type-47 revision-16 record, RECOGNISED but
    not decoded: only the proven common header (sequence, strap time) is read and
    the exact inner bytes are retained. The body layout is not source-closed, so
    no body field is invented here.

It is deliberately standalone rather than folded into the gen5 historical decoder
family: that family never sees live type-43 frames, and its inner[2] /
ppgSampleRateHz meaning does not apply.

Evidence

Field offsets, the sample scale and the 500 Hz -> 100 Hz relationship come from
the retained MG fixtures and firmware trace, not from inference. LabradorR16Raw
decodes no body field precisely because that layout is NOT closed — a candidate
packing exists and fails validation, which is why it stays out of this parser.

Tests

labrador_r17_test, labrador_r16_test, labrador_reassembly_test (a
1,584-byte framed R16 through FrameReassembler at 1/7/20/244/512/1583/1584/4096
byte chunkings, split at the header end, inside the CRC32, and on an embedded
fake aa 01 header, followed by an R18), gen5_hello_maverick_test, and exact
Labrador list bytes added to doc_conformance_test.

Verified against current main: dart analyze clean, dart test 649 passing.

Summary by Sourcery

Support WHOOP MG Labrador ECG packet recognition and parsing while keeping historical raw records lossless and gen4 command behavior compatible.

New Features:

  • Add WHOOP MG identity detection through the revision-gated Maverick HELLO discriminator.
  • Add standalone parsers for live Labrador R17 filtered ECG packets and recognized-but-preserved R16 raw ECG records.
  • Export the Labrador parsing APIs through the public library interface.

Bug Fixes:

  • Correct historical-transmit abort command framing for gen5 while preserving the existing gen4 command bytes.

Enhancements:

  • Expose Labrador ECG flags, unreadable reasons, timing, status, sample values, and unassigned packet tails without assigning unsupported meanings to raw fields.

Tests:

  • Add coverage for Maverick recognition, Labrador R17/R16 parsing and validation, CRC-gated frame parsing, and adversarial gen5 frame reassembly.

Summary by CodeRabbit

  • New Features

    • Added support for parsing and exporting WHOOP MG Labrador filtered and raw ECG records.
    • Added WHOOP MG “Maverick” device identification.
    • Historical-abort commands can now target the appropriate hardware generation.
  • Bug Fixes

    • Improved generation-specific command framing for historical data operations.
  • Tests

    • Added coverage for Labrador ECG parsing, frame reassembly, device identification, and gen4/gen5 command compatibility.

@sourcery-ai

sourcery-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces a standalone WHOOP MG Labrador parsing surface: revision-17 live filtered-ECG decoding, revision-16 historical raw-record recognition with lossless preservation, Maverick HELLO identification, and gen5 historical-command framing, with extensive bounds, CRC, reassembly, and wire-conformance tests.

Sequence diagram for Labrador frame validation and parsing

sequenceDiagram
    participant FrameReassembler
    participant Frame
    participant LabradorR17
    participant LabradorR16Raw

    FrameReassembler->>Frame: reassemble bytes
    Frame->>Frame: decodable
    alt revision 17 live or allowed stored packet
        Frame->>LabradorR17: tryParseFrame(f, allowStored)
        LabradorR17->>LabradorR17: parse(inner, allowStored)
        LabradorR17-->>Frame: decoded samples and metadata
    else revision 16 historical packet
        Frame->>LabradorR16Raw: tryParseFrame(f)
        LabradorR16Raw->>LabradorR16Raw: tryParse(inner)
        LabradorR16Raw-->>Frame: common header and exact inner bytes
    end
Loading

File-Level Changes

Change Details Files
Adds standalone WHOOP MG Labrador packet models and parsers for live R17 filtered ECG and historical R16 raw ECG.
  • Exports the new Labrador API.
  • Parses validated R17 fixed fields, flags, unreadable reasons, variability, signed ECG samples, and variable-length tails.
  • Recognises R16 records using only the proven common header while preserving the exact inner payload.
  • Provides frame-level parsing that requires successful frame validation.
lib/src/labrador.dart
lib/openstrap_protocol.dart
Adds WHOOP MG identification and generation-specific historical abort framing.
  • Identifies Maverick only for revision-1 HELLOs with optical discriminator below 38.
  • Adds an optional band profile to historical-abort command construction while retaining gen4 bytes.
  • Verifies exact gen5 Labrador command bodies and padding.
lib/src/control.dart
lib/src/commands.dart
test/gen5_hello_maverick_test.dart
test/doc_conformance_test.dart
Adds comprehensive parser, framing, and identity coverage based on synthetic and retained wire-shaped fixtures.
  • Tests R17 packet identity, bounds, sample decoding, flags, masks, terminal states, variability, and tail preservation.
  • Tests R16 recognition, byte preservation, CRC gating, and rejection of unsupported records.
  • Exercises 1,584-byte R16 reassembly across chunk sizes, CRC boundaries, embedded header-like bytes, and a following R18 frame.
test/labrador_r17_test.dart
test/labrador_r16_test.dart
test/labrador_reassembly_test.dart

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

sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Sep 8, 2026

@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 reviewed your changes and they look great!

Sourcery assessment

Approved.


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

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Warning

Review limit reached

Next included review available in 46 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: a43208c8-4bda-499e-b57d-d2800743b3aa

📥 Commits

Reviewing files that changed from the base of the PR and between 5b2cd5a and 61349b4.

📒 Files selected for processing (2)
  • lib/src/labrador.dart
  • test/gen5_hello_maverick_test.dart

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 48be30a2-ff33-4081-8e8f-6dc436f63b4d

📥 Commits

Reviewing files that changed from the base of the PR and between fe1464d and 5b2cd5a.

📒 Files selected for processing (9)
  • lib/openstrap_protocol.dart
  • lib/src/commands.dart
  • lib/src/control.dart
  • lib/src/labrador.dart
  • test/doc_conformance_test.dart
  • test/gen5_hello_maverick_test.dart
  • test/labrador_r16_test.dart
  • test/labrador_r17_test.dart
  • test/labrador_reassembly_test.dart

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The PR adds public WHOOP MG Labrador R17 and R16 wire-format parsers, supports gen5 historical-abort framing, adds MAVERICK detection, and expands command, parser, and frame-reassembly tests.

Changes

Labrador protocol support

Layer / File(s) Summary
Labrador models and parsers
lib/src/labrador.dart, lib/openstrap_protocol.dart, test/labrador_*
Adds R17 filtered ECG and R16 raw ECG models, flag and unreadable-mask decoding, CRC-gated parsing, raw-byte preservation, and comprehensive parser tests.
Gen5 command and identity handling
lib/src/commands.dart, lib/src/control.dart, test/doc_conformance_test.dart, test/gen5_hello_maverick_test.dart
Adds the optional band profile to cmdAbortHistorical and adds Gen5HelloInfo.isMaverick. Tests verify gen5 command bytes, gen4 compatibility, and MAVERICK identity boundaries.
Frame reassembly validation
test/labrador_reassembly_test.dart
Tests R16 reassembly across chunk sizes, CRC boundaries, embedded 0xAA bytes, and concatenated R16/R18 frames.
Formatting-only cleanup
lib/src/commands.dart, lib/src/control.dart, test/doc_conformance_test.dart
Reflows existing declarations and expressions without changing behavior.

Priority: ⬇️ Low — Defer the WHOOP MG Labrador parsing support because it is a parsing-only protocol expansion with lifecycle, policy, and storage explicitly out of scope.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to 5b2cd

The new Labrador parsing and Gen5 command support are covered by validation and protocol-conformance tests, with no actionable merge risk identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main changes: WHOOP MG identity detection, the R17 parser, and R16 recognition.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

Comment @coderabbitai help to get the list of available commands.

Gen5HelloInfo.isMaverick: revision-1 HELLO with optical discriminator in [0,38) — the official 5.458.0 MAVERICK interval (physical MG reports 0; the ordinary WHOOP 5.0 reports 82 and stays GOOSE). Never read through a non-rev-1 layout; UUID/name/command acceptance are not MG evidence.

LabradorR17: the live (type 43) filtered-ECG record, source-proven field map at inner[3..25] plus signed i16 LE samples from 26. Bounds: fixed fields present, count <= 100, 26+2*count bytes available, no fixed total length; aligned tail bytes kept unnamed. Samples stay input-referred integer microvolts — no rescale, no wrist sign flip, no lead claim. Stored type-47 R17 only on explicit opt-in (the official foreground flow never enables it). Standalone rather than a Gen5HistoricalRecord: live frames never reach that type-47 dispatch, and its inner[2] flags/ppg-rate meaning does not apply.

LabradorR16Raw: recognises historical type-47 revision-16 raw ECG and keeps the exact inner bytes with the common sequence/strap-time header only — the body is not source-closed.

cmdAbortHistorical gains a profile parameter so a gen5 caller pads the bodyless opcode 20 through the normal framer; gen4 default is byte-identical.

Tests: identity boundaries, 0/49/100 samples, count >100, count beyond bytes, every fixed-field truncation, i16 signs, flag and unreadable bits, tail preservation, R16 recognition, 1,584-byte R16 reassembly under adversarial chunking (embedded 0xAA/fake header), and exact Labrador list bytes in doc_conformance.
@sourcery-ai
sourcery-ai Bot dismissed their stale review September 8, 2026 16:11

Sourcery withdrew this approval because the latest commits introduced blocking findings.

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