Repository navigation
Conversation
syncPushRegistration awaited getExpoPushTokenAsync with no bound. When the APNs device token or the exp.host request never settled, the sync never returned, the switch kept spinning, and every later sync waited behind it on the controller's shared queue. The token step now fails after 20 s with action "failed", step "token", so the status shows "Could not register: ...", the toggle shows its error toast and is usable again, and syncs for other servers run. A coalesced rerun of the same sync reuses that failure instead of starting another 20 s wait. Fixes #8392 Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/8392-ios-app-push-switch-spins-forever-and-the-p-thr_cqfe85c9g8
branch
December 1, 2026 00:50
scowalt
pushed a commit
to scowalt/bb
that referenced
this pull request
Dec 1, 2026
## Human comments ## What was wrong `syncPushRegistration` awaited the Expo push token (`getExpoPushTokenAsync`: the APNs device token, then a POST to exp.host) with no time limit. When either step never settled, the sync never returned. The controller keeps `syncing: true` until a sync returns, and all syncs run one after another on one shared queue. So the switch spun forever, the phone never sent `pushSubscriptions.add`, and syncs for other servers waited behind the stuck one (get-bb#8392). get-bb#8225 (already merged) doesn't change this: it still fetches the token once at cold start, and that fetch has no time limit. ## What changed - `apps/mobile/src/data/notifications/push-registration.ts`: the token step gives up after `PUSH_TOKEN_TIMEOUT_MS` (20 s) and returns `{ action: "failed", step: "token" }`. The status reads "Could not register: No push token from Apple or Expo after 20 s", the existing toggle toast shows the error, the switch becomes usable again, and queued syncs run. A later attempt fetches again; get-bb#8225's cached token stays empty after a failure. On iOS, a new native `getDevicePushTokenAsync` call replaces the stuck one, so a retry doesn't conflict with the stuck request. - `push-registration-controller.ts`: turning the switch on starts a second sync of the same server (`PushNotificationsHost`'s effect reruns when `activeEnabled` changes), and the two are coalesced into one sync plus a rerun. Without this change the rerun fetched the token again, so the spinner lasted about 40 s and the toast showed late. A rerun inside the same coalesced sync now reuses the token failure instead of waiting again. A rerun that unregisters needs no token and runs normally. - No server, wire, CLI or protocol changes. ## How you verified - New test `gives up on a push token request that never settles, once per coalesced sync, and runs the next sync`. Without the timeout it never finishes (vitest timeout at 15 s). Without the rerun change it fails (`expected { action: 'registered' } to deeply equal { action: 'failed', … }`). - `pnpm exec turbo run typecheck test lint lint:type-aware --continue --filter=@bb/mobile`: 8 tasks successful, 365 tests passed, 0 lint errors. - iOS 27.2 Simulator, local Debug dev-client build against a `start:worktree` server: - Before: with a temporary QA shim that holds every exp.host `fetch` open, the switch stayed on "Registering…" with a spinner for more than 3 minutes, and `pushSubscriptions.list` on the server was empty. - After: on a cold start and on toggling off and on, the spinner stopped at about 20 s with "Could not register: No push token from Apple or Expo after 20 s" and the toast "Could not turn on notifications". - Apple-side hang, without the shim: right after a simulator boot, the token request hung before any exp.host request. CFNetwork logged no exp.host connection, and apsd never logged the app. With the fix it failed after 20 s. Once apsd was up, toggling registered and the server listed the subscription ("On · registered with this server"). So the hang on vv2002's phone may be in Apple's device-token step rather than exp.host; the timeout covers both. Fixes get-bb#8392 > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
syncPushRegistrationawaited the Expo push token (getExpoPushTokenAsync: the APNs device token, then a POST to exp.host) with no time limit. When either step never settled, the sync never returned. The controller keepssyncing: trueuntil a sync returns, and all syncs run one after another on one shared queue. So the switch spun forever, the phone never sentpushSubscriptions.add, and syncs for other servers waited behind the stuck one (#8392). #8225 (already merged) doesn't change this: it still fetches the token once at cold start, and that fetch has no time limit.What changed
apps/mobile/src/data/notifications/push-registration.ts: the token step gives up afterPUSH_TOKEN_TIMEOUT_MS(20 s) and returns{ action: "failed", step: "token" }. The status reads "Could not register: No push token from Apple or Expo after 20 s", the existing toggle toast shows the error, the switch becomes usable again, and queued syncs run. A later attempt fetches again; Fetch the Expo push token once per device token on mobile #8225's cached token stays empty after a failure. On iOS, a new nativegetDevicePushTokenAsynccall replaces the stuck one, so a retry doesn't conflict with the stuck request.push-registration-controller.ts: turning the switch on starts a second sync of the same server (PushNotificationsHost's effect reruns whenactiveEnabledchanges), and the two are coalesced into one sync plus a rerun. Without this change the rerun fetched the token again, so the spinner lasted about 40 s and the toast showed late. A rerun inside the same coalesced sync now reuses the token failure instead of waiting again. A rerun that unregisters needs no token and runs normally.How you verified
gives up on a push token request that never settles, once per coalesced sync, and runs the next sync. Without the timeout it never finishes (vitest timeout at 15 s). Without the rerun change it fails (expected { action: 'registered' } to deeply equal { action: 'failed', … }).pnpm exec turbo run typecheck test lint lint:type-aware --continue --filter=@bb/mobile: 8 tasks successful, 365 tests passed, 0 lint errors.start:worktreeserver:fetchopen, the switch stayed on "Registering…" with a spinner for more than 3 minutes, andpushSubscriptions.liston the server was empty.Fixes #8392
🤖 Generated with Claude Code