diag(hrv): size the cross-second R-R over-count with a windowed shadow candidate (#1331/#1118) - #1399
Merged
Merged
Conversation
…w candidate (#1331/#1118) The #1331 4.0 logs read `crossSecondOverCount` every night: the same-second shadow collapses (#1352's exact + 40 ms candidates) can't reach the duplicate twins because they straddle the second boundary, so `cov40` stays ~1.7-2.0 on the heavy nights and RSA-respiration stays blanked by #1127's beat-accuracy gate. Add a THIRD shadow candidate, `xsec` — the 40 ms collapse widened to a 1-second window — logged beside the others so we can SIZE how much of a night is cross-second (does coverage fall to ~1.0, does beat-accuracy clear the 0.5 gate?). `collapseOverCount` gains a `windowSec` param (default 0 = same-second, byte- identical for every existing caller). Instrumentation ONLY — the shipped HRV/resp path is unchanged. The window is a strict UPPER BOUND, deliberately NOT a shippable de-dup: a steady real HR has near-identical intervals one second apart, so a cross-second collapse over-merges real beats (the test pins this: a 10-beat steady stream drops to 5 at window=1). The real fix is density/timeline-based and must be validated against ground truth (@artemc's H10) before it becomes the read path — this just quantifies the target. Both platforms (byte-identical `hrv dedup` line + twin tests).
ryanbr
force-pushed
the
diag/1331-cross-second-dedup-sizing
branch
from
August 17, 2026 04:01
ba443a1 to
1820100
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The latest #1331 4.0 logs read
crossSecondOverCountevery night. #1352's shadow de-dup only tests same-second collapses (exact + 40 ms), which by definition can't reach duplicates that straddle the second boundary — socov40stays ~1.7–2.0 on the heavy nights,beatAccuratestays ~0.46, and RSA-respiration stays blanked by #1127's 0.5 gate. Nothing currently measures how much of the over-count is cross-second.What
Adds a third shadow candidate,
xsec— the 40 ms collapse widened to a 1-second window — logged beside the existing ones in thehrv dedupline, so a capture shows whether a cross-second collapse would drive coverage → ~1.0 and clear the beat-accuracy gate.collapseOverCountgains awindowSecparam (default 0 = same-second, byte-identical for every existing caller).Deliberately instrumentation-only (not the fix)
The shipped HRV/resp path is unchanged. A cross-second window is a strict UPPER BOUND, not a shippable de-dup: a steady real HR has near-identical intervals one second apart, so it over-merges real beats — the test pins this (a 10-beat steady stream drops to 5 at
windowSec=1). The real fix is density/timeline-based and must be validated against ground truth (@artemc's H10) before it touches the read path; this just quantifies the target, matching #1352's "validate before it becomes the read path" pattern.Verification
hrv dedupline + twin tests (HrvCollapseOverCount*gets awindowSeccase on each side).HrvCollapseOverCount/HrvRrCoveragetests green locally.StrandAnalytics(swift-packages) covers the function + test; app-targetIntelligenceEngine.swiftvia the app-build gate (below).