Skip to content

decodeFrame historical hr + garmin mlr fixes - #73

Open
abdulsaheel wants to merge 2 commits into
mainfrom
fix/sweep-protocol-main-1
Open

abdulsaheel wants to merge 2 commits into
mainfrom
fix/sweep-protocol-main-1

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

decodeFrame was still turning short gen4 0x2F records into realtime_hr (version byte 10 hit the r10 path, anything under 64 bytes read a timestamp byte as bpm). same gate as live.dart now.

garmin: a watch sends data on a bare handle byte, not just the flagged form, so those were all getting dropped. also close-all had the client id 2 bytes late, it goes right after the type like register-ml.

Summary by Sourcery

Fix historical heart-rate detection and Garmin MLR handle and close-all request handling.

Bug Fixes:

  • Prevent historical gen4 records from being misclassified as realtime heart-rate data while preserving decoding of valid full-size R10 records.
  • Decode Garmin MLR notifications addressed with bare handle bytes.
  • Correct the Garmin CLOSE_ALL request layout so the client ID follows the request type.

Tests:

  • Add coverage for historical-record heart-rate misclassification, truncated records, valid archived R10 decoding, bare Garmin handles, and CLOSE_ALL field offsets.

Summary by CodeRabbit

  • Bug Fixes
    • Improved heart-rate decoding so historical records are not mistaken for realtime readings, while valid archived R10 records continue to decode correctly.
    • Improved handling of Garmin MLR data packets, including packets with unflagged handles.
    • Corrected the client ID placement in Garmin close-all requests for more reliable request handling.

@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.

Sorry @abdulsaheel, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 6 days and 12 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: 45c76b36-cdd0-4a5e-8a23-6baff3ee7f6f

📥 Commits

Reviewing files that changed from the base of the PR and between bc7d8d0 and 6f3b29c.

📒 Files selected for processing (4)
  • lib/src/control.dart
  • lib/src/garmin.dart
  • test/decode_integrity_test.dart
  • test/garmin_test.dart

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


📝 Walkthrough

Walkthrough

The changes update historical R10 frame routing, Garmin MLR decoding, and the byte layout of CLOSE_ALL requests. Tests cover the R10 frame cases, bare-handle MLR data, and Garmin request fields.

Changes

R10 Frame Routing

Layer / File(s) Summary
Historical R10 routing checks
lib/src/control.dart, test/decode_integrity_test.dart
R10 routing now distinguishes realtime-raw frames and applies a minimum-length check to other R10 frames. Historical frames bypass the compact realtime path. Tests cover truncated historical records and a full-size archived record.

Garmin Protocol

Layer / File(s) Summary
MLR bare-handle decoding
lib/src/garmin.dart, test/garmin_test.dart
A nonzero, unflagged first byte identifies a data frame when at least one payload byte follows. The decoder uses the full byte as the handle and removes it from the payload.
CLOSE_ALL request layout
lib/src/garmin.dart, test/garmin_test.dart
The request places the client ID at offset 1 and the reserved 16-bit field at offset 9. Tests check these fields.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 6f3b2

The changes fix short historical heart-rate records being misread as realtime data, accept Garmin bare-handle data frames, and reorder the close-all request fields. No concrete merge-blocking risk was identified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 6f3b2

The changes are narrowly scoped byte-decoding and encoding corrections, with no demonstrated new authorization bypass. However, accepting additional Garmin handle formats and correcting the reset command depend on session controls outside the supplied code, so downstream safety remains unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The directly evidenced exposure is the exported codec's broader acceptance of incoming handle-addressed bytes and corrected reset-request serialization. No privileged downstream sink or cross-tenant effect was established; effective device and session scope remains unresolved.

Trust Boundaries and Controls

  • observed — MLR decoding classifies supplied bytes without checking session-owned registrations. This was already true for flagged data packets and now also applies to accepted bare handles. Successful decoding is therefore not evidence of handle authorization; no downstream bypass was demonstrated.

Hardening Proposals

  • proposed — At the external session boundary, validate decoded handles against accepted current-session registrations and ensure reset acknowledgement invalidates old handles before reuse. Verify rejection of stale or refused handles across delayed delivery, repeated reset, interruption, and reconnect.
🚥 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 accurately identifies both main changes: the historical heart-rate fix in decodeFrame and the Garmin MLR fixes. It is concise and specific enough for a teammate to understand the pull reques…
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.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

@sourcery-ai

sourcery-ai Bot commented Oct 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR hardens frame decoding by preventing short gen4 historical records from entering realtime-HR heuristics, while keeping valid archived R10 packets supported. It also fixes Garmin MLR handling for bare handle-addressed data and aligns CLOSE_ALL serialization with the protocol’s client-ID offset.

Flow diagram for historical and realtime frame decoding

flowchart TD
    A["Decode data record"] --> B{"Record is historical 0x2F?"}
    B -->|Yes| C{"R10 at valid minimum length?"}
    B -->|No| D{"R10 realtime or valid length?"}
    C -->|Yes| E["parseR10Lite"]
    C -->|No| F["Skip realtime-HR heuristics"]
    D -->|Yes| E
    D -->|No| G{"Packet length less than 64?"}
    G -->|Yes| H["Compact realtime parsing"]
    G -->|No| I["Other record decoding"]
Loading

Flow diagram for Garmin MLR notification decoding

flowchart TD
    A["garminDecodeMlr"] --> B{"Flagged handle byte?"}
    B -->|Yes| C["Decode flagged handle data"]
    B -->|No| D{"Bare nonzero handle byte?"}
    D -->|Yes| E["Decode bare handle data"]
    D -->|No| F{"Control packet type"}
    F --> G["Decode Garmin control response"]
Loading

File-Level Changes

Change Details Files
Prevent historical gen4 records from being misclassified as realtime heart-rate packets while preserving valid archived R10 decoding.
  • Gate R10 parsing on realtime packet type or the minimum R10 frame length.
  • Exclude historical 0x2F frames from compact realtime heuristics.
  • Add coverage for short, truncated, and full-size historical records.
lib/src/control.dart
test/decode_integrity_test.dart
Broaden Garmin MLR data-frame routing and correct the CLOSE_ALL request wire layout.
  • Accept bare non-zero handle bytes, including handles outside the flagged 3-bit range.
  • Retain null handling for empty and single-byte inputs.
  • Move the 64-bit client ID immediately after the request type and place reserved bytes afterward.
  • Add routing and byte-offset assertions for the updated protocol behavior.
lib/src/garmin.dart
test/garmin_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

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