Skip to content

fix R10 misdecode of short historical records with version byte 10 - #68

Merged
abdulsaheel merged 1 commit into
mainfrom
fix/r10-version10-collision
Sep 19, 2026
Merged

abdulsaheel merged 1 commit into
mainfrom
fix/r10-version10-collision

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

recType 10 is both the R10 live-raw record tag AND a valid-but-unmapped historical layout-version byte. decodeRecord/realtimeRr routed any frame with recType==10 through the R10 100Hz field map with no length or plausibility check, so a short (~96 byte) 0x2F historical record whose version byte happened to be 10 got its unrelated v24-layout bytes read as hr/rr/imu instead of falling through to the archive path every other unrecognized version already takes.

fix: gate the R10 branch on pkt==0x2B (unambiguous at any length, even truncated) OR a genuine-R10 length floor (~1920 bytes, kR10MinLength=685 for the accel arrays) — real hardware does send archived 0x2F R10 snapshots at full length, confirmed against the 2934-case parity fixture, so this can't just be a pkt-type check.

verified: patched a real v24 fixture's version byte to 10 at short length, decodeRecord/realtimeRr both correctly return null now (were misdecoding hr=98 + fabricating steps before). full dart test suite green (631 passed, 4 pre-existing skips) in a clean worktree off main.

Summary by Sourcery

Correct R10 record detection so short historical version-10 records are not interpreted using the live R10 layout.

Bug Fixes:

  • Prevent short historical records with layout version 10 from being misdecoded as R10 live records by requiring an unambiguous packet type or genuine R10 record length.
  • Ensure affected records fall through to the archive/unsupported path instead of producing fabricated heart-rate, respiration, or motion data.

Enhancements:

  • Centralize the minimum valid R10 record length for consistent validation across acceleration, respiration, and activity decoding.

recType 10 is both the R10 live-raw record tag and a valid but unmapped
historical layout-version byte. decodeRecord/realtimeRr routed any
recType==10 frame through the R10 field map with no length or
plausibility check, so a short (~96-byte) 0x2F historical record whose
version byte happened to be 10 got its unrelated v24-layout bytes read
as hr/rr/imu instead of falling through to the archive path every other
unrecognized version already takes.

gate the R10 branch on pkt==0x2B (unambiguous at any length) or on a
genuine-R10 length floor (~1920-byte records, incl. archived 0x2F R10
snapshots, which real hardware does send). full test suite still green.

@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 5 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 10 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: 06a175d4-9d6b-457f-9abc-3124fc9cd4df

📥 Commits

Reviewing files that changed from the base of the PR and between b44ca07 and 41a3169.

📒 Files selected for processing (1)
  • lib/src/live.dart

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 Sep 19, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes version-byte collisions by recognizing R10 only for unambiguous realtime raw packets or sufficiently long genuine R10 records, preserving support for full-length archived R10 snapshots while preventing short historical records from being misdecoded.

Flow diagram for R10 record recognition

flowchart TD
    A["Receive record"] --> B{recType == 10?}
    B -->|No| C["Use existing record/archive handling"]
    B -->|Yes| D{pkt is realtimeRawData?}
    D -->|Yes| E["Decode as R10"]
    D -->|No| F{length >= kR10MinLength?}
    F -->|Yes| E
    F -->|No| G["Return null / archive as unrecognized historical version"]
Loading

File-Level Changes

Change Details Files
Disambiguate R10 records from historical records whose version byte is also 10 by centralizing and applying a minimum-length threshold.
  • Define the 685-byte R10 length floor based on the acceleration array layout.
  • Allow realtime raw packets to use the R10 parser at any length, while requiring the floor for other packet types.
  • Apply the same length guard to acceleration parsing and motion extraction.
  • Let short historical version-10 records fall through to the archive/unrecognized-version path instead of fabricating HR, RR, or motion data.
lib/src/live.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

@abdulsaheel
abdulsaheel merged commit 57d658b into main Sep 19, 2026
4 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.

1 participant