Skip to content

gen4 GET_CLOCK: emit the reply's sub-second field - #88

Open
magnetarQ wants to merge 3 commits into
OpenStrap:mainfrom
magnetarQ:4-pr-protocol-clock
Open

magnetarQ wants to merge 3 commits into
OpenStrap:mainfrom
magnetarQ:4-pr-protocol-clock

Conversation

@magnetarQ

@magnetarQ magnetarQ commented Nov 25, 2026 •

Copy link
Copy Markdown

Code: emits clock_subsec (gen4 only, when < 32768, only with a plausible clock_epoch); test uses one real reply body
(strap clock value only, no health data). dart analyze clean, dart test all passed.
The gen4 GET_CLOCK (0x0B) reply body is [u32 sec][u32 subsec] (control.dart already notes this) but only the seconds
are emitted. On our WHOOP 4.0 the subsec word is always < 32768 (17 replies; upper half 0) and is read as 1/32768 s, the same unit as
the record/event sub-second fields: with it, the bounds each reply puts on strap−laptop clock offset
([sec+subsec/32768 − t_reply, … − t_write]) intersect on each of the four days with more than one reply (9, 3, 2 and 2
replies). Whole seconds alone do not intersect on two of them, and milliseconds on none. These bounds alone would also
allow 1/65536 s; 1/32768 rests on all 17 values being below 32768 and on the record/event sub-second unit.

🤖 Generated with Claude Code

Summary by Sourcery

Expose validated gen4 clock sub-second precision while preserving existing epoch decoding and gen5 behavior.

New Features:

  • Emit the gen4 GET_CLOCK reply’s sub-second field as clock_subsec when the value is valid and the clock epoch is plausible.

Enhancements:

  • Keep clock sub-second decoding scoped to gen4 replies and exclude unsupported layouts or out-of-range values.

Tests:

  • Add coverage for real gen4 clock data, boundary values, truncated replies, invalid epochs, and gen5 compatibility.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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 59 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 080d334d-7d96-4873-91a1-b3bea136fe67
Commits

Reviewing files that changed from the base of the PR and between fbadb5b and 290f28e.

Files selected for processing: 2

  • lib/src/control.dart
  • test/control_plane_offsets_test.dart
  • 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 commented Nov 25, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Decode and emit the gen4 GET_CLOCK sub-second word only when the epoch is plausible, the opcode is gen4, the payload is long enough, and the value is below 32768.

  • lib/src/control.dart L1017-1031

Tests

Cover a real gen4 reply, accepted and rejected sub-second boundaries, truncated or implausible replies, and gen5 compatibility.

  • test/control_plane_offsets_test.dart L96-127

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 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 1 issue

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

## Individual Comments

### Comment 1
<location path="lib/src/control.dart" line_range="1025-1026" />
<code_context>
+        // half 0), and only with it do the clock-offset bounds the replies give
+        // ([sec + subsec/32768 - t_reply, ... - t_write]) agree within a day.
+        // Anything >= 32768 is not that count, so it is not emitted.
+        if (!profile.isGen5 && payload.length >= at + 8) {
+          final sub = u32(payload, at + 4);
+          if (sub < 32768) dec['clock_subsec'] = sub;
+        }
</code_context>
<issue_to_address>
**Gen5 reply gains a false fraction**

When a gen5 `Cmd.getClockGen5` reply is parsed with the default gen4 profile and its payload has at least two trailing bytes beyond the normal gen5 reply, `op` selects the gen5 layout at `payload[3]`, but `!profile.isGen5` treats the reply as gen4. With a gen5 reply parsed using the default gen4 profile and at least two trailing payload bytes, `u32(payload, at + 4)` combines the gen5 u16 fraction with those bytes and can emit a bogus `clock_subsec`.

Require `op == Cmd.getClock` as well as a gen4 profile before decoding the gen4 sub-second word.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: lib/src/control.dart:1026


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

Comment thread lib/src/control.dart Resolved

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

Sourcery assessment

Approved.

@magnetarQ magnetarQ changed the title gen4 GET_CLOCK: emit the reply's sub-seconds (1/32768 s) gen4 GET_CLOCK: emit the reply's sub-second field Nov 25, 2026
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