Skip to content

iOS push notifications: APNs registration, enriched alerts, deep links - #40

Merged
Quick104 merged 3 commits into
mainfrom
feat/push-notifications
Jul 1, 2026
Merged

Quick104 merged 3 commits into
mainfrom
feat/push-notifications

Conversation

@Quick104

@Quick104 Quick104 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

What

End-to-end APNs push support for the iOS app:

  • Registration (Notifications/ApplePushRegistration.swift): requests notification authorization once a server+profile is active, registers the device token with POST /api/v1/devices/push/apple, dedupes by a server|profile|token fingerprint, and tolerates older servers (404/405 → marked unsupported for that context). The reported apns_environment is parsed from the embedded provisioning profile's aps-environment entitlement at runtime rather than #if DEBUG, so the CI sideload IPAs re-signed with development profiles register sandbox tokens as sandbox.
  • Notification Service extension (NotificationService/, new SiloNotificationService target): enriches the generic APNs alert with display metadata from GET /api/v1/notifications/push/apple/display/{delivery_id}, authenticated with the App Group + shared-keychain mirrored credentials — including X-Profile-Token, which PIN-protected profiles require. Handler state is NSLock-guarded so the system content handler is invoked exactly once even when the fetch races serviceExtensionTimeWillExpire. Requests use a dedicated 4s/5s-timeout ephemeral session; failures fall back to the generic alert.
  • Deep links (Notifications/ApplePushDeepLinkCoordinator.swift): notification taps map the payload's silo_url to continuum:// URLs through the existing .continuumDeepLink channel, with a pending buffer for cold launches. Routes are forwarded without an allowlist — ContentView.handleDeepLink stays the single owner of route validity.
  • Inbox sync (Notifications/ApplePushNotificationSync.swift): push wakes trigger a cursor-based GET /api/v1/notifications/sync; the cursor is scoped per server+profile so switching contexts can't skip notifications. None of the delegate callbacks block on the network: banners present immediately, taps navigate before syncing, and background wakes race the sync against a 15s deadline so the completion handler always lands inside the ~30s system budget.
  • Signing/config: aps-environment entitlement driven by a per-config APS_ENVIRONMENT build setting (Debug=development, Release=production); new extension xcconfig follows the existing team-default + Local.xcconfig override pattern; .personal.entitlements variants and updated Local.xcconfig.sample keep the Personal Team workflow signable (push is unavailable there and fails gracefully).

Why

Server-side notification delivery (relay + push_devices + display endpoint) already exists in silo-server; this adds the iOS client half so users get enriched, tappable alerts for new content.

