Skip to content

fix: alcoholNightFlag missing whole-bpm quantum guard on RHR - #66

Merged
abdulsaheel merged 1 commit into
mainfrom
fix/alcohol-rhr-quantum-guard
Sep 18, 2026
Merged

abdulsaheel merged 1 commit into
mainfrom
fix/alcohol-rhr-quantum-guard

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

same gap illness_cusum just got fixed for (8368d5e). alcoholNightFlag standardizes tonight's rhr against robustBaseline(rhrHistory) via modZ/mdc with no dispersionBelowQuantum check. a whole-bpm baseline like alternating 54/55/56 has sd ~0.76, under the 1bpm quantum but nonzero, so it passes the mad!=0 check and a normal +3bpm night blows up into an extreme z, clears mdc, and can push the alcohol band into moderate/heavy off rounding noise.

fix mirrors illness_cusum almost exactly: dispersionBelowQuantum(rhrHistory, 1.0) guard, null out rhrZ/rhrMdc when it fires (rhrUp stays false, everything downstream is already null-safe), note gets a short suffix saying why. rmssd untouched, not quantized this way.

also widened the shared alcohol-night test fixture (it was itself sub-quantum, would've broken the heavy/moderate/light tests once the guard landed) and added a regression test for the abstain case.

not wired into the app (file's own header says so), zero blast radius.

Summary by Sourcery

Guard alcohol-night RHR standardization against sub-quantum baseline dispersion while continuing to evaluate RMSSD normally.

Bug Fixes:

  • Prevent alcohol-night RHR scoring from generating extreme autonomic or alcohol signals when the baseline dispersion is below the whole-bpm measurement quantum.
  • Add regression coverage ensuring ordinary RHR increases abstain from the alcohol signature under sub-quantum baselines.

Enhancements:

  • Annotate results when the RHR axis is abstained due to insufficient resolvable baseline dispersion.

Tests:

  • Widen the shared alcohol-night RHR fixture to represent a baseline with measurable whole-bpm dispersion.

same gap illness_cusum just got patched for. a quantized-but-nonzero
RHR baseline (alternating 54/55/56, sd ~0.76) let a small +3bpm night
fabricate an extreme z and clear mdc trivially. add the same
dispersionBelowQuantum(rhrHistory, 1.0) guard, abstain the RHR axis
when it fires. rmssd untouched, it's not quantized this way.

widened the shared test fixture (was itself sub-quantum) so the
heavy/moderate/light tests keep testing real signal, and added a
regression test for the abstain case.
@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 36 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: d735cf48-e95b-458e-8ab8-f3de16ec9a44

📥 Commits

Reviewing files that changed from the base of the PR and between 8368d5e and 75f85cc.

📒 Files selected for processing (2)
  • lib/src/onehz/human/event_detection.dart
  • test/onehz/human_test.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 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 18 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

Prevents whole-bpm RHR quantization noise from creating extreme z-scores and false alcohol-night classifications by mirroring the existing dispersion-below-quantum guard, with targeted fixture updates and an abstention regression test.

Sequence diagram for guarded alcohol-night RHR evaluation

sequenceDiagram
    participant Caller
    participant alcoholNightFlag
    participant Baseline as robustBaseline
    participant Quantum as dispersionBelowQuantum
    participant MDC as mdc

    Caller->>alcoholNightFlag: alcoholNightFlag(...)
    alcoholNightFlag->>Baseline: robustBaseline(rhrHistory)
    alcoholNightFlag->>Quantum: dispersionBelowQuantum(rhrHistory, _rhrQuantum)
    alt RHR dispersion below 1 bpm
        alcoholNightFlag->>alcoholNightFlag: rhrZ = null
        alcoholNightFlag->>alcoholNightFlag: rhrMdc = null
        alcoholNightFlag->>alcoholNightFlag: rhrUp = false
    else RHR dispersion is resolvable
        alcoholNightFlag->>Baseline: modZ(tonight.rhr)
        alcoholNightFlag->>MDC: mdc(rhrBase)
    end
    alcoholNightFlag-->>Caller: Metric<EventState> with abstention note when guarded
Loading

Flow diagram for whole-bpm RHR abstention

flowchart TD
    A["Nightly RHR and history"] --> B["dispersionBelowQuantum(rhrHistory, _rhrQuantum)"]
    B -->|"below 1 bpm"| C["rhrZ = null; rhrMdc = null"]
    B -->|"resolvable dispersion"| D["rhrBase.modZ(tonight.rhr); mdc(rhrBase)"]
    C --> E["rhrUp remains false; RHR axis abstained"]
    D --> F["RHR signal can contribute to alcoholNightFlag"]
    E --> G["RMSSD continues independently"]
    F --> H["EventState and explanatory note"]
    G --> H
Loading

File-Level Changes

Change Details Files
Add a whole-bpm dispersion guard to abstain from unreliable nightly RHR standardization.
  • Define a 1 bpm RHR quantum consistent with existing channel conventions.
  • Null RHR z-score and MDC when baseline dispersion is below the quantum, while leaving RMSSD processing and downstream null-safe behavior unchanged.
  • Append an explanatory note suffix when the RHR axis is abstained.
lib/src/onehz/human/event_detection.dart
Update alcohol-night coverage for resolvable RHR baselines and sub-quantum regression behavior.
  • Widen the shared RHR fixture so existing band tests retain real dispersion.
  • Add a regression test ensuring an ordinary +3 bpm night does not produce a moderate/heavy alcohol band and reports abstention.
test/onehz/human_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

@abdulsaheel
abdulsaheel merged commit def6999 into main Sep 18, 2026
4 checks passed
@abdulsaheel
abdulsaheel deleted the fix/alcohol-rhr-quantum-guard branch September 18, 2026 20:35
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