rouse-context/integrations
monkopedia-coder 9bde50178e
fix(health): paginate reads + downsample/bucket query_health_data (Fixes #536) (#538)
High-volume record types (e.g. BloodGlucose from a Dexcom CGM, ~288
records/day) crashed query_health_data with a generic tool error. The read
built ReadRecordsRequest with no pageSize, so Health Connect returned a full
~1000-record page in a single Binder transaction that exceeded the ~1MB
limit and threw before serialization. This lands three related changes on a
shared paginated read:

1. Paginated read (crash fix). HealthConnectClientRecordReader now sets a
   bounded pageSize (READ_PAGE_SIZE=1000) and loops over response.pageToken
   until exhausted, with a MAX_RECORDS=50_000 ceiling to bound memory. read's
   signature is unchanged; a PageFetcher seam makes the loop unit-testable.

2. Downsampled raw mode (default). Repository.queryRecords now returns a
   QueryResult(records, totalCount, downsampled). When mapped records exceed
   the cap (limit if given, else DEFAULT_MAX_RECORDS=500) it evenly downsamples
   across the whole range (first and last retained) rather than trimming one
   end, and the tool response gains total_count and downsampled. Real record
   objects are preserved, so the wire contract is unchanged.

3. Bucketed mode (new bucket param). query_health_data takes an optional
   bucket like 1m/5m/1h/1d. Bucketing is guarded BEFORE reading: if the
   expected bucket count exceeds MAX_BUCKETS=1000 it errors with the count and
   limit. It applies only to instantaneous scalar types via a per-type
   bucketValues extractor colocated with the existing mappers in VitalsQueries
   and BodyQueries (BloodGlucose, HeartRate, HRV, RestingHeartRate,
   RespiratoryRate, OxygenSaturation, Body/BasalBody temperature, Weight,
   Height, BodyFat, BoneMass, LeanBodyMass, Vo2Max); session/multi-value/
   cumulative types (SleepSession, ExerciseSession, BloodPressure,
   SkinTemperature, Steps, etc.) return a clear error. Per non-empty window it
   emits {start, count, min, max, avg}.

Tool description updated to document all three behaviors. This is an MCP
tool-behavior change, not an app-UI change, so no docs/ux-decisions.md entry.

Co-authored-by: Monkopedia <monkopedia@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 11:13:23 -04:00
..
src fix(health): paginate reads + downsample/bucket query_health_data (Fixes #536) (#538) 2026-07-08 11:13:23 -04:00
build.gradle.kts Fix #417: Migrate manual JSON in MCP providers to @Serializable data classes (#418) 2026-04-26 12:10:10 -04:00