Skip to content

Fix mobile native bridge crash - #1226

Merged
Asherlc merged 6 commits into
mainfrom
Asherlc/sentry-7522052337
Jun 2, 2026
Merged

Asherlc merged 6 commits into
mainfrom
Asherlc/sentry-7522052337

Conversation

@Asherlc

@Asherlc Asherlc commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Fixes a production mobile crash where WHOOP BLE and HealthKit native events could cross the Expo/React Native bridge from background callback queues. WHOOP connection/orientation events and HealthKit observer events now emit on the main thread, and optional nil payload values are stripped before bridging. The production incident baseline documents Sentry issue DOFEK-MOBILE-P, the root cause evidence, and remaining risk. Validated with pnpm lint, root/server/web typechecks, focused mobile Vitest tests, and Swift package tests for both native modules.


Summary by cubic

Fixes a production crash by forcing native whoop-ble and health-kit events to emit on the main thread, stripping nil payloads, and acknowledging HealthKit observer queries after emission. Prevents EXC_BAD_ACCESS during foreground sync when background callbacks crossed the Expo/React Native bridge and avoids re-fired observer updates.

  • Bug Fixes
    • Added MainThreadEventEmitter in whoop-ble and health-kit iOS modules to dispatch on the main thread and drop nil payloads.
    • Updated WhoopBleModule.swift (connect/disconnect/orientation) and HealthKitModule.swift (observer events) to use the helper; HealthKit now calls the observer completion after sending the event; cleaned up SwiftLint closure style.
    • Added Swift tests for both modules (main-thread dispatch, nil compaction, observer completion order) and updated the incident baseline with Sentry DOFEK-MOBILE-P.

Written for commit 9e05a46. Summary will update on new commits.

Review in cubic

@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 Jun 2, 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 3 minutes and 49 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: 2238f1d4-84bc-4e00-b48f-3b103062454c

📥 Commits

Reviewing files that changed from the base of the PR and between 3c776de and 9e05a46.

📒 Files selected for processing (7)
  • docs/production-incident-baseline.md
  • packages/mobile/modules/health-kit/Tests/MainThreadEventEmitterTests.swift
  • packages/mobile/modules/health-kit/ios/HealthKitModule.swift
  • packages/mobile/modules/health-kit/ios/MainThreadEventEmitter.swift
  • packages/mobile/modules/whoop-ble/Tests/MainThreadEventEmitterTests.swift
  • packages/mobile/modules/whoop-ble/ios/MainThreadEventEmitter.swift
  • packages/mobile/modules/whoop-ble/ios/WhoopBleModule.swift

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.

@Asherlc
Asherlc marked this pull request as ready for review June 2, 2026 18:08
Copilot AI review requested due to automatic review settings June 2, 2026 18:08
@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 Jun 2, 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)

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Storybook previews for d4ee0685 are ready:

This comment updates automatically on each PR push.

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Mobile Preview

Scan to open on device:

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

Channel pr-1226
Deep Link dofek://preview/pr-1226
Commit d4ee068

To test on device:

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

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

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Review app deployment was skipped for PR #1226.

Hetzner could not allocate the configured review app server type in the configured location. This is provider capacity/placement availability, not a code failure in this PR.

@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.

1 issue found across 7 files

Confidence score: 3/5

  • There is a concrete reliability risk in packages/mobile/modules/health-kit/ios/HealthKitModule.swift: HKObserverQuery completion may run before the main-thread event dispatch, which can cause background HealthKit update events to be missed.
  • Given the medium severity (6/10) and solid confidence (7/10), this is more than a minor housekeeping issue and could create user-visible data sync gaps.
  • This is likely fixable with ordering/synchronization in the observer callback flow, but it adds meaningful merge risk until addressed.
  • Pay close attention to packages/mobile/modules/health-kit/ios/HealthKitModule.swift - ensure observer completion happens only after the event send is safely executed.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/mobile/modules/health-kit/ios/HealthKitModule.swift 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: This PR fixes a production crash by ensuring bridge events are dispatched on the main thread and nil payloads are stripped; the changes are isolated to two iOS modules, include unit tests, and do not affect core business logic.

Re-trigger cubic

@Asherlc
Asherlc merged commit 3a981f4 into main Jun 2, 2026
66 checks passed
@Asherlc
Asherlc deleted the Asherlc/sentry-7522052337 branch June 2, 2026 19:16
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