Skip to content

Fix Healthspan activity and HealthKit steps - #1188

Merged
Asherlc merged 3 commits into
mainfrom
Asherlc/fix-activity-steps-messaging
May 27, 2026
Merged

Asherlc merged 3 commits into
mainfrom
Asherlc/fix-activity-steps-messaging

Conversation

@Asherlc

@Asherlc Asherlc commented May 26, 2026

Copy link
Copy Markdown
Owner

Fixes HealthKit incremental sync to request daily quantity samples from the local day boundary instead of a rolling 24-hour window, preventing partial step totals from replacing full-day values. Updates Healthspan scoring to use weekly exercise minutes from daily metrics as the aerobic activity floor when heart-rate zone minutes undercount activity. Adds mobile and server regressions for the step sync window and Healthspan activity score behavior, and records the production incident analysis in docs/production-incident-baseline.md. Validation: pnpm lint; pnpm test:changed; pnpm tsc --noEmit; cd packages/server && pnpm tsc --noEmit; cd packages/web && pnpm tsc --noEmit.


Summary by cubic

Fixes undercounted steps and aerobic minutes by syncing HealthKit daily stats from the local day boundary and using device-reported weekly exercise minutes as a floor. Bounds all Healthspan reads to the selected date window and the user's access window.

  • Bug Fixes
    • Mobile: Incremental HealthKit sync now starts at the local calendar-day boundary instead of a rolling 24 hours to avoid partial-day overwrites.
    • Server: Healthspan bounds all reads (RHR, steps, strength, HR‑zone) to the date window and access window, adds an exclusive end bound to the HR‑zone query, and uses weekly exercise minutes from fitness.v_daily_metrics as the aerobic floor when zone minutes are lower or missing.
    • Tests/Docs: Added regressions for day-boundary sync, aerobic fallback, and SQL bounds; documented the production incident.

Written for commit cbe1a9b. Summary will update on new commits. Review in cubic

Copilot AI review requested due to automatic review settings May 26, 2026 23:07
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@surmado-code-review

surmado-code-review Bot commented May 26, 2026

Copy link
Copy Markdown

Automated Checks (advisory, non-blocking)

✅ All checks passed.


Surmado Code Review — Free tier limit reached

You've used all 10 free reviews this month. Deterministic checks (secrets, model strings) still ran above.

Upgrade to the Paid plan for 100 reviews/month + $15 per additional 100: https://app.surmado.com/checkout?plan=pr_review_starter

Or wait until your next monthly window for 10 more free reviews.


Surmado Code Review (v1.2-mt)

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Asherlc, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Asherlc, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 45 minutes and 47 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f947c63e-551d-42ea-8ddc-796d70c6f7ae

📥 Commits

Reviewing files that changed from the base of the PR and between 5accc61 and cbe1a9b.

📒 Files selected for processing (6)
  • docs/production-incident-baseline.md
  • packages/mobile/lib/health-kit-sync.test.ts
  • packages/mobile/lib/health-kit-sync.ts
  • packages/server/src/routers/healthspan-query.test.ts
  • packages/server/src/routers/healthspan-query.ts
  • packages/server/src/routers/healthspan.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

Storybook previews for aa7486bb are ready:

This comment updates automatically on each PR push.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: The changes fix two specific, well-documented bugs with targeted logic updates, add regression tests, and include a production incident analysis, presenting low risk as they are isolated to HealthKit sync window alignment and Healthspan scoring floor logic without altering core infrastructure...

Re-trigger cubic

@github-actions

github-actions Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

Mobile Preview

Scan to open on device:

QR code for dofek://preview/pr-1188

Channel pr-1188
Deep Link dofek://preview/pr-1188
Commit aa7486b

To test on device:

  1. Build and install the preview client: PREVIEW_CHANNEL=pr-1188 npx expo prebuild --clean -p ios
  2. Or tap deep link on an existing preview build: dofek://preview/pr-1188

Each PR gets its own channel. Build a preview client with PREVIEW_CHANNEL=pr-{N} to test.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a production issue where (1) HealthKit incremental sync could overwrite full-day step totals with partial-day values and (2) Healthspan aerobic activity could undercount when HR/power-derived zone minutes are missing or low. It adjusts the mobile HealthKit sync window to start at the local day boundary and updates server-side Healthspan aggregation to floor aerobic minutes using device-reported weekly exercise minutes, with regression tests and an incident write-up.

Changes:

  • Mobile: Start incremental HealthKit daily-statistics queries from the local calendar-day boundary (instead of a rolling 24h window).
  • Server: Add a Postgres query for weekly exercise_minutes from fitness.v_daily_metrics and use it as a floor for weekly aerobic minutes when HR-zone minutes undercount.
  • Quality/docs: Add regression tests for both behaviors and document the incident analysis.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/server/src/routers/healthspan-query.ts Adds weekly exercise-minute aggregation and uses it as an aerobic-minutes floor in Healthspan raw data.
packages/server/src/routers/healthspan.test.ts Updates router/unit tests to account for the additional DB query and adds coverage for the new activity-floor behavior.
packages/server/src/routers/healthspan-query.test.ts Adjusts raw-data tests for the additional DB call.
packages/mobile/lib/health-kit-sync.ts Changes incremental sync start date to local midnight of the lookback window.
packages/mobile/lib/health-kit-sync.test.ts Adds regression test for day-boundary incremental sync behavior.
docs/production-incident-baseline.md Records incident symptoms, root cause, mitigation, and follow-ups.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/server/src/routers/healthspan-query.ts
Comment thread packages/server/src/routers/healthspan-query.ts Outdated
Comment thread packages/server/src/routers/healthspan.test.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 3 files (changes from recent commits).

Auto-approved: The changes are targeted bug fixes for undercounted HealthKit steps and Healthspan aerobic minutes, with thorough regression tests and no risky refactors or critical-path modifications.

Re-trigger cubic

@github-actions

Copy link
Copy Markdown
Contributor

Review app is ready:

This environment runs on a dedicated Hetzner server for PR #1188 and updates on each push.

@Asherlc
Asherlc merged commit 9f8a341 into main May 27, 2026
66 checks passed
@Asherlc
Asherlc deleted the Asherlc/fix-activity-steps-messaging branch May 27, 2026 00:06
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