Repository navigation
feat(push): handle relay silo_delivery_id and silo_mode data keys - #71
Conversation
The Silo push relay's content-private FCM payload carries exactly silo_delivery_id and silo_mode. Read silo_delivery_id first (legacy keys stay as fallbacks) and treat silo_mode=background_wake as a silent inbox sync instead of posting a visible notification. Co-Authored-By: Claude Fable 5 <[email protected]>
📝 WalkthroughWalkthroughAdds background wake push handling that refreshes the notifications inbox silently, recognizes ChangesBackground wake synchronization
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant SiloFirebaseMessagingService
participant PushMessageHandler
participant PushNotificationPresenter
participant notificationsRepository
SiloFirebaseMessagingService->>PushMessageHandler: Handle background_wake payload
PushMessageHandler->>PushNotificationPresenter: Call sync()
PushNotificationPresenter->>notificationsRepository: Refresh notifications
PushMessageHandler-->>SiloFirebaseMessagingService: Return true without visible notification
Possibly related issues
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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
`@androidApp/src/androidMain/kotlin/org/siloserver/silo/android/push/PushNotificationPresenter.kt`:
- Around line 66-70: Update PushNotificationPresenter.sync() so coroutine
CancellationException from notificationsRepository.refresh() is rethrown rather
than swallowed by runCatching. Catch only the expected refresh failure types,
preserving cancellation propagation while retaining the existing handling for
those failures.
In
`@androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/push/AndroidPushSourceTest.kt`:
- Around line 39-42: Replace the comment-dependent key-presence assertions in
AndroidPushSourceTest with behavioral tests through PushMessageHandler: verify
background_wake triggers sync() without present(), and verify silo_delivery_id
is selected ahead of legacy delivery-id keys.
🪄 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: 3a3e8726-91e5-46d3-aa4c-bcec460f3fcf
📒 Files selected for processing (3)
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/push/PushNotificationPresenter.ktandroidApp/src/androidMain/kotlin/org/siloserver/silo/android/push/SiloFirebaseMessagingService.ktandroidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/push/AndroidPushSourceTest.kt
| // sync refreshes the inbox for a background_wake push without posting a | ||
| // visible notification. | ||
| suspend fun sync() { | ||
| runCatching { notificationsRepository.refresh() } | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -n -C 3 'runCatching|CancellationException|fun sync|presenter\.sync\(\)' \
androidApp/src/androidMain/kotlinRepository: Silo-Server/silo-android
Length of output: 50380
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== PushNotificationPresenter.kt ==\n'
sed -n '1,220p' androidApp/src/androidMain/kotlin/org/siloserver/silo/android/push/PushNotificationPresenter.kt
printf '\n== SiloFirebaseMessagingService.kt ==\n'
sed -n '1,140p' androidApp/src/androidMain/kotlin/org/siloserver/silo/android/push/SiloFirebaseMessagingService.ktRepository: Silo-Server/silo-android
Length of output: 9501
🏁 Script executed:
#!/bin/bash
set -euo pipefail
for f in \
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/push/PushNotificationPresenter.kt \
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/push/SiloFirebaseMessagingService.kt
do
echo "===== $f ====="
nl -ba "$f" | sed -n '1,220p'
doneRepository: Silo-Server/silo-android
Length of output: 310
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== NotificationsRepository.refresh definitions =="
rg -n -C 3 'suspend fun refresh\(' androidApp/src/androidMain/kotlin org || true
echo
echo "== sync() call sites =="
rg -n -C 2 '\.sync\(\)' androidApp/src/androidMain/kotlin || trueRepository: Silo-Server/silo-android
Length of output: 996
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== NotificationsRepository.refresh definitions =="
rg -n -C 3 'suspend fun refresh\(' androidApp/src/androidMain/kotlin || true
echo
echo "== sync() call sites =="
rg -n -C 2 '\.sync\(\)' androidApp/src/androidMain/kotlin || trueRepository: Silo-Server/silo-android
Length of output: 952
Preserve coroutine cancellation in sync()
runCatching swallows CancellationException, so a cancelled refresh is treated as success. Re-throw cancellation and only catch the refresh failures you expect.
🤖 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
`@androidApp/src/androidMain/kotlin/org/siloserver/silo/android/push/PushNotificationPresenter.kt`
around lines 66 - 70, Update PushNotificationPresenter.sync() so coroutine
CancellationException from notificationsRepository.refresh() is rethrown rather
than swallowed by runCatching. Catch only the expected refresh failure types,
preserving cancellation propagation while retaining the existing handling for
those failures.
| // The relay's fixed content-private data payload carries exactly these keys. | ||
| assertTrue(service.contains("silo_delivery_id")) | ||
| assertTrue(service.contains("silo_mode")) | ||
| assertTrue(service.contains("background_wake")) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Test runtime behavior instead of comment text.
These assertions pass even if the implementation is removed because the checked strings also appear in SiloFirebaseMessagingService.kt comments. Add a behavioral PushMessageHandler test that verifies background_wake invokes sync() without present(), and that silo_delivery_id takes precedence over legacy keys.
🤖 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
`@androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/push/AndroidPushSourceTest.kt`
around lines 39 - 42, Replace the comment-dependent key-presence assertions in
AndroidPushSourceTest with behavioral tests through PushMessageHandler: verify
background_wake triggers sync() without present(), and verify silo_delivery_id
is selected ahead of legacy delivery-id keys.
…ice (#100) (#100) Data-only pushes register in `private_push` mode, so the relay sends only `silo_delivery_id` — every word of user-visible text comes from the `GET /api/v1/notifications/{id}` lookup the client makes on receipt. When that lookup didn't finish, the notification fell back to "Silo notification" / "Open Silo to view it.", which is what users saw intermittently. `onMessageReceived` only *launched* that lookup on a service-scoped coroutine and returned. FCM's `EnhancedIntentService` completes the wakeful intent and calls `stopSelf()` the instant the callback returns (verified against firebase-messaging 25.1.0 bytecode), so `onDestroy` cancelled the scope mid-request. The cancellation was invisible: `safeApiCall` catches `Exception`, and JVM `CancellationException` is one, so the aborted call came back as a plain `NetworkError`. Everything after the fetch is non-suspending, so the notification still posted — just with the generic strings. Whether the request beat `stopSelf` came down to connection warmth, which is why it looked random. Run both callbacks inline instead. They execute on FCM's own intent-handling executor, never the main thread, so blocking there is the documented contract. `onNewToken` had the same bug and silently dropped token re-registration. - `PUSH_WORK_BUDGET_MS` (8s) bounds each network call. That executor is single-threaded (`FcmExecutors.newIntentHandleExecutor`), so deliveries in a burst queue head-to-tail and a callback must give the thread back promptly. Deliberately under the shared client's 10s connect timeout: a server we haven't connected to by then can't help us inside the window either. - `withinPushBudget` rethrows `CancellationException` ahead of its broad catch, matching the convention in the shared repositories and addressing review feedback on #71 that was never applied. Follow-up, deliberately not folded in: `safeApiCall` swallowing `CancellationException` breaks structured concurrency for ~179 call sites app-wide and deserves its own change. Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Summary
The Silo push relay's FCM payload is a fixed content-private data message carrying exactly
silo_delivery_idandsilo_mode. The existingPushMessageHandleronly looked fordelivery_id-style keys and ignored mode entirely, so relay pushes would have been dropped.silo_delivery_idis now the primary delivery-id key (legacydelivery_id/deliveryId/idremain as fallbacks).silo_mode=background_waketriggers a silent inbox refresh (PushNotificationPresenter.sync()) instead of posting a visible notification;private_alert(or absent mode) keeps the existing fetch-then-present flow.AndroidPushSourceTestnow pins the relay contract keys.Pairs with the server PR that enables FCM delivery (
Silo-Server/silo-serverfeat/android-fcm-push) and the already-deployed relay/v1/fcm/sendendpoint. No registration, manifest, DI, or permission changes needed — that wiring already existed.Commands run
./gradlew :androidApp:testDebugUnitTest :shared:testDebugUnitTest(BUILD SUCCESSFUL)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests