mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 23:33:29 +00:00
v1.4.35 — persistent measurement rollups + partial read-swap
Foundation release for the persistent measurement_rollups cache tier. Adds the additive table + enum, populates it from every measurement write hook, lands the Apple-Health-import end-of-job backfill, and ships the parity-checked read-swap on two reader surfaces. The comprehensive insights aggregator and the slim analytics summaries slice now source count / min / max / mean per type from the DAY rollup buckets via aggregateBuckets, plus the comprehensive dailyByType correlation feed straight from the bucket means. Slope / R² / standard deviation / anomaly counts stay on live SQL — they do not compose across DAY buckets. A defensive parity check against the live aggregate's COUNT(*) falls back to live SQL when divergence is detected. Includes the new scripts/backfill-rollups.ts CLI for the one-shot fold of historical measurements into all four granularities. Tests: 4280 unit + 228 integration. tsc + lint clean. Migration 0067_v1434_measurement_rollups is idempotent under re-run.
This commit is contained in:
1 parent
9715831f82
commit
8dc9edb65e
26 files changed
+2650
-65
No files matched your search
@@ -0,0 +1,144 @@
|
||||
# v1.4.34.4 + v1.4.34.5 — Audit-Marathon Closure
|
||||
|
||||
Shipped: 2026-05-17 (consecutive releases on the same date as v1.4.34.3).
|
||||
|
||||
| Tag | Highlights | Release |
|
||||
| --- | --- | --- |
|
||||
| v1.4.34.4 | Audit-driven hotfix bundle across security, UX, code quality, mobile-deep, docs, GitHub metadata | [v1.4.34.4](https://github.com/MBombeck/HealthLog/releases/tag/v1.4.34.4) |
|
||||
| v1.4.34.5 | Audit follow-on: 24 critical-path integration tests + iOS textarea zoom fix | [v1.4.34.5](https://github.com/MBombeck/HealthLog/releases/tag/v1.4.34.5) |
|
||||
|
||||
## Audit waves
|
||||
|
||||
Eight axes, eight reports archived under `.planning/round-audit-*.md`:
|
||||
|
||||
| Axis | Report | Findings (hotfix-ready / total) |
|
||||
| --- | --- | --- |
|
||||
| Mobile security | `round-audit-mobile-security.md` | 3 / 8 |
|
||||
| UX + accessibility | `round-audit-ux.md` | 8 / 11 |
|
||||
| Code quality + docs | `round-audit-code-quality.md` | 5 / 15 |
|
||||
| README + GitHub discoverability | `round-audit-docs-discoverability.md` | 7 / 15 |
|
||||
| Web performance (Lighthouse-grade) | `round-audit-perf.md` | 3 / 7 |
|
||||
| Mobile-deep (viewport-by-viewport) | `round-audit-mobile-deep.md` | 5 / 16 |
|
||||
| Test coverage gaps | `round-audit-test-coverage.md` | 5 / 8 (mostly critical-path) |
|
||||
| Docs depth (beyond README) | `round-audit-docs-depth.md` | 5 / 14 |
|
||||
|
||||
## What landed (v1.4.34.4 + v1.4.34.5)
|
||||
|
||||
### Security (6 findings)
|
||||
|
||||
- `destroyAllSessions` now wraps `prisma.session.deleteMany` plus `apiToken.updateMany({ revoked: true })` plus `refreshToken.updateMany({ revokedAt: now })` in one `$transaction`. A stolen iOS Bearer no longer survives a user-initiated password change or an admin reset. Same rotation fires from `POST /api/auth/password`, `POST /api/admin/users/[id]/reset-password`, and `DELETE /api/settings/account`.
|
||||
- `/.well-known/` proxy bypass tightened from `startsWith` to an exact-match `Set` seeded with `apple-app-site-association`. Stale `/api/auth/codex/callback` PUBLIC_PATHS entry dropped (route was renamed to the device-code family).
|
||||
- HSTS gains `; preload` (eligible for the Chromium preload list).
|
||||
- Withings host removed from the global CSP and gated to the integration's own routes.
|
||||
- `getClientIp` warns once per process on `TRUST_PROXY_HOPS`/XFF mismatch and exposes a tagged `getClientIpOrTrustWarning(request)` helper so future callers can route to a tighter universal rate-limit bucket.
|
||||
- Service-worker rejects off-origin `notificationclick` URLs and falls back to `/`. Manifest gains `scope` / `id` / `display_override`. Offline fallback body switched to a locale-neutral icon.
|
||||
|
||||
### UX + accessibility (8 findings)
|
||||
|
||||
- Dialog / Sheet close-X, ChartSkeleton loading announcement, and notifications-section breadcrumb all read i18n keys instead of hardcoded English. All six locales updated.
|
||||
- Focus rings on bottom-nav primary links, the More overflow trigger, and the mobile top-bar user menu.
|
||||
- Input / NativeSelect / Select / DateTimeInput tap-target floor: `h-11 sm:h-10` so mobile clears the 44 px WCAG floor.
|
||||
- Admin chip-strip auto-scroll-into-view (matches v1.4.33 settings-shell pattern).
|
||||
- List-page subtitles (measurements / mood / medications) now visible on mobile.
|
||||
- Insights empty-state CTA vocabulary normalised — links open the right measurement form instead of silently failing on BODY_TEMPERATURE / BLOOD_GLUCOSE / PULSE.
|
||||
|
||||
### Mobile-deep responsive (4 findings)
|
||||
|
||||
- `viewport.themeColor` reacts to light/dark via the media-query pair (Android URL bar + iOS PWA status bar match the active palette).
|
||||
- TopBar reserves `env(safe-area-inset-top)` — iOS PWA on notched iPhones no longer clips the logo.
|
||||
- Coach FAB respects `env(safe-area-inset-bottom)` so it floats above the home-indicator inset.
|
||||
- Sonner toaster switches to `theme="system"`.
|
||||
- Five textareas now ship `text-base sm:text-sm` so iOS Safari no longer zooms-on-focus (Coach composer, bug-report description, admin feedback note, medication-side-effects notes, medication-intake JSON import).
|
||||
|
||||
### Code quality (5 findings)
|
||||
|
||||
- Dead `SESSION_SECRET` env contract dropped from `.env.example`, `docker-entrypoint.sh`, `docker-compose.yml`, `CONTRIBUTING.md`, `docs/self-hosting/scaling.md`, and the README Quick Start (three secrets, not four).
|
||||
- `toJson<T>()` helper consolidates seven Prisma JSON-cast sites.
|
||||
- `db-compat.ts` gains a header docstring naming it the schema-bootstrap path.
|
||||
- Passkey response types adopted from `@simplewebauthn/server` (was `any` + eslint-disable).
|
||||
- Zero-TODO CI gate at `.github/workflows/no-todo-markers.yml`.
|
||||
|
||||
### Docs + discoverability
|
||||
|
||||
- README rework: How-it-compares matrix vs Withings web / Apple Health / Oura / Garmin / generic CSV; Apple Health + AI Coach promoted to standalone Key-Features bullets; status block; latest-release + GHCR badges; OpenAPI pointer above the API table.
|
||||
- openGraph + twitter cards now carry `images` and `summary_large_image`.
|
||||
- GitHub repo metadata: description 290 → 156 chars, keyword-front; `homepageUrl` flipped to `demo.healthlog.dev`; six generic / PII-adjacent topics (`glp-1`, `mounjaro`, `tracking`, `health`, `dashboard`, `bloodpressure`) swapped for six high-intent ones (`apple-health-import`, `withings-alternative`, `glucose-tracker`, `mood-tracker`, `ai-insights`, `personal-dashboard`).
|
||||
- Five new user-facing docs:
|
||||
- `docs/self-hosting/getting-started.md`
|
||||
- `docs/self-hosting/reverse-proxy.md`
|
||||
- `docs/integrations/apple-health.md`
|
||||
- `docs/integrations/withings.md`
|
||||
- `docs/integrations/ai-providers.md`
|
||||
- `docs/README.md` clarifies the in-repo docs tree role vs `docs.healthlog.dev`.
|
||||
|
||||
### Tests (24 new integration cases)
|
||||
|
||||
| Surface | File | Cases |
|
||||
| --- | --- | --- |
|
||||
| User-initiated password change | `tests/integration/auth-password-change.test.ts` | 5 |
|
||||
| Admin reset-password | `tests/integration/admin-reset-password.test.ts` | 5 |
|
||||
| Withings OAuth handshake | `tests/integration/withings-oauth.test.ts` | 5 |
|
||||
| Passkey register | `tests/integration/passkey-register.test.ts` | 4 |
|
||||
| IW-G cache-invalidation matrix | `tests/integration/cache-invalidation-coverage.test.ts` | 5 |
|
||||
|
||||
Integration suite: 197/50 → 222/55. Unit suite: 4235 → 4266. tsc + lint clean throughout.
|
||||
|
||||
## Findings deferred (not landing in v1.4.34.x)
|
||||
|
||||
- **F-1 mobile-security**: Apple Health unzip OOM / zip-bomb (4-h streaming refactor). Real DoS, but the refactor is non-trivial — v1.5.x.
|
||||
- **F-4 mobile-security**: Withings shared webhook secret. Rotation runbook + helper script, operator-side — v1.5.x.
|
||||
- **F-8 mobile-security**: Audit-log coverage gap on Bearer mutation paths. Sweep + regression test — medium effort, v1.5.x.
|
||||
- **F-4 / F-6 UX**: 5 non-English plural strings (medium effort) and chart accessibility (figure / figcaption synthesis) — v1.5.x.
|
||||
- **F-3 mobile-deep**: 5 raw DialogContent never migrated to ResponsiveSheet (doctor report, intake import ×2, password change, app-log preview). Substantial UX touch — defer.
|
||||
- **Code quality F-1**: 2 366 version-tagged inline comments + 244 wave/phase markers. Sweepable in one focused half-day; not blocking.
|
||||
- **Code quality F-2**: 7-file domain-prompt factory refactor.
|
||||
- **Code quality F-4**: 171 lib exports lack JSDoc.
|
||||
- **Perf F-1 / F-3**: Insights/Dashboard fan-out queries → server-side `Promise.all` inside Suspense; `/api/insights/targets` SQL-aggregator gap. Higher-cost work; benchmark in a v1.5 perf pass.
|
||||
- **Docs-depth F-7**: OpenAPI 14-documented vs 181-actual route divergence. Intentional iOS-codegen-locked subset; needs docstring clarification, not a full spec rewrite.
|
||||
|
||||
## Coolify auto-deploy
|
||||
|
||||
**Working in production.** v1.4.34.3 was the first release deployed by Coolify without a manual MCP trigger or a host-side retag fallback — proving the v1.4.34.2 `pull_policy: always` fix lands as designed. Every subsequent release (v1.4.34.4, v1.4.34.5) auto-pulls on tag push.
|
||||
|
||||
The v1.4.34 closure's Operator-Action #4 ("watch registry for new digests" toggle) is obsoleted by this fix.
|
||||
|
||||
## Operator actions still pending
|
||||
|
||||
These remain environment-side, unchanged by v1.4.34.4/.5:
|
||||
|
||||
1. edge01 Coolify-MCP daemon restart.
|
||||
2. edge01 `DATABASE_URL` pool-bump (apps01 already drained).
|
||||
3. Coolify resource-limits resize on apps01 (CPU=2, Memory=1g, Reservation=512m).
|
||||
4. ~~Coolify "watch registry for new digests" toggle~~ — obsoleted by v1.4.34.2 `pull_policy: always`.
|
||||
5. apps01 28 duplicate env-pairs prune.
|
||||
|
||||
## Tests of note
|
||||
|
||||
- 4266 unit tests pass (was 4235 — +31 new).
|
||||
- 222 integration tests pass across 55 files (was 197 across 50 — +24 new + 5 new files).
|
||||
- `tsc --noEmit` clean.
|
||||
- `eslint` clean.
|
||||
- Zero TODO/FIXME/XXX/HACK markers in product code, now CI-enforced.
|
||||
- 4 pre-existing e2e failures on main (`onboarding-flicker-dashboard` + `mobile-viewport touch-targets≥44×44`) carry from v1.4.34 — not introduced by this work.
|
||||
- 4 pre-existing integration-test parallel-DB-isolation flakes (`apns-dispatch`, `integration-status`) — not introduced by this work.
|
||||
|
||||
## What changed quantitatively
|
||||
|
||||
- **24 commits** since the v1.4.34.3 release (Coach-CTA removal):
|
||||
- 2 security commits (token wipe + well-known proxy; HSTS + CSP + SW + manifest)
|
||||
- 1 UX commit (8 hotfix-ready findings)
|
||||
- 1 code-quality commit (5 hotfix-ready findings)
|
||||
- 1 mobile + docs commit (themeColor + FAB + Sonner + 2 self-hosting docs)
|
||||
- 1 integration-docs commit (Apple Health + Withings + AI providers)
|
||||
- 1 TopBar safe-area commit
|
||||
- 1 textarea iOS-zoom commit
|
||||
- 1 critical-path tests commit
|
||||
- 8 audit-report + planning commits
|
||||
- 2 release commits (v1.4.34.4, v1.4.34.5)
|
||||
- 1 toJson test-mock fix commit
|
||||
- **2 GitHub releases** shipped with full notes
|
||||
- **5 new user-facing docs** under `docs/`
|
||||
- **8 audit reports** archived under `.planning/round-audit-*.md`
|
||||
- **31 new unit tests + 24 new integration tests** = 55 net test gain
|
||||
|
||||
End of audit marathon. The next layer of findings (perf fan-out queries, prompt-factory refactor, version-tag sweep, JSDoc gap, plural-i18n) is captured per-file in the audit reports for a future v1.5.x pass.
|
||||
@@ -0,0 +1,75 @@
|
||||
# v1.4.35 handover — finish Layer B + ship
|
||||
|
||||
**Current state:** Foundation committed on `develop` as `9872081d`. Reads still on live-SQL. Read-swap NOT done yet.
|
||||
|
||||
## What's already in (commit `9872081d`):
|
||||
|
||||
- `prisma/migrations/0067_v1434_measurement_rollups/` — additive
|
||||
- `MeasurementRollup` model + `RollupGranularity` enum (`prisma/schema.prisma`)
|
||||
- `db-compat.ts` schema-bootstrap path
|
||||
- `src/lib/measurements/rollups.ts` — `recomputeBucketsForMeasurement` (sync DAY, pg-boss WEEK/MONTH/YEAR), `recomputeUserRollups` (full range), `ensureUserRollupsFresh` (stale-detect + bounded recompute)
|
||||
- `src/lib/measurements/rollup-read.ts` — read helpers
|
||||
- Write hooks on all 6 measurement-mutation endpoints (try/catch wrapped)
|
||||
- Apple-Health-import worker post-completion `recomputeUserRollups` call
|
||||
- `scripts/backfill-rollups.ts` (CLI, idempotent, single-user serial)
|
||||
- pg-boss `rollup-recompute` worker subscription (concurrency=2, singleton-keyed)
|
||||
- +14 unit + 3 integration tests. tsc + lint clean.
|
||||
- `ensureUserRollupsFresh` is called as a side effect from `comprehensive-aggregator`, `summaries-slice`, `/api/analytics`. Response still served by live-SQL.
|
||||
|
||||
## What's STILL TO DO for v1.4.35:
|
||||
|
||||
### 1. Parity-safe read-swap
|
||||
|
||||
Modify `src/lib/insights/comprehensive-aggregator.ts` so the per-type aggregate query reads `count/min/max/mean` from `measurement_rollups` (granularity=DAY, 90-day window) and composes them:
|
||||
- `count` = `sum(bucket.count)` across DAY buckets
|
||||
- `min` = `min(bucket.minValue)`
|
||||
- `max` = `max(bucket.maxValue)`
|
||||
- `mean` = `sum(bucket.mean * bucket.count) / sum(bucket.count)` (weighted mean)
|
||||
- `slope7/30/90`, `r2_7/30/90`, `stddev`, `anomalyCount` — **stay on the existing live-SQL aggregation** (the `CTE` block in the current `$queryRawUnsafe`). These don't compose linearly across buckets.
|
||||
- `latest` + `latestMeasuredAt` — also stay on raw rows (`DISTINCT ON (type)` query already in the file).
|
||||
|
||||
For `dailyByType` (the correlation pairing input, currently `date_trunc('day', measured_at)` aggregate): **read directly from `measurement_rollups`** filtered to `(userId, type, granularity=DAY, bucketStart in 90d)` and map `bucket.bucketStart → day, bucket.mean → value`. Byte-identical to the current daily-mean computation.
|
||||
|
||||
Same pattern in `src/lib/analytics/summaries-slice.ts` (the slim slice).
|
||||
|
||||
### 2. Stale-handling on read
|
||||
|
||||
If `ensureUserRollupsFresh` fires a recompute, the bucket data MIGHT be momentarily stale relative to the freshly-written measurement (the recompute is async-ish for non-DAY grain). For the DAY-grain read paths above, this is fine because `recomputeBucketsForMeasurement` ran SYNC on the most recent write. But add a fallback: if bucket-derived count/min/max disagrees with a fresh `findFirst({ orderBy: { measuredAt: 'desc' } })` (i.e. there's a measurement after the newest bucket's `bucketStart + 1d`), fall back to live-SQL for that type.
|
||||
|
||||
### 3. Tests
|
||||
|
||||
Add to `tests/integration/measurement-rollups.test.ts`:
|
||||
- Seed 50 measurements across 30 days → `comprehensive` response's `summaries[type].count/min/max/mean` matches a parallel live-SQL aggregation byte-for-byte.
|
||||
- Same for `dailyByType`.
|
||||
- Write a new measurement after warm cache → next read reflects it correctly.
|
||||
|
||||
### 4. Release flow
|
||||
|
||||
1. Bump `package.json`: `1.4.34.5 → 1.4.35`
|
||||
2. CHANGELOG entry under `## [1.4.35] — 2026-05-17 — Persistent measurement rollups + partial read-swap`. Cover: schema migration, write hooks, Apple-Health-import backfill, partial read-swap (count/min/max/mean + dailyByType from buckets; slope/r2/sd stay on live), backfill script. Mention this is the foundation for v1.5.1's full read-swap.
|
||||
3. Commit the read-swap + version bump + changelog on develop.
|
||||
4. `git checkout main && git merge --squash develop && git checkout --theirs CHANGELOG.md package.json && git add CHANGELOG.md package.json && git commit -m "v1.4.35 — persistent measurement rollups + partial read-swap"` (let auto-merge handle the route files).
|
||||
5. `git tag -a v1.4.35 -m "v1.4.35 — persistent measurement rollups + partial read-swap"`
|
||||
6. `git push origin main && git push origin v1.4.35`
|
||||
7. `gh release create v1.4.35 --title "v1.4.35 — Persistent measurement rollups + partial read-swap" --notes "..."` (full notes from CHANGELOG).
|
||||
8. Coolify will auto-pull via the v1.4.34.2 `pull_policy: always` fix.
|
||||
9. Wait for live: `until curl -s https://healthlog.bombeck.io/api/version | jq -e '.data.version == "1.4.35"' > /dev/null; do sleep 30; done`.
|
||||
10. **Run backfill against Marc's account post-deploy.** Marc's userId is in the Coolify Postgres — either run via `coolify-apps01` MCP exec (preferred) or instruct Marc to SSH and run `docker exec <container> pnpm tsx scripts/backfill-rollups.ts --user <marcs-userId>`. Expected runtime: single-digit minutes.
|
||||
|
||||
### 5. Closure
|
||||
|
||||
- Update `.planning/round-audit-marathon-closure.md` to note Layer B / v1.4.35 landed.
|
||||
- Write/update `~/.claude/projects/-Users-marc-Projects-HealthLog/memory/project_v14345_audit_marathon.md` to flip Layer B from "deferred to v1.5.x" to "shipped as v1.4.35".
|
||||
|
||||
## Caveats / gotchas
|
||||
|
||||
- The byte-shape parity check is the load-bearing concern. Run the comprehensive integration test BEFORE squash-merge to main — if it fails byte-shape parity, the read-swap is wrong (most likely a weighted-mean rounding mismatch).
|
||||
- `setup.ts.truncateAllTables` already includes `measurement_rollups` — no need to touch.
|
||||
- pg-boss worker subscription is in `src/lib/jobs/reminder-worker.ts` under the `rollup-recompute` job name. Existing pattern — copy how `reminder-fan-out` is wired if a second subscription needs adding.
|
||||
- The agent's `$queryRawUnsafe` + enum-whitelist pattern for `date_trunc` unit is intentional (Postgres 42803). Don't try to bind the unit literal.
|
||||
|
||||
## How Marc resumes
|
||||
|
||||
The exact prompt to fire in a fresh session:
|
||||
|
||||
> Mache v1.4.35 fertig. Lies `.planning/round-v1435-handover.md` — Foundation steckt schon im commit `9872081d` auf develop. Du musst nur noch den parity-safe Read-Swap landen (count/min/max/mean + dailyByType aus DAY-Buckets, slope/r2/sd bleiben auf live-SQL), Tests grün, dann komplett shippen: version bump, CHANGELOG, squash zu main, tag v1.4.35, GH release, live verify, backfill für meinen Account post-deploy. Closure + Memory-Update zum Schluss.
|
||||
Reference in new issue
Block a user