Integrate in-app notification channel dispatch
epic-pause-status-notifications-backend-pipeline-task-009 — Wire the in-app notification channel into the orchestrator alongside the FCM push channel. Insert notification records into the in-app notifications table for both coordinator and peer mentor, ensure records are properly typed with pause or resume event metadata, and confirm that both channels are dispatched in parallel for the 5-second SLA.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 5 - 253 tasks
Can start after Tier 4 completes
Implementation Notes
Implement as `dispatchInAppNotifications(supabase, records: InAppNotificationRecord[]): Promise
The Supabase Realtime integration is automatic once the row is inserted (assuming the Flutter client has a live `notifications` channel subscription filtered by `recipient_user_id`). Confirm with the frontend team that the Flutter BLoC listening to the notifications Realtime channel handles the `pause_status_change` notification_type and routes to the correct UI state.
Testing Requirements
Unit tests: mock Supabase client and verify (a) bulk INSERT called with both records when coordinator found, (b) single INSERT called with mentor-only record when coordinator not_found, (c) insert failure caught and logged without throwing, (d) correct field values for PAUSE vs RESUME transitions. Integration tests: insert records into a test Supabase instance and verify via SELECT that records exist with correct fields. Verify Realtime event fires on a subscribed test client within 1 second of insert. Assert no RLS violation when reading back with recipient user's JWT.
Supabase Edge Functions have cold start latency that may push coordinator notification delivery beyond the 5-second SLA, particularly during low-traffic periods when the function is not warm.
Mitigation & Contingency
Mitigation: Keep the Edge Function lightweight — delegate all heavy logic to the orchestrator layer and avoid large dependency bundles. Measure p95 end-to-end latency in staging and document actual SLA achievable.
Contingency: If cold start latency consistently breaches 5 seconds, introduce a keep-warm ping from the nightly-scheduler or document the actual p95 latency in the feature spec and adjust the acceptance criterion to reflect the realistic bound.
Supabase database webhooks may fire duplicate events for a single status change under retry conditions, causing coordinators to receive multiple identical notifications for one pause event.
Mitigation & Contingency
Mitigation: Add idempotency checking in the webhook handler using the event timestamp and peer mentor ID. Store a notification dispatch record in the pause-status-record-repository and skip dispatch if a record for the same event already exists.
Contingency: If duplicates slip through in production, add a de-duplication filter in the notification centre UI layer so the coordinator sees at most one card per event, and implement a cleanup job for the notifications table.
A peer mentor with multi-chapter membership may have more than one responsible coordinator. The orchestrator design currently targets a single coordinator, and resolving multiple recipients may require schema changes to the org membership query.
Mitigation & Contingency
Mitigation: Review the multi-chapter-membership-service patterns before implementing the orchestrator's coordinator resolution. Design the dispatcher call to accept an array of coordinator IDs from the outset so adding multiple recipients is non-breaking.
Contingency: If multi-coordinator dispatch is out of scope for this epic, document the limitation and create a follow-up task. Default to the primary coordinator (lowest chapter hierarchy level) as the single recipient in the interim.