Implement transition direction detection
epic-pause-status-notifications-backend-pipeline-task-004 — Implement the logic that determines transition direction from the old and new status column values. Detect active→paused (pause event) and paused→active (resume event) transitions, ignore non-status-change updates, and map the transition to a typed TransitionEvent enum passed to the orchestrator.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
Keep detectTransition() as a standalone exported pure function in a separate transition-detector.ts file — do not inline it into the handler. This makes it trivially testable and reusable. Use a lookup table pattern (a Map or switch statement) rather than nested if/else for clarity. Since the pause feature is a SHOULD HAVE in Phase 2 per the product roadmap, design the TransitionEvent type to be extensible — a const object as enum replacement (export const TransitionEvent = { PAUSE: 'pause', RESUME: 'resume' } as const) is more Deno-idiomatic than TypeScript enum.
The null return for no-ops is intentional — it signals to the orchestrator 'nothing to do' without throwing, which keeps error handling clean.
Testing Requirements
Pure unit tests for detectTransition() — no mocks needed. Test matrix: (1) 'active' → 'paused' returns PAUSE, (2) 'paused' → 'active' returns RESUME, (3) 'active' → 'active' returns null, (4) 'paused' → 'paused' returns null, (5) 'active' → unknown_value returns null, (6) unknown_value → 'active' returns null, (7) both unknown returns null. Test the webhook handler integration: inject a no-op transition context and verify HTTP 200 with skipped body. All edge cases documented as test names for future maintainers.
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.