Skip to content

feat(growth): one invite reminder after 5 days, and "your friend joined" notifications (#1397) - #1438

Merged
thinkclay merged 1 commit into
mainfrom
feat/invite-reminders
Nov 24, 2026
Merged

thinkclay merged 1 commit into
mainfrom
feat/invite-reminders

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #1397. Part of epic #1399. Also fixes an existing bug that silently dropped de-duplicated notifications (migration 401, below).

Reminders

  • _shared/invites/reminders.ts sends one reminder per email invite. An invite qualifies when it was sent at least 5 days ago and is still pending, unexpired and unreminded.
    • The reminder has the subject "Reminder: invited you to Scaffald", the same link and note as the original, and goes out as a marketing send.
    • reminder_sent_at is stamped when the reminder goes out, and also when it never can: the address is suppressed, or the person joined in the meantime. So nobody is reminded twice.
    • NevarMail's daily cap or an outage leaves the invite for tomorrow, and the cap also ends the run.
    • Phone invites are never reminded, because Scaffald doesn't send texts.
    • With no NevarMail use case configured (every environment today), nothing is sent and nothing is stamped, so reminders start once email is set up.
  • The invites-remind edge function (service-role only) runs daily at 15:00 UTC from pg_cron via core.run_invite_reminders() (migration 400). It has the same shape as 391's account-deletion job, and it's added to deploy-functions.sh, config.toml and the functions README.

Notifications for the inviter

These are in-app notifications, de-duplicated per referred user, with a "See your invites" button to /dashboard/invite.

  • referral.joined fires from POST /v1/invites/claim: "Jo joined Scaffald". The name comes from the invite, or else from the new account.
  • referral.onboarded fires from POST /v1/prerequisites/complete. The first time, it stamps referral_attributions.onboarded_at and sends " set up their profile".
  • Neither can fail the request it rides on. Migration 400 adds both types to core.notification_type.

Migration 401: the existing bug

insertNotification de-duplicates with .upsert(…, { onConflict: 'dedupe_key' }). But the unique index from 025 is partial (WHERE dedupe_key IS NOT NULL), and PostgREST's ON CONFLICT can't target a partial index. So every insert with a dedupe key has failed with 42P10 and returned null.

notify-publish passes a key for every event that has one, so those notifications were never written; its result just said "Failed to insert notification". Expect some notifications to start arriving once this ships.

The fix replaces the index with a plain unique index. It enforces the same rule (NULLs stay distinct, so rows without a key are unaffected) and works as an upsert target. The old index already kept non-null keys unique, so building the new one can't fail on existing rows.

Tests

  • New gated invite-reminders-rest.test.ts:
    • Covers every case: due, too new, already reminded, accepted, expired, phone, joined since, and suppressed.
    • Never sends twice; the cap defers to the next run; nothing happens without email configured.
    • The joined and onboarded notifications go through the real API, are idempotent, and onboarding with no invite behind it is untouched.
  • A unit test for the reminder email.
  • notifications-operations, invites-rest, invites-data-rls and the RLS matrix still pass, run against the API from this branch.
  • check-migrations and check-edge-fn-types pass (within baseline; invites-remind has 0 errors).

Pushed with SKIP_PREPUSH=1: the shared local edge runtime still serves another session's worktree. CI is the check.

🤖 Generated with Claude Code

…ed" notifications (#1397)

Reminders:
- _shared/invites/reminders.ts: an email invite sent ≥5 days ago that is
  still pending, unexpired and unreminded gets ONE reminder ("Reminder:
  <inviter> invited you to Scaffald", same link and note, marketing send).
  reminder_sent_at is stamped when it goes out and when it never can
  (suppressed, the person joined meanwhile), so nothing is reminded twice;
  NevarMail's daily cap or an outage leaves it for tomorrow and the cap
  ends the run. Phone invites are never reminded (Scaffald doesn't text).
  With no NevarMail use case configured nothing is sent or stamped.
- invites-remind edge function (service-role only), daily 15:00 UTC from
  pg_cron via core.run_invite_reminders() (migration 400). Added to
  deploy-functions.sh, config.toml and the functions README.

Notifications for the inviter (in-app, "See your invites" → /dashboard/invite):
- referral.joined from POST /v1/invites/claim: "Jo joined Scaffald",
  named from the invite, else the new account.
- referral.onboarded from POST /v1/prerequisites/complete: stamps
  referral_attributions.onboarded_at the first time and says "<Name> set
  up their profile". Neither can fail the request it rides on.
- Migration 400 adds both to core.notification_type.

Migration 401 fixes a long-standing bug this surfaced: the dedupe_key
unique index (025) is partial, and PostgREST's ON CONFLICT can't target a
partial index, so every insertNotification with a dedupe key failed with
42P10 and returned null. notify-publish passes one for every event that
has it, so those notifications were never written ("Failed to insert
notification"). A plain unique index enforces the same rule (NULLs stay
distinct) and is a valid upsert target.

Tests: gated invite-reminders-rest (due/too new/already reminded/
accepted/expired/phone/joined/suppressed, never twice, the cap defers,
nothing without email config; joined + onboarded notifications through
the real api, idempotent, no-invite onboarding untouched); reminder email
unit test; notifications-operations, invites, RLS suites still green;
edge-fn type ratchet within baseline (invites-remind 0).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results

    CPU | AMD EPYC 9V74 80-Core Processor
Runtime | Deno 2.9.8 (x86_64-unknown-linux-gnu)

file:///home/runner/work/SaaS/SaaS/packages/supabase/functions/api/__tests__/benchmarks/rest-vs-trpc.bench.ts

| benchmark                                     | time/iter (avg) |        iter/s |      (min … max)      |      p75 |      p99 |     p995 |
| --------------------------------------------- | --------------- | ------------- | --------------------- | -------- | -------- | -------- |

group jobs-list
REST: GET /v1/jobs (paginated list):   → Average response time: 85.82ms
REST: GET /v1/jobs (paginated list):   → Average response time: 83.79ms
REST: GET /v1/jobs (paginated list):   → Average response time: 81.61ms
REST: GET /v1/jobs (paginated list):   → Average response time: 85.19ms
REST: GET /v1/jobs (paginated list):   → Average response time: 85.55ms
| REST: GET /v1/jobs (paginated list)           |           3.2 s |           0.3 | (   3.2 s …    3.3 s) |    3.2 s |    3.3 s |    3.3 s |

group job-details
REST: GET /v1/jobs/:id (single job):   → Average response time: 81.21ms
REST: GET /v1/jobs/:id (single job):   → Average response time: 84.65ms
REST: GET /v1/jobs/:id (single job):   → Average response time: 84.85ms
REST: GET /v1/jobs/:id (single job):   → Average response time: 83.47ms
REST: GET /v1/jobs/:id (single job):   → Average response time: 127.97ms
| REST: GET /v1/jobs/:id (single job)           |           3.4 s |           0.3 | (   3.2 s …    4.1 s) |    3.2 s |    4.1 s |    4.1 s |

group application-create
REST: POST /v1/applications (create):   → Average response time: 82.27ms
REST: POST /v1/applications (create):   → Average response time: 79.03ms
REST: POST /v1/applications (create):   → Average response time: 81.23ms
REST: POST /v1/applications (create):   → Average response time: 80.25ms
REST: POST /v1/applications (create):   → Average response time: 79.40ms
| REST: POST /v1/applications (create)          |           5.3 s |           0.2 | (   5.2 s …    5.3 s) |    5.3 s |    5.3 s |    5.3 s |

group concurrency
REST: Concurrent GET /v1/jobs (10 parallel):   → Throughput: 24.38 req/s
REST: Concurrent GET /v1/jobs (10 parallel):   → Average time per batch: 410.18ms
REST: Concurrent GET /v1/jobs (10 parallel):   → Throughput: 24.00 req/s
REST: Concurrent GET /v1/jobs (10 parallel):   → Average time per batch: 416.62ms
REST: Concurrent GET /v1/jobs (10 parallel):   → Throughput: 20.11 req/s
REST: Concurrent GET /v1/jobs (10 parallel):   → Average time per batch: 497.27ms
REST: Concurrent GET /v1/jobs (10 parallel):   → Throughput: 20.00 req/s
REST: Concurrent GET /v1/jobs (10 parallel):   → Average time per batch: 499.98ms
REST: Concurrent GET /v1/jobs (10 parallel):   → Throughput: 20.80 req/s
REST: Concurrent GET /v1/jobs (10 parallel):   → Average time per batch: 480.72ms
| REST: Concurrent GET /v1/jobs (10 parallel)   |           8.4 s |           0.1 | (   7.6 s …    8.8 s) |    8.7 s |    8.8 s |    8.8 s |

group filtered-queries
REST: GET /v1/jobs with multiple filters:   → Average response time: 86.87ms
REST: GET /v1/jobs with multiple filters:   → Average response time: 138.14ms
REST: GET /v1/jobs with multiple filters:   → Average response time: 82.95ms
REST: GET /v1/jobs with multiple filters:   → Average response time: 82.93ms
REST: GET /v1/jobs with multiple filters:   → Average response time: 84.98ms
| REST: GET /v1/jobs with multiple filters      |           3.5 s |           0.3 | (   3.3 s …    4.4 s) |    3.3 s |    4.4 s |    4.4 s |


@thinkclay
thinkclay merged commit 38aac5e into main Nov 24, 2026
25 of 27 checks passed
@thinkclay
thinkclay deleted the feat/invite-reminders branch November 24, 2026 06:37
thinkclay added a commit that referenced this pull request Nov 26, 2026
Office/Admin/Developers split (epic #1442: #1443, #1444, #1445, #1446)
and worker invites with reminders (#1430, #1438; migrations 400, 401).

Co-Authored-By: Claude Opus 5.5 <[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.

feat(growth): one invite reminder after 5 days, and 'your friend joined' notifications

1 participant