Reviewer notes

  • A high-effort multi-agent code review ran on this diff; all confirmed findings are fixed in this branch (blocking delegate callbacks, PIN-profile 403 on enrichment, APNs environment mismatch on re-signed builds, extension content-handler race, cross-context sync cursor, personal-team signing gap, XCTest convention, deep-link allowlist drift).
  • Two gaps need silo-server coordination and are tracked separately: no deregistration endpoint (sign-out/profile-switch leaves the device registered — the server upserts per (profile_id, device_id)), and the extension's mirrored access token expires ~8h after the app last ran, after which enrichment falls back to the generic alert until the app is opened.
  • Tests: Tests/ApplePushRegistrationTests.swift (XCTest, 10 cases) covers wire encoding, provisioning-profile parsing, sync/display decoding, and deep-link mapping. iOS build green (Silo scheme, iPhone 17 Pro sim); tvOS/macOS untouched (all new app code is #if os(iOS)).
  • Run xcodegen generate after checkout — project.yml adds the extension target.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added an iOS Notification Service Extension for enriching incoming push content.
    • Introduced coordinated push registration, notification sync after background wake, and push-driven deep-link routing.
  • Bug Fixes
    • Improved deep-link queue consumption so taps and launches route consistently.
    • Added safer time-expiry handling during notification enrichment and sync.
  • Documentation
    • Expanded iOS signing guidance for the extension and entitlements.
  • Tests
    • Added coverage for push registration, deep-link parsing, notification sync, and push display decoding.

Adds iOS push notification support end to end:

- APNs registration coordinator that requests authorization once a
  server+profile is active, dedupes registrations by fingerprint, and
  reports the APNs environment parsed from the embedded provisioning
  profile (not #if DEBUG), so re-signed sideload builds register the
  environment they were actually signed for.
- Notification Service extension that enriches generic alerts with
  compact display metadata fetched from the Silo server using the
  App Group + shared keychain mirrored credentials (including the
  profile token, required for PIN-protected profiles). Handler state is
  lock-guarded so the content handler fires exactly once even when the
  fetch races the expiration deadline.
- Notification tap deep links (continuum://item|play routes are owned
  by ContentView; the coordinator forwards routes without a second
  allowlist) with a pending buffer for cold launches.
- Inbox sync on push wakes, cursor-scoped per server+profile. Delegate
  callbacks never block on the network: banners present immediately,
  taps navigate before syncing, and background wakes race the sync
  against a 15s deadline to stay inside the system budget.
- Personal-team signing variants and Local.xcconfig.sample docs for the
  new extension target.

Known server-side follow-ups (tracked separately): a deregistration
endpoint so sign-out/profile-switch can silence a device, and a
longer-lived scoped credential so extension enrichment survives access
token expiry.

Co-Authored-By: Claude Fable 5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 81f6ba1434

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

A background remote-notification wake of a killed app can run the
notification sync before ContentView.checkInitialState() points
TokenStore at the active registry server, so HTTPClient sent the sync
unauthenticated and it 401ed. Retarget from ServerRegistry first; the
call is an idempotent no-op on every subsequent sync.

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e70575c7-0a8a-47ea-81f2-cd7266f23222

📥 Commits

Reviewing files that changed from the base of the PR and between b721b2d and 2b6a1f7.

📒 Files selected for processing (3)
  • iosApp/Tests/ApplePushRegistrationTests.swift
  • iosApp/iosApp/Notifications/ApplePushNotificationSync.swift
  • iosApp/iosApp/Notifications/ApplePushRegistration.swift
🚧 Files skipped from review as they are similar to previous changes (3)
  • iosApp/iosApp/Notifications/ApplePushNotificationSync.swift
  • iosApp/Tests/ApplePushRegistrationTests.swift
  • iosApp/iosApp/Notifications/ApplePushRegistration.swift

📝 Walkthrough

Walkthrough

This PR adds iOS push notification support: APNs registration, notification sync, deep-link routing, a Notification Service extension, app wiring, project/signing updates, and tests.

Changes

Apple Push Notification Feature

Layer / File(s) Summary
APNs registration coordinator
iosApp/iosApp/Notifications/ApplePushRegistration.swift, iosApp/Tests/ApplePushRegistrationTests.swift
Adds wire models, provisioning-profile APNs environment parsing, registration gating and deduplication, plus tests for token formatting, topic selection, and environment extraction.
Push display metadata and enrichment client
iosApp/iosApp/Notifications/ApplePushDisplayMetadata.swift
Defines the display response model, auth state, wire helpers, state reader, and async client used to fetch and apply enriched notification content.
Notification Service extension
iosApp/NotificationService/NotificationService.swift, iosApp/NotificationService/Info.plist, iosApp/NotificationService/*.entitlements
Implements the notification service extension and adds its plist and entitlements for extension registration, App Groups, and shared keychain access.
Remote notification sync coordinator
iosApp/iosApp/Notifications/ApplePushNotificationSync.swift, iosApp/Tests/ApplePushRegistrationTests.swift
Adds sync response models and a coordinator that fetches notification updates after remote wakes, with tests covering sync query construction and decoding.
Deep link coordinator
iosApp/iosApp/Notifications/ApplePushDeepLinkCoordinator.swift, iosApp/Tests/ApplePushRegistrationTests.swift
Adds a singleton that extracts, stores, posts, consumes, and clears continuum:// deep links, with tests for push/display URL mapping.
App delegate push wiring
iosApp/iosApp/Notifications/SiloAppDelegate+Push.swift, iosApp/iosApp/ContentView.swift
Extends app lifecycle and notification handling to forward registration events, sync remote notifications, post deep links, and consume pending links in the UI.
Project, signing, and entitlements configuration
iosApp/project.yml, iosApp/Signing/SiloNotificationService.xcconfig, iosApp/Signing/Local.xcconfig.sample, iosApp/Silo.entitlements, iosApp/iosApp/Info.plist
Adds the notification service target, signing defaults, local override documentation, APS/app-group entitlements, and the remote-notification background mode.
Unit tests
iosApp/Tests/ApplePushRegistrationTests.swift
Adds coverage for push registration, sync decoding, display mutation, and deep-link routing helpers.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant APNs
  participant SiloAppDelegate
  participant ApplePushRegistrationCoordinator
  participant Backend

  APNs->>SiloAppDelegate: didRegisterForRemoteNotificationsWithDeviceToken
  SiloAppDelegate->>ApplePushRegistrationCoordinator: registerCurrentDeviceTokenIfPossible()
  ApplePushRegistrationCoordinator->>Backend: POST registration payload
  Backend-->>ApplePushRegistrationCoordinator: success / 404/405 / error

  APNs->>SiloAppDelegate: didReceiveRemoteNotification
  SiloAppDelegate->>SiloAppDelegate: syncWithDeadline()
  SiloAppDelegate->>ApplePushNotificationSyncCoordinator: refreshFromRemoteNotification()
  ApplePushNotificationSyncCoordinator->>Backend: GET /api/v1/notifications/sync
  Backend-->>ApplePushNotificationSyncCoordinator: sync response
Loading
sequenceDiagram
  participant APNs
  participant NotificationService
  participant ApplePushDisplayClient
  participant Backend

  APNs->>NotificationService: didReceive(request, contentHandler)
  NotificationService->>ApplePushDisplayClient: fetchDisplay(deliveryID)
  ApplePushDisplayClient->>Backend: GET push display endpoint
  Backend-->>ApplePushDisplayClient: ApplePushDisplayResponse
  ApplePushDisplayClient-->>NotificationService: enriched content
  NotificationService->>NotificationService: complete(with: enrichedContent)
Loading

Estimated code review effort: 4 (Complex) | ~60 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main iOS push notification work: APNs registration, notification enrichment, and deep-link handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/push-notifications

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
iosApp/Tests/ApplePushRegistrationTests.swift (2)

56-86: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Coverage gap: reason_flags and read_at not asserted.

The response payload includes reason_flags and a null read_at, but the test only checks id, profileId, nextCursor, and unreadCount. Consider asserting on readAt being nil and on the decoded reason flags to confirm those fields round-trip correctly, since they're explicitly included in the fixture.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@iosApp/Tests/ApplePushRegistrationTests.swift` around lines 56 - 86, The
ApplePushNotificationSyncResponse decoding test is missing assertions for fields
already present in the fixture. Update
testNotificationSyncResponseDecodesSnakeCasePayload in
ApplePushRegistrationTests to verify the decoded notification’s readAt is nil
and that reasonFlags is parsed correctly from reason_flags, alongside the
existing checks for id, profileId, nextCursor, and unreadCount.

130-156: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider splitting into focused test methods.

This single test bundles five distinct scenarios (item URL, absolute URL, passthrough of existing continuum:// URL, unvalidated forwarding, and two nil cases) using multiple try XCTUnwrap calls. Since XCTUnwrap throws and aborts the test on failure, an early failure (e.g., in the item-URL case) hides results for all subsequent assertions in the same run, reducing diagnostic value.

Splitting into per-scenario test methods would give independent pass/fail signals for each case.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@iosApp/Tests/ApplePushRegistrationTests.swift` around lines 130 - 156, The
test method ApplePushDeepLinkCoordinator.deepLinkURL(fromDisplayURL:) currently
combines several unrelated scenarios, which makes failures harder to diagnose
because XCTUnwrap stops the whole test early. Split
testNotificationDisplayURLMapsToAppDeepLink into focused test methods for each
case (item URL mapping, absolute URL mapping, existing continuum:// passthrough,
unvalidated forwarding, and nil inputs) so each assertion set runs independently
and reports its own result.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@iosApp/iosApp/Notifications/ApplePushNotificationSync.swift`:
- Around line 49-78: The sync flow in ApplePushNotificationSync’s push handling
path sets inFlight too late, allowing re-entrant calls before the first await.
Move the inFlight = true assignment to before the retargetActiveServer call in
the method that builds the server/profile context, so the guard can block
concurrent sync attempts and cursor updates stay serialized.

In `@iosApp/iosApp/Notifications/ApplePushRegistration.swift`:
- Around line 140-146: Gate cached token uploads in
registerCurrentDeviceTokenIfPossible on current notification authorization,
since it can still upload lastDeviceToken even when notifications are denied.
Update ApplePushRegistration.registerCurrentDeviceTokenIfPossible to check the
current authorization status before sending any cached token, and return early
unless permissions allow registration. Keep the existing
AuthService.shared.hasServer and hasProfile checks, but add the authorization
guard alongside them so ContentView’s foreground call cannot re-upload a token
after prepareForAuthenticatedProfile() has bailed out.

---

Nitpick comments:
In `@iosApp/Tests/ApplePushRegistrationTests.swift`:
- Around line 56-86: The ApplePushNotificationSyncResponse decoding test is
missing assertions for fields already present in the fixture. Update
testNotificationSyncResponseDecodesSnakeCasePayload in
ApplePushRegistrationTests to verify the decoded notification’s readAt is nil
and that reasonFlags is parsed correctly from reason_flags, alongside the
existing checks for id, profileId, nextCursor, and unreadCount.
- Around line 130-156: The test method
ApplePushDeepLinkCoordinator.deepLinkURL(fromDisplayURL:) currently combines
several unrelated scenarios, which makes failures harder to diagnose because
XCTUnwrap stops the whole test early. Split
testNotificationDisplayURLMapsToAppDeepLink into focused test methods for each
case (item URL mapping, absolute URL mapping, existing continuum:// passthrough,
unvalidated forwarding, and nil inputs) so each assertion set runs independently
and reports its own result.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f971e70-051c-41f4-990f-cd4fa4cfbadc

📥 Commits

Reviewing files that changed from the base of the PR and between c240713 and b721b2d.

📒 Files selected for processing (16)
  • iosApp/NotificationService/Info.plist
  • iosApp/NotificationService/NotificationService.entitlements
  • iosApp/NotificationService/NotificationService.personal.entitlements
  • iosApp/NotificationService/NotificationService.swift
  • iosApp/Signing/Local.xcconfig.sample
  • iosApp/Signing/SiloNotificationService.xcconfig
  • iosApp/Silo.entitlements
  • iosApp/Tests/ApplePushRegistrationTests.swift
  • iosApp/iosApp/ContentView.swift
  • iosApp/iosApp/Info.plist
  • iosApp/iosApp/Notifications/ApplePushDeepLinkCoordinator.swift
  • iosApp/iosApp/Notifications/ApplePushDisplayMetadata.swift
  • iosApp/iosApp/Notifications/ApplePushNotificationSync.swift
  • iosApp/iosApp/Notifications/ApplePushRegistration.swift
  • iosApp/iosApp/Notifications/SiloAppDelegate+Push.swift
  • iosApp/project.yml

… authorization

The TokenStore retarget added a suspension point before inFlight was
claimed, so a second push/foreground/tap sync could re-enter and race
the cursor bookkeeping — claim the flag before the first await.

registerCurrentDeviceTokenIfPossible could re-upload the cached device
token after the user revoked notification authorization in Settings
(e.g. on foreground after a profile switch); it now checks the current
authorization status before posting.

Also assert createdAt/readAt round-trip in the sync decoding test.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Quick104
Quick104 merged commit 3658e6b into main Jul 1, 2026
1 check passed
@Quick104
Quick104 deleted the feat/push-notifications branch July 1, 2026 21:20
Quick104 added a commit that referenced this pull request Jul 2, 2026
…nsions

The push-notification (#40) and offline-downloads (#41) PRs added two
embedded app extensions, but the beta_ios lane still fetched only the main
app's profile and forced it onto every target via a global
PROVISIONING_PROFILE_SPECIFIER xcarg, failing the archive step with a
bundle-ID mismatch.

- match now syncs profiles for the app and both extensions
- per-target signing via update_code_signing_settings + export_options
  provisioningProfiles mapping (same pattern as the tvOS Top Shelf lane)
- Matchfile identifier list includes both extension IDs
- new sync_signing lane for read-write local profile generation

Co-Authored-By: Claude Fable 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.

1 participant