Skip to content

Add mobile push notifications to the bb app - #2881

Merged
SawyerHood merged 17 commits into
bb/add-mobile-push-notifications-thr_nuee4d9q4wfrom
bb/push-pr-2-mobile-client-stacked-on-pr-1-thr_7rschxesi6
Sep 2, 2026
Merged

SawyerHood merged 17 commits into
bb/add-mobile-push-notifications-thr_nuee4d9q4wfrom
bb/push-pr-2-mobile-client-stacked-on-pr-1-thr_7rschxesi6

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The bb mobile app could not notify a user when the app was closed. #2872 adds the server side as the built-in push-notifications plugin. This PR stacks on it and adds the phone client. The design and decisions are in plans/bb-mobile-push-self-hosted.md.

What changed

All under apps/mobile/**.

  • Registration talks to the plugin through sdk.plugins.callRpc (pushSubscriptions.add|list|remove) with local zod schemas for the outputs. A missing row on remove counts as already removed. A server without the plugin or with it disabled shows "Push notifications plugin is disabled on this server" in Settings.
  • src/data/notifications/: registration policy (decidePushSync, syncPushRegistration, unregisterPushRegistration, enablePushForProfile, describePushStatus), the coalescing registration controller, the MMKV push store, the RPC wrapper keyed by server URL so a removed profile's row can still be deleted, notification payload to profile resolution, and the badge count.
  • Registration refuses a Direct profile over plain http:// unless the host is loopback. Tailscale Serve and bb connect profiles register normally. The Settings row shows "Push needs HTTPS or bb connect".
  • src/notifications/: PushNotificationsHost (mounted once in app/_layout.tsx) syncs on connect, AppState active, token roll, and toggle; cleans up removed profiles; routes taps, including cold start, to /threads/<id> on the owning profile by matching the serverUrl hint first and probing saved profiles only when no hint matches; shows a foreground toast with Open; shows the one-time "Get notified…" sheet after the first successful connection and never on launch. AppBadgeSync owns the app-icon badge.
  • Settings: new app/settings/notifications.tsx and NotificationsSettingsScreen with one switch per server profile and a status hint, linked from Device settings, reachable at bb://settings/notifications.
  • e2e: shell-deep-link.yaml opens the Notifications screen. README push section and release check updated.

How you verified

  • Tests: push-subscriptions-api.test.ts (RPC mapping, not-found on remove, both unloaded-plugin server messages), push-registration.test.ts (including the plain-HTTP refusal and loopback allowance), push-registration-controller.test.ts, push-store.test.ts, push-notification-target.test.ts (hint match before probing), app-badge.test.ts, shell-links.test.ts.
  • pnpm exec turbo run typecheck test --continue --filter=@bb/mobile: green, 43 test files, 325 tests.
  • Not run here: the dev client and xcrun simctl push (Linux host). Acceptance on a physical iPhone with an EAS development build follows the checklist in the plan.

AGENT GENERATED

…b/push-pr-2-mobile-client-stacked-on-pr-1-thr_7rschxesi6
…b/push-pr-2-mobile-client-stacked-on-pr-1-thr_7rschxesi6
…b/push-pr-2-mobile-client-stacked-on-pr-1-thr_7rschxesi6
…-thr_nuee4d9q4w' into bb/push-pr-2-mobile-client-stacked-on-pr-1-thr_7rschxesi6
…b/push-pr-2-mobile-client-stacked-on-pr-1-thr_7rschxesi6
@SawyerHood
SawyerHood marked this pull request as ready for review September 2, 2026 16:22
SawyerHood and others added 4 commits September 2, 2026 16:28
…b/push-pr-2-mobile-client-stacked-on-pr-1-thr_7rschxesi6
…b/push-pr-2-mobile-client-stacked-on-pr-1-thr_7rschxesi6
@SawyerHood
SawyerHood merged commit cef44ae into main Sep 2, 2026
15 checks passed
@SawyerHood
SawyerHood deleted the bb/push-pr-2-mobile-client-stacked-on-pr-1-thr_7rschxesi6 branch September 2, 2026 16:42
SawyerHood added a commit that referenced this pull request Sep 2, 2026
…plugin event (#2872)

## Human comments

## What was wrong

The bb mobile app had no way to reach a user when the app was closed. An
earlier end-to-end implementation (`b0362ef65` on `bb-mobile-4-push`)
never landed and fell 400 commits behind. It also returned full Expo
push tokens from the unauthenticated list route, had no runtime off
switch, ignored `HTTPS_PROXY`, and could not tell a multi-server phone
which server sent a push. Plugins also could not observe a new pending
interaction, so a notifier could not be written as a plugin at all. The
design, the alternatives, and the settled decisions are in
`plans/bb-mobile-push-self-hosted.md`: the server posts to Expo's push
API directly, so a self-hosted server needs no Apple or Google key and
bb connect holds nothing.

## What changed

Server side only. The mobile client follows in the stacked PR #2881.

- **Plugin SDK.** New `interaction.pending` thread event carrying the
thread and pending interaction DTOs, emitted after the pending row
commits. New `bb.server.experimental_appUrl` exposing the operator's
`BB_APP_URL` (or `null`). Both have entries in `docs/api_to_audit.md`,
Plugin Guide card updates, and a refreshed SDK inventory. RPC method
names may now use dot-separated segments.
- **Built-in plugin `push-notifications`**
(`plugins/push-notifications`, enabled by default). Listens to
`interaction.pending`, `thread.idle` (root, visible threads), and
`thread.failed`; coalesces per thread for 2 s; re-reads the thread and
its interactions through the SDK at flush time and drops the push when
the thread was read, the interaction was answered, the status moved on,
or the thread is archived, deleted, or hidden. Posts batches of 100 to
Expo through undici with `EnvHttpProxyAgent` (honors
`HTTPS_PROXY`/`NO_PROXY`), removes rows on `DeviceNotRegistered`, warns
on network failures at most once per hour, never logs tokens, and
includes `serverUrl` in the push data when the app URL is configured.
- Subscriptions live in plugin key-value storage. RPC
`pushSubscriptions.list|add|remove` (list returns `tokenSuffix`, never
the token). CLI `bb push-notifications list|add|remove|status`.
Declarative setting `expoPushUrl` (default
`https://exp.host/--/api/v2/push/send`). Disabling the plugin is the off
switch.
- Docs: `docs/configuration.md`, `docs/platform-support.md`, a new "Push
notifications on a self-hosted server" section in
`docs/multiple-devices.md`, regenerated guide templates, bb-cli and
plugin-authoring skill references.
- No server-to-daemon wire change, so `HOST_DAEMON_PROTOCOL_VERSION` is
unchanged. No core schema change: the earlier core table and migration
were removed before this PR left draft.

## How you verified

- Tests: `plugins/push-notifications/server.test.ts` (fake Expo endpoint
and fake plugin host: each trigger, coalescing, read and
resolved-interaction cancellation, `serverUrl` present and absent, proxy
dispatcher, warning throttle, `DeviceNotRegistered` cleanup, RPC and CLI
surfaces), `public-sdk-only.test.ts`,
`apps/server/test/services/plugins/plugin-thread-events.test.ts` for the
new event, the builtin-registry tests, `packages/plugin-sdk` fake host
tests, and the Plugin Guide api-sync tests.
- `pnpm exec turbo run typecheck test --continue
--filter=@get-bb/plugin-sdk --filter=@bb/plugin-api-map --filter=@bb/db
--filter=@bb/domain --filter=@bb/server-contract --filter=@bb/server
--filter=@bb/sdk --filter=@bb/cli --filter=@bb/config --filter=bb-app
--filter=@bb/app --filter=bb-plugin-push-notifications`: 30 tasks green.
- `bb plugin build plugins/push-notifications` and `pnpm exec turbo run
smoke:tarball --filter=bb-app`: the packed app ships and starts the
plugin.
- Real delivery to a phone is exercised in the stacked mobile PR.

> AGENT GENERATED

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
ymichael added a commit that referenced this pull request Sep 8, 2026
## Human comments

## What was wrong

On a fresh iOS simulator, Maestro reports `openLink: "bb://threads"`
complete before the operating system's first custom-scheme confirmation
has been accepted. The app remains behind the native `Open in “bb”?`
dialog while `shell-deep-link` waits for `shell-webview`; that
simulator-owned dialog survives the next flow's app stop and launch, so
later flows cannot see their native screens. The original and prior
scheduled evidence show that exact sequence: [run
33637452626](https://github.com/get-bb/bb/actions/runs/33637452626) and
[run
33517924818](https://github.com/get-bb/bb/actions/runs/33517924818).

After this PR was labeled, [run
34273156200](https://github.com/get-bb/bb/actions/runs/34273156200)
checked out the PR merged with newer main and exposed a second
deterministic blocker introduced by #2881: the first-run `Get notified
when a thread needs you?` action sheet covered an otherwise rendered
shell after every direct-server pairing. That explains why
`shell-launch` now failed before any deep link. Its artifact shows the
sheet in all three failed-flow screenshots; `clear-open-confirmation`
passed after each failure and `shell-unreachable-server` passed, proving
the PR's fail-closed cleanup prevented native state from leaking. Every
scheduled main run since #2881 merged shows the same new `shell-launch`
failure, so this recurrence is current-main flow orchestration, not
infrastructure.

## What changed

- Route every Mobile E2E `bb://` action through one parameterized
Maestro subflow. It preserves the real custom-scheme invocation,
conditionally accepts the native confirmation only when visible on iOS,
and proves the dialog is absent before route assertions continue.
- Make the existing direct-server pairing subflow own the post-connect
UI boundary. It uses the unchanged 30-second readiness budget to wait
for either the notification opt-out or rendered page content,
conditionally chooses `Not now`, proves the sheet is absent, and keeps
the `shell-webview` assertion.
- Have `shell-launch`, `shell-deep-link`, and `shell-send` use that one
pairing boundary instead of duplicating pairing. The notifications
deep-link added by #2881 also uses the custom-scheme helper.
- After a failed CI flow, preserve the original final screenshot, cancel
and verify removal of the native confirmation, and stop the app before
continuing. If cleanup cannot establish isolation, the runner stops
before the next flow.
- Add regression coverage for cleanup-before-continuation, fail-closed
cleanup failure, shared pairing, and the absence of direct `bb://`
Maestro commands.
- No assertion, timeout, polling budget, or retry budget increased. No
server/host-daemon wire, CLI, SDK, or user-facing configuration changed,
so `HOST_DAEMON_PROTOCOL_VERSION` is unchanged.

## How you verified

- Mandatory initial fresh-main gate: clean worktree; `HEAD`,
`origin/main`, and merge-base all independently verified as
`ab8e0a202c70525c3c935733300198dac617e3de` before task inspection.
- Before the follow-up edit, fetched and recorded live `origin/main` as
`06047280e04e6ce57554052ec788a1c5defe7d1e`, with PR head
`5f2f960c2c289518b8493dece775f4f22103f722` and retained merge-base
`ab8e0a202c70525c3c935733300198dac617e3de`; then rebased cleanly.
Current PR merge-base is `06047280e04e6ce57554052ec788a1c5defe7d1e`.
- Native red: run 34273156200 failed `shell-launch`, `shell-deep-link`,
and `shell-send` at `shell-webview`; its screenshots show the
notification action sheet over the rendered shell. The new cleanup
passed after every failure, and `shell-unreachable-server` passed.
- Original focused runner red on pre-fix main: 2/2 tests failed because
cleanup was never invoked and the next flow always ran.
- Focused green: `pnpm exec turbo run test --filter=@bb/mobile --force
--concurrency=2 -- --run src/lib/e2e/mobile-e2e-flows.test.ts
src/lib/e2e/ci-run-flows.test.ts` — 2 files, 4 tests passed.
- `pnpm exec turbo run test --filter=@bb/mobile --force --concurrency=2`
— 46 files, 331 tests passed.
- `pnpm exec turbo run typecheck --filter=@bb/mobile --force
--concurrency=2` — passed.
- `pnpm exec turbo run lint --filter=@bb/mobile --force --concurrency=2`
— passed with two pre-existing React warnings and zero errors.
- `pnpm exec turbo run build --filter=@bb/app --force --concurrency=2` —
passed after a frozen-lockfile install refreshed dependencies for
current main; 439 files precompressed.
- `bash -n`, Ruby YAML parsing for every changed Maestro file, targeted
`oxfmt --check`, `git diff --check`, and the no-direct-`bb://` scan
passed. ShellCheck is unavailable on this host.
- [Ordinary CI run
34277221769](https://github.com/get-bb/bb/actions/runs/34277221769)
passed on commit `1594a59a2b2ccf1c17645200f2fb0db522e8861c`, including
build/typecheck/lint, package tests, all app test shards, server,
integration, and Linux/macOS package smoke.
- All local build, test, typecheck, lint, and install commands ran with
explicit process-group deadlines on Intel host `host_nwqfteeqz4`
(`x86_64`, Intel Core i5-1038NG7). A final cwd audit found one stale
earlier Xcode-discovery process group, terminated it, and then proved no
task build, test, backend, fixture, Maestro, or simulator process
remained. Temporary artifacts and logs were moved recoverably to Trash.
- This host has Command Line Tools only, with no Xcode app, iOS runtime,
or Maestro, so no after-change simulator result is claimed. The
`mobile-e2e` label was removed before the updated push; [run
34277221938](https://github.com/get-bb/bb/actions/runs/34277221938)
therefore skipped without starting a simulator.

> AGENT GENERATED: by GPT-5.6-Sol.
ymichael pushed a commit that referenced this pull request Nov 30, 2026
## Human comments

## What was wrong

Each app resume runs two push syncs: the AppState `active` handler (it
also reads the OS permission, #2881) and the effect that runs again when
realtime reconnects (`PushNotificationsHost.tsx`). Each sync called
`syncPushRegistration`, which calls `getExpoPushTokenAsync` before it
checks the stored record. That call is always a POST to
`https://exp.host/--/api/v2/push/getExpoPushToken`. The Expo push token
changes only with the device token, and expo-notifications 58.1.8
already sends device token changes to Expo by itself
(`DevicePushTokenAutoRegistration.fx.ts`, turned on by the first
`getExpoPushTokenAsync`). So the phone made 2 exp.host round trips per
resume to learn a token it already had. I confirmed the call pattern
with the real `createPushRegistrationController` and counting fakes
before changing anything (numbers below).

## What changed

- `apps/mobile/src/data/notifications/push-registration-controller.ts`:
the controller keeps the Expo push token for the app process and gives
`syncPushRegistration` that value instead of a new fetch. It drops the
token when the device token rolls (`handleTokenRolled`, after its
existing duplicate check) and when Android releases the device token
(`releaseUnusedDeviceToken`), so the next sync fetches again. Cold start
still fetches once and compares the token with the stored record, as
before. The 24 h re-registration still runs; it re-registers with the
kept token.
- `push-registration-controller.test.ts`: a new test for the resume
pattern and a token roll. Two tests had the old fetch counts. The
permission-revoke test replaced `notifications.getPermission` after the
controller was built; it now uses a permission variable in `setup()` and
also asserts that the profile is unregistered.
- No wire, CLI, server or protocol changes.

Deviation from the issue's idea (check the record age before the fetch,
and set `registeredAt: 0` on a token roll): that also gives 0 fetches
per resume, but it stops the token check at cold start for up to 24 h,
writes the persisted record on every roll, and does not cover the
Android path where the controller releases the device token while other
profiles keep a fresh record. The in-memory token has none of these
gaps. If a token event arrives while a fetch is in flight, the in-flight
result is kept; the Expo push token does not depend on the device token,
so this can only keep the same value.

## How you verified

Before/after with the real controller and counting fakes (script kept
out of the commit):

| Scenario | exp.host token fetches before | after | server registers
before | after |
| --- | --- | --- | --- | --- |
| Cold start | 1 | 1 | 1 | 1 |
| 10 resumes (AppState active + reconnect effect) | 20 | 0 | 0 | 0 |
| Device token roll, then one sync | 2 | 1 | 0 | 0 |

New test `fetches the Expo push token once per device token, not on
every resume sync`, run against the unfixed controller:

```
FAIL coalesces concurrent syncs for one profile into one in-flight run plus a trailing run
FAIL fetches the Expo push token once per device token, not on every resume sync
AssertionError: expected "vi.fn()" to be called once, but got 2 times
AssertionError: expected "vi.fn()" to be called once, but got 4 times
Tests  2 failed | 7 passed (9)
```

With the fix: 9 passed. Each token reset is covered: without the reset
in `releaseUnusedDeviceToken`, `waits for token deletion before
registering a newly enabled server` fails; without the reset in
`handleTokenRolled`, the new test and `ignores repeated device token
events and events caused by an active sync` fail.

`pnpm exec turbo run typecheck test lint lint:type-aware --continue
--filter=@bb/mobile`: 8 tasks successful, 49 test files and 360 tests
passed, lint 0 errors (6 existing warnings in other files),
lint:type-aware 0 warnings.

Fixes #8224

> AGENT GENERATED
scowalt pushed a commit to scowalt/bb that referenced this pull request Dec 1, 2026
## Human comments

## What was wrong

Each app resume runs two push syncs: the AppState `active` handler (it
also reads the OS permission, get-bb#2881) and the effect that runs again when
realtime reconnects (`PushNotificationsHost.tsx`). Each sync called
`syncPushRegistration`, which calls `getExpoPushTokenAsync` before it
checks the stored record. That call is always a POST to
`https://exp.host/--/api/v2/push/getExpoPushToken`. The Expo push token
changes only with the device token, and expo-notifications 58.1.8
already sends device token changes to Expo by itself
(`DevicePushTokenAutoRegistration.fx.ts`, turned on by the first
`getExpoPushTokenAsync`). So the phone made 2 exp.host round trips per
resume to learn a token it already had. I confirmed the call pattern
with the real `createPushRegistrationController` and counting fakes
before changing anything (numbers below).

## What changed

- `apps/mobile/src/data/notifications/push-registration-controller.ts`:
the controller keeps the Expo push token for the app process and gives
`syncPushRegistration` that value instead of a new fetch. It drops the
token when the device token rolls (`handleTokenRolled`, after its
existing duplicate check) and when Android releases the device token
(`releaseUnusedDeviceToken`), so the next sync fetches again. Cold start
still fetches once and compares the token with the stored record, as
before. The 24 h re-registration still runs; it re-registers with the
kept token.
- `push-registration-controller.test.ts`: a new test for the resume
pattern and a token roll. Two tests had the old fetch counts. The
permission-revoke test replaced `notifications.getPermission` after the
controller was built; it now uses a permission variable in `setup()` and
also asserts that the profile is unregistered.
- No wire, CLI, server or protocol changes.

Deviation from the issue's idea (check the record age before the fetch,
and set `registeredAt: 0` on a token roll): that also gives 0 fetches
per resume, but it stops the token check at cold start for up to 24 h,
writes the persisted record on every roll, and does not cover the
Android path where the controller releases the device token while other
profiles keep a fresh record. The in-memory token has none of these
gaps. If a token event arrives while a fetch is in flight, the in-flight
result is kept; the Expo push token does not depend on the device token,
so this can only keep the same value.

## How you verified

Before/after with the real controller and counting fakes (script kept
out of the commit):

| Scenario | exp.host token fetches before | after | server registers
before | after |
| --- | --- | --- | --- | --- |
| Cold start | 1 | 1 | 1 | 1 |
| 10 resumes (AppState active + reconnect effect) | 20 | 0 | 0 | 0 |
| Device token roll, then one sync | 2 | 1 | 0 | 0 |

New test `fetches the Expo push token once per device token, not on
every resume sync`, run against the unfixed controller:

```
FAIL coalesces concurrent syncs for one profile into one in-flight run plus a trailing run
FAIL fetches the Expo push token once per device token, not on every resume sync
AssertionError: expected "vi.fn()" to be called once, but got 2 times
AssertionError: expected "vi.fn()" to be called once, but got 4 times
Tests  2 failed | 7 passed (9)
```

With the fix: 9 passed. Each token reset is covered: without the reset
in `releaseUnusedDeviceToken`, `waits for token deletion before
registering a newly enabled server` fails; without the reset in
`handleTokenRolled`, the new test and `ignores repeated device token
events and events caused by an active sync` fail.

`pnpm exec turbo run typecheck test lint lint:type-aware --continue
--filter=@bb/mobile`: 8 tasks successful, 49 test files and 360 tests
passed, lint 0 errors (6 existing warnings in other files),
lint:type-aware 0 warnings.

Fixes get-bb#8224

> AGENT GENERATED
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.

1 participant