Skip to content

fix(colmi): preserve quarter-hour offset in activity buckets (up to ~75% step undercount)#87

Merged
saksham2001 merged 2 commits into
saksham2001:mainfrom
rgvxsthi:fix/colmi-activity-buckets
Jul 15, 2026
Merged

fix(colmi): preserve quarter-hour offset in activity buckets (up to ~75% step undercount)#87
saksham2001 merged 2 commits into
saksham2001:mainfrom
rgvxsthi:fix/colmi-activity-buckets

Conversation

@rgvxsthi

Copy link
Copy Markdown
Contributor

Bug

ColmiDecoder.decodeActivityHistory built each activity bucket's timestamp as hour = v[4] / 4, minute = 0, dropping the within-hour quarter (v[4] % 4).

Daily step/distance totals are computed as the sum of buckets keyed by their start epoch (ActivityService.applyActivityBucket upserts by startEpoch). So all four quarter-hour buckets of a given hour collapsed onto HH:00:00 and overwrote each other — only the last-written quarter survived. A normally-worn Colmi/R02 ring that's active in more than one quarter of an hour has its steps and distance undercounted by up to ~75%.

Fix

Set minute = (v[4] % 4) * 15 so each quarter-hour bucket keeps a distinct timestamp/epoch. (v[4] is the quarter-of-day index 0…95 → hour = q/4, minute = (q%4)*15.)

Why tests didn't catch it

The existing ColmiDecoderTests had no coverage for the activity-history bucket path, and the captured fixtures elsewhere used quarter indices that were exact multiples of 4 (one bucket per hour), so no collision occurred. Added testActivityHistoryPreservesQuarterHourOffset — two same-hour quarters (6 → 01:30, 7 → 01:45) must decode to distinct timestamps. Full ColmiDecoderTests suite green.

Found via a code audit; connected-ring, all Colmi/R02-family users.

The activity-history decoder built each bucket's timestamp as
`hour = v[4]/4, minute = 0`, discarding the within-hour quarter
(`v[4] % 4`). Daily step/distance totals are the sum of buckets keyed by
their start epoch, so all four quarter-hour buckets of an hour collapsed
onto HH:00 and overwrote each other — undercounting a normally-worn
Colmi/R02 ring's steps and distance by up to ~75%.

Set `minute = (v[4] % 4) * 15` so each quarter keeps a distinct epoch.
Existing tests passed only because their captured buckets happened to use
quarter indices that were exact multiples of 4 (one per hour); add a
regression test with two same-hour quarters.
@rgvxsthi
rgvxsthi requested a review from saksham2001 as a code owner July 12, 2026 23:41
@saksham2001
saksham2001 merged commit cfa8109 into saksham2001:main Jul 15, 2026
2 checks passed
@rgvxsthi
rgvxsthi deleted the fix/colmi-activity-buckets branch July 16, 2026 04:20
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.

2 participants