Skip to content

TestFlight diagnostic build: HealthKit logging + permission fixes - #30

Draft
gsbernstein wants to merge 4 commits into
masterfrom
cursor/healthkit-diagnostics-999a
Draft

TestFlight diagnostic build: HealthKit logging + permission fixes#30
gsbernstein wants to merge 4 commits into
masterfrom
cursor/healthkit-diagnostics-999a

Conversation

@gsbernstein

@gsbernstein gsbernstein commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Purpose

TestFlight diagnostic build for a tester who cannot load HealthKit sleep data. Adds local logging with a share/copy flow in Settings — no third-party analytics.

Also fixes several issues found while investigating:

  • Grant Access did nothingrequestAuthorization() returned early when state was already hasRequested from a silent init attempt, so the button had no effect. Grant now always calls requestAuthorization, shows a spinner, and surfaces errors.
  • Launch crash (build 8) — SwiftData store reset recovery on schema mismatch.
  • Infinite spinner — preferences seeding no longer cancels the HealthKit bootstrap task.
  • Xcode build failure (exit 65)DiagnosticLogger.log() was MainActor-isolated but called from BedtimeApp's nonisolated static ModelContainer initializer. Fixed by making log() nonisolated.

For the tester

  1. Install this build from TestFlight
  2. Open the app, try Grant Access on the home screen (or Retry HealthKit Access in Settings)
  3. Go to Settings → Diagnostics
  4. Tap Share Diagnostic Logs (Messages/Mail) or Copy Logs to Clipboard
  5. Send the logs to Greg

The logs include: HealthKit availability, authorization calls, sample counts, discovered sources, permission state transitions, and ModelContainer status.

What to look for in logs

  • Silent load returned 0 samples + requestAuthorization returned + still 0 samples → likely read access denied (check Settings → Health → Data Access & Devices → Bedger → Sleep)
  • Display query error → HealthKit query failure with message
  • Discovered N sources with N > 0 but 0 sessions → source filtering or sleep stage parsing issue
Open in Web Open in Cursor 

cursoragent and others added 4 commits July 24, 2026 14:27
- DiagnosticLogger records HealthKit bootstrap, queries, and state changes.
- Settings Diagnostics section: share/copy logs, retry HealthKit, live state.
- Grant Access always calls requestAuthorization and shows loading/errors.
- Bootstrap tries silent data load first; only prompts when zero samples.
- Await HK queries, recover from SwiftData store failures, fix preferences seeding.

Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
Make log() nonisolated so it can be called from BedtimeApp's static
ModelContainer initializer. Move UI-published mutations to @mainactor
record() and remove init-time logging that referenced shared during init.

Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
Present UIActivityViewController from the topmost view controller instead
of nesting a SwiftUI sheet inside the Settings sheet.

Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
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