Skip to content

feat(notifications): add Android FCM push delivery via the relay - #409

Merged
Quick104 merged 1 commit into
mainfrom
feat/android-fcm-push
Jul 14, 2026
Merged

Quick104 merged 1 commit into
mainfrom
feat/android-fcm-push

Conversation

@Quick104

@Quick104 Quick104 commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds Android push delivery through the Silo push relay's new POST /v1/fcm/send endpoint (deployed at push.siloserver.org), reusing the existing Apple pipeline end to end: same outbox, dispatcher, retry schedule, idempotency keys, credential renewal, and terminal-device pruning.

  • Schema (20260714160000_push_devices_android.sql): push_devices gains nullable fcm_token_ciphertext / fcm_token_hash; the platform CHECKs on push_devices and push_delivery_attempts now allow 'android', and the old apple_fields_check becomes a platform-conditional exclusivity constraint.
  • Registration: new profile-scoped POST /notifications/push/devices (the contract the Android client already ships with) plus DELETE /notifications/push/devices/{device_id}. FCM tokens are validated ([A-Za-z0-9_:-]{64,512}), encrypted at rest with per-row AAD, and hashed case-sensitively.
  • Delivery: fanout and operational dispatch enqueue attempts for every admin-enabled platform; the sender picks /v1/apple/send or /v1/fcm/send per device. A relay 422 fcm_rejected with reason UNREGISTERED disables the device (mirrors the conservative APNs list); INVALID_ARGUMENT stays request-level.
  • Config: new notifications.android_push_delivery_enabled setting (default off, validated in admin settings), surfaced via the capability endpoint's android_push block, same relay credential as Apple.
  • Admin: POST /admin/notifications/push/fcm/test mirrors the Apple test endpoint.

Privacy / delivery risks

  • The FCM payload is built by the relay and stays content-private (data-only, delivery ID + mode); this server still sends only the opaque IDs it already sent for Apple.
  • FCM tokens follow the exact APNs token handling: encrypted at rest, hashed for lookups, never logged.
  • Ambiguous relay outcomes remain delivery-unknown via the shared idempotency handling; nothing is resent on 409.

Request/response examples

Register (Android client, profile-scoped):

POST /api/v1/notifications/push/devices
{"platform":"android","token":"<fcm-token>","device_id":"<install-id>","push_mode":"private_push"}
→ 200 {"id":"01J...","server_device_id":"01J...","enabled":true,"push_mode":"private_push"}

Relay send (server → relay):

POST /v1/fcm/send  (Idempotency-Key: <attempt-id>)
{"token":"<fcm-token>","mode":"private_alert","server_device_id":"01J...","delivery_id":"01J...","collapse_id":"01J..."}
→ 200 {"request_id":"...","fcm_message_id":"...","status":"accepted"}

Commands run

  • GOWORK=off go build ./internal/... ./cmd/...
  • GOWORK=off go vet ./internal/notifications/... ./internal/api/...
  • GOWORK=off go test ./internal/... (all pass; DB-backed tests skip without SILO_TEST_DATABASE_URL)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added Android push notification support using FCM, including device registration and removal.
    • Added Android push capability reporting and configurable delivery enablement.
    • Added admin tools for sending Android test notifications.
    • Enabled notification delivery across Apple and Android devices.
  • Bug Fixes
    • Improved platform-specific validation and error messages for push settings and delivery failures.

Extend the push pipeline to Android devices through the Silo push
relay's /v1/fcm/send endpoint. push_devices gains platform-conditional
FCM token columns (encrypted at rest with row AAD, hashed like APNs
tokens), the generic POST /notifications/push/devices endpoint the
Android client already calls registers FCM tokens, and fanout,
operational dispatch, retries, and terminal UNREGISTERED device
disabling all reuse the existing Apple machinery. Delivery is gated by
a new notifications.android_push_delivery_enabled setting, advertised
through the capability endpoint's android_push block, and testable via
POST /admin/notifications/push/fcm/test.

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

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds Android FCM device registration, persistence, capability settings, platform-aware push enqueueing, relay delivery, admin testing, and API coverage while retaining Apple push support.

Changes

Android FCM push support

