Skip to content

Give up on a stuck push token request on mobile - #8419

Merged
ymichael merged 1 commit into
mainfrom
bb/8392-ios-app-push-switch-spins-forever-and-the-p-thr_cqfe85c9g8
Dec 1, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/8392-ios-app-push-switch-spins-forever-and-the-p-thr_cqfe85c9g8

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

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 (#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 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; Fetch the Expo push token once per device token on mobile #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 #8392

AGENT GENERATED

🤖 Generated with Claude Code

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
ymichael merged commit 4419acb into main Dec 1, 2026
23 checks passed
@ymichael
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]>
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.

iOS app: push switch spins forever and the phone never registers when the Expo push token request never settles

1 participant