Skip to content

feat(push): handle relay silo_delivery_id and silo_mode data keys - #71

Merged
Quick104 merged 1 commit into
mainfrom
feat/relay-fcm-data-keys
Jul 14, 2026
Merged

Quick104 merged 1 commit into
mainfrom
feat/relay-fcm-data-keys

Conversation

@Quick104

@Quick104 Quick104 commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Silo push relay's FCM payload is a fixed content-private data message carrying exactly silo_delivery_id and silo_mode. The existing PushMessageHandler only looked for delivery_id-style keys and ignored mode entirely, so relay pushes would have been dropped.

  • silo_delivery_id is now the primary delivery-id key (legacy delivery_id/deliveryId/id remain as fallbacks).
  • silo_mode=background_wake triggers a silent inbox refresh (PushNotificationPresenter.sync()) instead of posting a visible notification; private_alert (or absent mode) keeps the existing fetch-then-present flow.
  • AndroidPushSourceTest now pins the relay contract keys.

Pairs with the server PR that enables FCM delivery (Silo-Server/silo-server feat/android-fcm-push) and the already-deployed relay /v1/fcm/send endpoint. 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

    • Added support for background wake messages that refresh the notifications inbox without displaying a notification.
    • Expanded message delivery ID recognition to support additional relay payload formats.
  • Bug Fixes

    • Background notification synchronization now safely handles refresh failures without interrupting message processing.
  • Tests

    • Added coverage for the new background wake and delivery payload fields.

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

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds background wake push handling that refreshes the notifications inbox silently, recognizes silo_delivery_id, and verifies required relay payload keys in Android push source tests.

Changes

Background wake synchronization

Layer / File(s) Summary
Background wake handling and inbox refresh
androidApp/src/androidMain/kotlin/org/siloserver/silo/android/push/PushNotificationPresenter.kt, androidApp/src/androidMain/kotlin/org/siloserver/silo/android/push/SiloFirebaseMessagingService.kt, androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/push/AndroidPushSourceTest.kt
Adds silent notification refresh for background_wake messages, supports silo_delivery_id alongside legacy delivery keys, and asserts the required relay payload fields.

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
Loading

Possibly related issues

  • Silo-Server/silo-android#19 — Covers Android push delivery, background inbox synchronization, and notification handling addressed by this change.

Suggested reviewers: rxwatcher

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately highlights the main push-handling change around silo_delivery_id and silo_mode keys.
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/relay-fcm-data-keys

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

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 30b2536 and 4b5d2c4.

📒 Files selected for processing (3)
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/push/PushNotificationPresenter.kt
  • androidApp/src/androidMain/kotlin/org/siloserver/silo/android/push/SiloFirebaseMessagingService.kt
  • androidApp/src/androidUnitTest/kotlin/org/siloserver/silo/android/push/AndroidPushSourceTest.kt

Comment on lines +66 to +70
// sync refreshes the inbox for a background_wake push without posting a
// visible notification.
suspend fun sync() {
runCatching { notificationsRepository.refresh() }
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n -C 3 'runCatching|CancellationException|fun sync|presenter\.sync\(\)' \
  androidApp/src/androidMain/kotlin

Repository: 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.kt

Repository: 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'
done

Repository: 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 || true

Repository: 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 || true

Repository: 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.

Comment on lines +39 to +42
// 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"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

@Quick104
Quick104 merged commit 3adcba7 into main Jul 14, 2026
2 checks passed
@Quick104
Quick104 deleted the feat/relay-fcm-data-keys branch July 14, 2026 17:44
Quick104 added a commit that referenced this pull request Jul 25, 2026
…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]>
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