Layer / File(s) Summary
Platform-aware push storage contracts
migrations/sql/..., internal/notifications/push_devices.go
Schema constraints, encrypted FCM token fields, registration interfaces, and repository operations support Android push devices and platform-specific delivery attempts.
FCM registration and unregistration API
internal/api/handlers/notifications_push_devices.go, internal/api/router.go, internal/notifications/push_devices.go, *_test.go
Android registration and device-scoped unregistration handlers, service methods, routes, validation, and tests are added.
Platform settings and push enqueueing
internal/notifications/settings.go, internal/api/handlers/notifications.go, internal/notifications/fanout_worker.go, internal/notifications/operational_dispatch.go, internal/notifications/push_delivery.go
Enabled Apple and Android platforms drive capability responses, device lookup, and delivery-attempt creation.
Platform-aware relay delivery and admin tests
internal/notifications/push_sender.go, internal/api/handlers/admin_apple_push.go, internal/api/router.go, *_test.go
The sender selects platform-specific tokens, relay paths, payloads, rejection handling, and admin test flows for Apple and FCM delivery.

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

Possibly related issues

Possibly related PRs

Suggested labels: v1

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% 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 clearly matches the main change: adding Android FCM push delivery through the relay.
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/android-fcm-push

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

@coderabbitai coderabbitai Bot added the v1.0 Silo v1 scope - auto-adds to the Silo v1 project label Jul 14, 2026
@Quick104
Quick104 merged commit a196b08 into main Jul 14, 2026
1 check was pending
@Quick104
Quick104 deleted the feat/android-fcm-push branch July 14, 2026 17:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (8)
internal/api/handlers/notifications.go (1)

390-410: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated capabilityPush construction for Apple/Android.

Both blocks build an identical capabilityPush{Provider: PushProviderSiloRelay, SupportedModes: [...]} literal, differing only by which setting gates them. A shared helper would prevent the two from silently diverging (e.g. supported modes updated for one platform but not the other) as more platforms are added.

♻️ Proposed refactor
-	applePush := capabilityPush{Available: false, Provider: "off", SupportedModes: []string{"in_app_only"}}
-	androidPush := capabilityPush{Available: false, Provider: "off", SupportedModes: []string{"in_app_only"}}
-	if h.system.PushDevices != nil && h.system.PushDevices.Available() {
-		if h.system.Settings.ApplePushDeliveryEnabled(r.Context()) {
-			applePush = capabilityPush{
-				Available:      true,
-				Provider:       notifications.PushProviderSiloRelay,
-				SupportedModes: []string{notifications.PushModePrivatePush, notifications.PushModeInAppOnly},
-			}
-		}
-		if h.system.Settings.AndroidPushDeliveryEnabled(r.Context()) {
-			androidPush = capabilityPush{
-				Available:      true,
-				Provider:       notifications.PushProviderSiloRelay,
-				SupportedModes: []string{notifications.PushModePrivatePush, notifications.PushModeInAppOnly},
-			}
-		}
-	}
+	relayPushCapability := func(enabled bool) capabilityPush {
+		if !enabled {
+			return capabilityPush{Available: false, Provider: "off", SupportedModes: []string{"in_app_only"}}
+		}
+		return capabilityPush{
+			Available:      true,
+			Provider:       notifications.PushProviderSiloRelay,
+			SupportedModes: []string{notifications.PushModePrivatePush, notifications.PushModeInAppOnly},
+		}
+	}
+	devicesWired := h.system.PushDevices != nil && h.system.PushDevices.Available()
+	applePush := relayPushCapability(devicesWired && h.system.Settings.ApplePushDeliveryEnabled(r.Context()))
+	androidPush := relayPushCapability(devicesWired && h.system.Settings.AndroidPushDeliveryEnabled(r.Context()))
🤖 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 `@internal/api/handlers/notifications.go` around lines 390 - 410, Refactor the
Apple and Android branches in the capability construction flow to use a shared
helper for the enabled push capability. Keep the existing per-platform
delivery-toggle checks and disabled defaults unchanged, while centralizing the
identical Provider and SupportedModes values so both platforms cannot diverge.
internal/api/handlers/admin_apple_push.go (1)

68-77: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rename the shared push test types to be platform-neutral
notifications.ApplePushTestResult is now used by both SendApplePushTest and SendAndroidPushTest, so the Apple-specific name is misleading. If the admin request/response structs stay shared too, rename those for consistency.

