Skip to content

Add a built-in push notifications plugin and the interaction.pending plugin event - #2872

Merged
SawyerHood merged 21 commits into
mainfrom
bb/add-mobile-push-notifications-thr_nuee4d9q4w
Sep 2, 2026
Merged

SawyerHood merged 21 commits into
mainfrom
bb/add-mobile-push-notifications-thr_nuee4d9q4w

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Sep 1, 2026 •

Copy link
Copy Markdown
Collaborator

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

SawyerHood and others added 7 commits September 2, 2026 00:03
The settings test that main added renders GeneralSettingsSection with explicit
props and needed the push notification ones. The plugin SDK root bundle now
carries the notifications SDK area, so the Plugin Guide inventory hash moved.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@SawyerHood SawyerHood changed the title Add server-side mobile push notifications via Expo Add a built-in push notifications plugin and the interaction.pending plugin event Sep 2, 2026
@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
…tifications-thr_nuee4d9q4w

# Conflicts:
#	apps/server/test/services/plugins/official-plugins.test.ts
#	packages/plugin-api-map/sdk-public-api.json
Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit 147feae)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit ac81bf9)
@SawyerHood
SawyerHood merged commit af92a90 into main Sep 2, 2026
15 checks passed
@SawyerHood
SawyerHood deleted the bb/add-mobile-push-notifications-thr_nuee4d9q4w branch September 2, 2026 16:42
SawyerHood added a commit that referenced this pull request Sep 2, 2026
## 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

---------

Co-authored-by: Claude Fable 5.1 <[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.

1 participant