Repository navigation
iOS push notifications: APNs registration, enriched alerts, deep links - #40
Conversation
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]>
There was a problem hiding this comment.
💡 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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThis PR adds iOS push notification support: APNs registration, notification sync, deep-link routing, a Notification Service extension, app wiring, project/signing updates, and tests. ChangesApple Push Notification Feature
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
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)
Estimated code review effort: 4 (Complex) | ~60 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
iosApp/Tests/ApplePushRegistrationTests.swift (2)
56-86: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCoverage gap:
reason_flagsandread_atnot asserted.The response payload includes
reason_flagsand anullread_at, but the test only checksid,profileId,nextCursor, andunreadCount. Consider asserting onreadAtbeing 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 winConsider 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 multipletry XCTUnwrapcalls. SinceXCTUnwrapthrows 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
📒 Files selected for processing (16)
iosApp/NotificationService/Info.plistiosApp/NotificationService/NotificationService.entitlementsiosApp/NotificationService/NotificationService.personal.entitlementsiosApp/NotificationService/NotificationService.swiftiosApp/Signing/Local.xcconfig.sampleiosApp/Signing/SiloNotificationService.xcconfigiosApp/Silo.entitlementsiosApp/Tests/ApplePushRegistrationTests.swiftiosApp/iosApp/ContentView.swiftiosApp/iosApp/Info.plistiosApp/iosApp/Notifications/ApplePushDeepLinkCoordinator.swiftiosApp/iosApp/Notifications/ApplePushDisplayMetadata.swiftiosApp/iosApp/Notifications/ApplePushNotificationSync.swiftiosApp/iosApp/Notifications/ApplePushRegistration.swiftiosApp/iosApp/Notifications/SiloAppDelegate+Push.swiftiosApp/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]>
…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]>
What
End-to-end APNs push support for the iOS app:
Notifications/ApplePushRegistration.swift): requests notification authorization once a server+profile is active, registers the device token withPOST /api/v1/devices/push/apple, dedupes by a server|profile|token fingerprint, and tolerates older servers (404/405 → marked unsupported for that context). The reportedapns_environmentis parsed from the embedded provisioning profile'saps-environmententitlement at runtime rather than#if DEBUG, so the CI sideload IPAs re-signed with development profiles register sandbox tokens as sandbox.NotificationService/, newSiloNotificationServicetarget): enriches the generic APNs alert with display metadata fromGET /api/v1/notifications/push/apple/display/{delivery_id}, authenticated with the App Group + shared-keychain mirrored credentials — includingX-Profile-Token, which PIN-protected profiles require. Handler state isNSLock-guarded so the system content handler is invoked exactly once even when the fetch racesserviceExtensionTimeWillExpire. Requests use a dedicated 4s/5s-timeout ephemeral session; failures fall back to the generic alert.Notifications/ApplePushDeepLinkCoordinator.swift): notification taps map the payload'ssilo_urltocontinuum://URLs through the existing.continuumDeepLinkchannel, with a pending buffer for cold launches. Routes are forwarded without an allowlist —ContentView.handleDeepLinkstays the single owner of route validity.Notifications/ApplePushNotificationSync.swift): push wakes trigger a cursor-basedGET /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.aps-environmententitlement driven by a per-configAPS_ENVIRONMENTbuild setting (Debug=development, Release=production); new extension xcconfig follows the existing team-default +Local.xcconfigoverride pattern;.personal.entitlementsvariants and updatedLocal.xcconfig.samplekeep 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
(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/ApplePushRegistrationTests.swift(XCTest, 10 cases) covers wire encoding, provisioning-profile parsing, sync/display decoding, and deep-link mapping. iOS build green (Siloscheme, iPhone 17 Pro sim); tvOS/macOS untouched (all new app code is#if os(iOS)).xcodegen generateafter checkout —project.ymladds the extension target.🤖 Generated with Claude Code
Summary by CodeRabbit