Skip to content

release/v1.28.31 — heart-rate history keeps its daily shape#477

Merged
MBombeck merged 1 commit into
mainfrom
release/v1.28.31
Jul 12, 2026
Merged

release/v1.28.31 — heart-rate history keeps its daily shape#477
MBombeck merged 1 commit into
mainfrom
release/v1.28.31

Conversation

@MBombeck

Copy link
Copy Markdown
Owner

Dense intra-day retention (PULSE / HRV / SpO2) now folds to hourly means instead of a single daily mean — the day's shape survives permanently (up to 24 points/day ≈ 9k rows/metric/year), while the last 14 days keep every raw sample as before.

Fold changes

  • Hourly key stats:<HK>:<YYYY-MM-DD>T<HH>, local HH:30 anchor; stays under stats: so the idempotency predicate keeps holding; never collides with the daily shape or iOS ISO-instant wire ids.
  • Same adopt-in-place slot logic against both unique indexes (index-A externalId first, index-B anchor instant second), P2002 caught outside the transaction with one retry.
  • Pre-fold DAY-rollup recompute extended to HRV (the real constraint is mean fidelity — a post-fold recompute over hourly rows would store an unweighted mean-of-means); post-fold recompute removed tier-wide.
  • Derived-resting minting for proxy users unchanged (still from raw).

One-shot history rebuild (pg-boss, boot-discovered, once per install)

  • Per qualifying day (live daily-grain row older than the window + surviving tombstoned raws): mint hourly rows and retire the daily row in the same transaction — no instant with both grains live, so no double-count.
  • The retired daily row is the durable marker; discovery converges to zero. Days with pruned tombstones keep their daily mean.
  • PULSE/SpO2 DAY buckets untouched (true pre-fold stats); HRV DAY recomputed from hourly rows; W/M/Y whole-span enqueues.
  • Discovery SQL parameter-bound, constant regex only, pinned by integration tests against real Postgres.

Consumers audited: stress engine, readiness, coincident-deviation, day-detail chart paths — none assume one row per out-of-window day.

Gate: typecheck, lint, 13537 unit tests, dense-tier integration suites (real Postgres, both P2002 vectors + atomic retirement + convergence), prettier, knip, build, openapi:check — all green.

Long-term retention for the dense intra-day tier (PULSE, HRV, SpO2) folds
to per-local-hour means instead of a single daily mean: the last 14 days
keep every raw sample, older days keep up to 24 points per metric — the
day's shape survives permanently at ~9k rows/metric/year. Hourly rows key
as stats:<HK>:<YYYY-MM-DD>T<HH> anchored at local HH:30, adopt-in-place
against both unique indexes with the P2002 retry outside the transaction.
The pre-fold DAY-rollup recompute extends to HRV (mean fidelity, not only
min/max) and the post-fold recompute is gone for the whole tier. Derived
resting rows for proxy users still mint from the day's raw samples.

A one-shot rebuild reconstructs the hourly shape for every already-folded
day from the soft-deleted raw samples and retires the daily row in the
same transaction — at no instant are both grains live, so no
AVG-over-live-rows reader can double-count. Boot discovery pairs live
daily-grain rows with surviving tombstones (parameter-bound SQL, pinned
against real Postgres) and converges to zero once converted; days whose
tombstones were pruned keep their daily mean. PULSE/SpO2 DAY buckets keep
the true pre-fold stats; HRV DAY buckets recompute from the hourly rows
(strictly better than the collapsed fold-time bucket); WEEK/MONTH/YEAR
respans enqueue whole-bucket recomputes.
@MBombeck MBombeck merged commit 14b61e1 into main Jul 12, 2026
13 checks passed
@MBombeck MBombeck deleted the release/v1.28.31 branch July 12, 2026 10:19
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