🤖 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 `@internal/api/handlers/admin_apple_push.go` around lines 68 - 77, Rename
notifications.ApplePushTestResult and the shared admin push test
request/response structs to platform-neutral names, then update
SendApplePushTest, SendAndroidPushTest, AdminApplePushHandler.handleTest,
HandleTestAndroid, and all related references to use the new names consistently.
internal/notifications/push_sender.go (3)

424-438: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Dispatcher labels still say "apple push" despite now handling both platforms.

channel: "apple push" and the logger component notifications.apple_push.dispatch predate this generalization; now that enabled, claimPending, and claimDue cover Android attempts too, logs/metrics for Android push issues will be mislabeled as Apple, complicating triage.

♻️ Suggested rename
 	return &PushDispatcher{core: channelDispatcher[PushDeliveryAttempt]{
-		channel:      "apple push",
+		channel:      "push",
 		queue:        make(chan string, pushDispatchQueue),
-		logger:       slog.Default().With("component", "notifications.apple_push.dispatch"),
+		logger:       slog.Default().With("component", "notifications.push.dispatch"),
🤖 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 `@internal/notifications/push_sender.go` around lines 424 - 438, Update
newPushDispatcher so the dispatcher channel and logger component use
platform-neutral push-delivery labels instead of “apple push” and
“notifications.apple_push.dispatch”; keep the existing dispatcher behavior and
callbacks unchanged.

456-524: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

ApplePushTestResult is now the return type for Android tests too.

SendAndroidPushTest returns *ApplePushTestResult, an Apple-named type with no platform field, making it unclear at the call site (and to future maintainers) which platform a result belongs to.

♻️ Suggested rename
-type ApplePushTestResult struct {
+type PushTestResult struct {
 	AttemptID      string
 	PushDeviceID   string
 	ServerDeviceID string
 	Outcome        string
 	RelayRequestID string
 	UpstreamStatus *int
 	UpstreamReason string
 	FailureMessage string
 }

Rename call sites (SendApplePushTest, SendAndroidPushTest, sendPushTest, and any admin handlers referencing ApplePushTestResult) accordingly.

🤖 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 `@internal/notifications/push_sender.go` around lines 456 - 524, Rename
ApplePushTestResult to a platform-neutral result type and update all references,
including SendApplePushTest, SendAndroidPushTest, sendPushTest, and any admin
handlers or call sites using the result. Preserve the existing fields and
behavior while ensuring both Apple and Android test methods return the renamed
type.

172-177: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated platform→setting branch; extract a helper.

The "Android uses AndroidPushDeliveryEnabled, else ApplePushDeliveryEnabled" branch here is repeated verbatim in sendPushTest (Lines 479-482). A helper like s.settings.PlatformPushDeliveryEnabled(ctx, platform) would keep both call sites in sync, especially important if a third platform is ever added.

♻️ Suggested helper
-	deliveryEnabled := s.settings.ApplePushDeliveryEnabled(ctx)
-	if device.Platform == PushPlatformAndroid {
-		deliveryEnabled = s.settings.AndroidPushDeliveryEnabled(ctx)
-	}
+	deliveryEnabled := s.settings.PlatformPushDeliveryEnabled(ctx, device.Platform)
🤖 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 `@internal/notifications/push_sender.go` around lines 172 - 177, Extract the
repeated platform-to-delivery-setting selection into a shared helper, such as
PlatformPushDeliveryEnabled, on the settings type. Update both the current
delivery check and sendPushTest to call it, preserving Android’s setting
selection and Apple/default behavior while keeping both call sites synchronized.
internal/api/handlers/notifications_push_devices.go (1)

125-130: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Response type name is Apple-specific but used for the generic/Android endpoint.

HandleRegisterPushDevice (explicitly documented as the "platform-generic registration used by the Android client") reuses applePushRegisterResponse. The shape is fine, but the name will confuse future readers extending this to another platform. Consider a neutral name like pushDeviceRegisterResponse shared by both handlers.

🤖 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 `@internal/api/handlers/notifications_push_devices.go` around lines 125 - 130,
Rename the Apple-specific response type used by HandleRegisterPushDevice to the
neutral shared name pushDeviceRegisterResponse, and update its declaration and
all references in both generic/Android and Apple registration handlers while
preserving the existing response shape.
internal/notifications/push_devices.go (1)

37-38: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

FCM token regex may reject valid tokens as Google's format evolves.

Google's own guidance is that FCM registration tokens have no documented format and apps should not validate them against a pattern, since the format can change without notice. The chosen charset (A-Za-z0-9_:-, 64-512 chars) covers today's known token shapes, but a future format change (e.g. new separators, shorter/longer tokens) would silently block legitimate registrations with ErrPushDeviceInvalid until the regex is updated.

Consider loosening this check to a coarse sanity bound (e.g. non-empty, reasonable max length) and letting the relay/FCM API surface real invalid-token errors, mirroring the platform's own stance on this.

🤖 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 `@internal/notifications/push_devices.go` around lines 37 - 38, Replace the
strict fcmTokenPattern validation with a coarse sanity check that accepts any
non-empty FCM token up to a reasonable maximum length, without restricting
characters or requiring a minimum length. Update the push-device validation path
to retain ErrPushDeviceInvalid only for values outside those bounds, while
leaving relay/API validation to detect genuinely invalid tokens.
internal/notifications/push_devices_test.go (1)

175-254: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

New device-scoped unregistration path has no test coverage. Both test files added tracking (deleted/DeleteByProfileDevice) for the new unregister flow but neither actually exercises it with an assertion.

  • internal/notifications/push_devices_test.go#L175-L254: add a test that calls PushDeviceService.Unregister and asserts store.deleted contains the expected profileID/deviceID pair, plus a rejection case for empty profileID/deviceID.
  • internal/api/handlers/notifications_push_devices_test.go#L116-L176: add a test that calls HandleUnregisterPushDevice with a URL-routed device_id, asserts 204, and asserts store.deleted recorded the call.
🤖 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 `@internal/notifications/push_devices_test.go` around lines 175 - 254, Add
coverage for the device-scoped unregister flow: in
internal/notifications/push_devices_test.go:175-254, test
PushDeviceService.Unregister with valid profileID/deviceID and assert
store.deleted records the pair, plus verify empty profileID or deviceID is
rejected without calling the store; in
internal/api/handlers/notifications_push_devices_test.go:116-176, test
HandleUnregisterPushDevice using a URL-routed device_id, assert a 204 response,
and verify store.deleted records the request.
🤖 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 `@migrations/sql/20260714160000_push_devices_android.sql`:
- Around line 36-38: Move the fcm_token_hash index creation and the
corresponding index operation at the other referenced location out of this
migration into a separate Goose migration annotated with -- +goose NO
TRANSACTION. Use CREATE/DROP INDEX CONCURRENTLY there, while keeping the column
and constraint changes in the current transactional migration.
- Around line 7-10: Update each replacement CHECK constraint in the migration,
including the constraints on push_devices and push_delivery_attempts, to be
added with NOT VALID, then add separate ALTER TABLE ... VALIDATE CONSTRAINT
statements for each constraint. Preserve the existing constraint expressions and
names while ensuring validation occurs through the non-blocking validation path.

---

Nitpick comments:
In `@internal/api/handlers/admin_apple_push.go`:
- Around line 68-77: Rename notifications.ApplePushTestResult and the shared
admin push test request/response structs to platform-neutral names, then update
SendApplePushTest, SendAndroidPushTest, AdminApplePushHandler.handleTest,
HandleTestAndroid, and all related references to use the new names consistently.

In `@internal/api/handlers/notifications_push_devices.go`:
- Around line 125-130: Rename the Apple-specific response type used by
HandleRegisterPushDevice to the neutral shared name pushDeviceRegisterResponse,
and update its declaration and all references in both generic/Android and Apple
registration handlers while preserving the existing response shape.

In `@internal/api/handlers/notifications.go`:
- Around line 390-410: Refactor the Apple and Android branches in the capability
construction flow to use a shared helper for the enabled push capability. Keep
the existing per-platform delivery-toggle checks and disabled defaults
unchanged, while centralizing the identical Provider and SupportedModes values
so both platforms cannot diverge.

In `@internal/notifications/push_devices_test.go`:
- Around line 175-254: Add coverage for the device-scoped unregister flow: in
internal/notifications/push_devices_test.go:175-254, test
PushDeviceService.Unregister with valid profileID/deviceID and assert
store.deleted records the pair, plus verify empty profileID or deviceID is
rejected without calling the store; in
internal/api/handlers/notifications_push_devices_test.go:116-176, test
HandleUnregisterPushDevice using a URL-routed device_id, assert a 204 response,
and verify store.deleted records the request.

In `@internal/notifications/push_devices.go`:
- Around line 37-38: Replace the strict fcmTokenPattern validation with a coarse
sanity check that accepts any non-empty FCM token up to a reasonable maximum
length, without restricting characters or requiring a minimum length. Update the
push-device validation path to retain ErrPushDeviceInvalid only for values
outside those bounds, while leaving relay/API validation to detect genuinely
invalid tokens.

In `@internal/notifications/push_sender.go`:
- Around line 424-438: Update newPushDispatcher so the dispatcher channel and
logger component use platform-neutral push-delivery labels instead of “apple
push” and “notifications.apple_push.dispatch”; keep the existing dispatcher
behavior and callbacks unchanged.
- Around line 456-524: Rename ApplePushTestResult to a platform-neutral result
type and update all references, including SendApplePushTest,
SendAndroidPushTest, sendPushTest, and any admin handlers or call sites using
the result. Preserve the existing fields and behavior while ensuring both Apple
and Android test methods return the renamed type.
- Around line 172-177: Extract the repeated platform-to-delivery-setting
selection into a shared helper, such as PlatformPushDeliveryEnabled, on the
settings type. Update both the current delivery check and sendPushTest to call
it, preserving Android’s setting selection and Apple/default behavior while
keeping both call sites synchronized.
🪄 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: 1bd12406-1827-40d8-9c64-00f66c291d22

📥 Commits

Reviewing files that changed from the base of the PR and between 075e217 and cf5d59b.

📒 Files selected for processing (15)
  • internal/api/handlers/admin.go
  • internal/api/handlers/admin_apple_push.go
  • internal/api/handlers/notifications.go
  • internal/api/handlers/notifications_push_devices.go
  • internal/api/handlers/notifications_push_devices_test.go
  • internal/api/router.go
  • internal/notifications/fanout_worker.go
  • internal/notifications/operational_dispatch.go
  • internal/notifications/push_delivery.go
  • internal/notifications/push_devices.go
  • internal/notifications/push_devices_test.go
  • internal/notifications/push_sender.go
  • internal/notifications/push_sender_test.go
  • internal/notifications/settings.go
  • migrations/sql/20260714160000_push_devices_android.sql

Comment on lines +7 to +10
ALTER TABLE public.push_devices
DROP CONSTRAINT push_devices_platform_check;
ALTER TABLE public.push_devices
ADD CONSTRAINT push_devices_platform_check CHECK (platform IN ('apple', 'android'));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

New CHECK constraints will full-scan push_devices/push_delivery_attempts while holding the migration's lock.

Since push_devices already carries live Apple registrations, ADD CONSTRAINT ... CHECK (...) without NOT VALID forces a full-table scan while the transaction still holds the lock from the preceding ALTER TABLE/DROP CONSTRAINT statements, blocking writes for the scan's duration. The standard zero-downtime pattern is NOT VALID followed by a separate VALIDATE CONSTRAINT, which only takes a SHARE UPDATE EXCLUSIVE lock and doesn't block concurrent reads/writes.

🐛 Proposed fix (illustrated for one constraint; apply to the other two)
 ALTER TABLE public.push_devices
     ADD CONSTRAINT push_devices_platform_fields_check CHECK (
         ...
-    );
+    ) NOT VALID;
+ALTER TABLE public.push_devices
+    VALIDATE CONSTRAINT push_devices_platform_fields_check;

Also applies to: 12-34, 40-43, 51-54, 58-67, 69-72

🧰 Tools
🪛 Squawk (2.59.0)

[warning] 10-10: By default new constraints require a table scan and block writes to the table while that scan occurs. Use NOT VALID with a later VALIDATE CONSTRAINT call.

(constraint-missing-not-valid)

🤖 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 `@migrations/sql/20260714160000_push_devices_android.sql` around lines 7 - 10,
Update each replacement CHECK constraint in the migration, including the
constraints on push_devices and push_delivery_attempts, to be added with NOT
VALID, then add separate ALTER TABLE ... VALIDATE CONSTRAINT statements for each
constraint. Preserve the existing constraint expressions and names while
ensuring validation occurs through the non-blocking validation path.

Source: Linters/SAST tools

Comment on lines +36 to +38
CREATE INDEX push_devices_fcm_token_hash_idx
ON public.push_devices (fcm_token_hash)
WHERE fcm_token_hash IS NOT NULL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

Index create/drop will lock out writes; CONCURRENTLY needs its own non-transactional migration.

CREATE INDEX/DROP INDEX without CONCURRENTLY block table writes for the duration of the build/drop. Adding CONCURRENTLY here isn't a drop-in fix though: Postgres refuses CREATE/DROP INDEX CONCURRENTLY inside a transaction block, and Goose wraps this whole file's statements in one transaction by default — you'd need to split the index operations into their own migration file annotated with -- +goose NO TRANSACTION, since applying that annotation to this file would also strip atomicity from the column/constraint changes above.

Also applies to: 56-56

🧰 Tools
🪛 Squawk (2.59.0)

[warning] 36-38: During normal index creation, table updates are blocked, but reads are still allowed. Use concurrently to avoid blocking writes.

(require-concurrent-index-creation)

🤖 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 `@migrations/sql/20260714160000_push_devices_android.sql` around lines 36 - 38,
Move the fcm_token_hash index creation and the corresponding index operation at
the other referenced location out of this migration into a separate Goose
migration annotated with -- +goose NO TRANSACTION. Use CREATE/DROP INDEX
CONCURRENTLY there, while keeping the column and constraint changes in the
current transactional migration.

Source: Linters/SAST tools

@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: cf5d59b04a

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

SupportedModes: []string{notifications.PushModePrivatePush, notifications.PushModeInAppOnly},
}
}
if h.system.Settings.AndroidPushDeliveryEnabled(r.Context()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Expose the Android toggle before gating capability on it

When admins enable the existing Silo Push Relay card, the settings UI still only loads and writes notifications.apple_push_delivery_enabled (web/src/pages/admin-settings/NotificationsAdminSettings.tsx), but Android capability now requires this new AndroidPushDeliveryEnabled key. In normal UI-configured deployments the relay can be registered and switched on while /notifications/capability continues to report android_push.available=false, so Android clients never attempt push registration/delivery unless an operator discovers and writes the hidden setting through the raw settings API.

Useful? React with 👍 / 👎.

Comment on lines +294 to +295
COALESCE(fcm_token_ciphertext, ''),
COALESCE(fcm_token_hash, ''),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Update temp push_devices schemas for FCM columns

Adding these columns to the shared pushDeviceColumns projection makes the DB-backed repository tests query fcm_token_ciphertext/fcm_token_hash, but the session-local push_devices temp tables in internal/notifications/push_devices_test.go and internal/notifications/operational_dispatch_test.go were not given those columns. When SILO_TEST_DATABASE_URL is set, even the Apple-only tests now fail with a missing-column error before exercising the code under test; keep the temp schemas in sync with the production migration.

Useful? React with 👍 / 👎.

sendPath = relayFcmSendPath
payload = pushRelayFcmRequest{
Token: token,
Mode: "private_alert",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Send the FCM wire mode instead of the APNs mode

For Android devices this builds the /v1/fcm/send payload with mode: "private_alert", but the repo's FCM relay contract says the FCM wire modes are private_data or background_wake, with profile private_push mapping to FCM private_data (docs/superpowers/plans/notifications/00-architecture-overview.md and 03-fcm-relay.md). With the documented relay validation, every Android push attempt using this path is rejected before delivery, while retries keep sending the same invalid payload.

Useful? React with 👍 / 👎.

Comment on lines +107 to +111
Token string `json:"token"`
Mode string `json:"mode"`
ServerDeviceID string `json:"server_device_id"`
DeliveryID string `json:"delivery_id"`
CollapseID *string `json:"collapse_id,omitempty"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Include the required FCM relay fields

Even after the mode value is fixed, this request shape still does not match the checked-in /v1/fcm/send contract: docs/superpowers/plans/notifications/relay/00-relay-spec.md requires project_id and package_name for the relay allowlist and names the collapse field collapse_key, while this struct sends neither allowlist field and uses collapse_id. In deployments using the documented relay validation, Android sends will be rejected before reaching FCM because the request is missing required routing/allowlist data and may include an unexpected field.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1.0 Silo v1 scope - auto-adds to the Silo v1 project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant