Fix: scope Health Connect aggregate null-bucket skip to HEART_RATE only#19
Merged
Merged
Conversation
PR #18 changed getAggregateHCData so a missing aggregate bucket is skipped (`?: continue`) instead of falling back to 0, to avoid fabricating a 0 BPM heart-rate reading. That skip was applied unconditionally to every metric MapToHCAggregateMetric handles (STEPS, WEIGHT, HEIGHT, DISTANCE_DELTA, WATER, the SLEEP_* durations, ACTIVE_ENERGY_BURNED, TOTAL_CALORIES_BURNED), not just HEART_RATE. For every one of those other types, zero is a legitimate value for a bucket (e.g. 0 steps taken in an interval), so skipping the bucket silently drops real data instead of reporting it as zero. Scope the skip-on-null behavior to dataType == HEART_RATE and restore the zero fallback for every other aggregate metric type. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
PR #18 ("Stream Health Connect reads page-by-page + optional native downsampling (fixes HR OOM)") changed
getAggregateHCDatainHealthPlugin.ktso that a missing/empty aggregate bucket is skipped entirely (?: continue) instead of falling back to0. The stated rationale was heart-rate specific: a 0 BPM reading is not a real data point, so it shouldn't be fabricated for buckets with no HR samples.That rationale is correct for
HEART_RATE, but thecontinuewas applied unconditionally to every metric type this function handles viaMapToHCAggregateMetric—STEPS,WEIGHT,HEIGHT,DISTANCE_DELTA,WATER, theSLEEP_*duration types,ACTIVE_ENERGY_BURNED, andTOTAL_CALORIES_BURNED. For all of those, zero is a legitimate, meaningful value for a bucket (e.g. 0 steps taken, 0 meters traveled, 0 calories burned in an interval with no activity). Skipping the bucket instead of reporting0silently drops real data for every non-HR caller.This PR scopes the skip-on-null behavior to
dataType == HEART_RATEonly, and restores the old zero-fallback for every other aggregate metric type.?: continue) rather than fabricating0.HEART_RATEonly; every other metric type gets the old zero-fallback back.No current caller in
shiftapp_flutteris affected — it only queriesHEART_RATEaggregates — but this is a shared plugin fork, and any other/future caller of a non-HR aggregate type would otherwise get silently-missing buckets instead of zeros.This was caught in review after #18 merged — it's a latent scope issue present in the original PR, not a regression introduced by this change.
Related: #18
Out of scope (noted, not touched)
Two issues were identified in the surrounding code during this review but are explicitly out of scope for this PR and were not touched:
SleepSessionRecordbranch ingetHCDatareadsresponse.recordsfrom only the last page of a paginated sleep query instead of accumulating across all pages.samplingIntervalMillisdownsampling ingetHCDatarelies on — not confirmed as a bug, needs real-device validation.Diff
Single-file, Kotlin-only change in
packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt, scoped entirely to the null-bucket-handling block insidegetAggregateHCData. Does not touchgetHCData, the page-by-page/samplingIntervalMillisdownsampling logic, theHEART_RATE to HeartRateRecord.BPM_AVGmapping, or thetry/catcharoundgetAggregateHCData— all added by #18 and correct/unrelated.Test plan
is Length/is Energychecks and themapOfconstruction).packages/health/example/androidfails to build withflutter build apk --debugdue to a pre-existing, unrelated Flutter-Gradle-plugin-loading incompatibility (the example project uses the legacy imperativeapplystyle, which the installed Flutter 3.35.4 toolchain rejects). This is a project-config issue independent of this change and was not touched.android/src/testdoesn't exist), consistent with the rest of the codebase.