Skip to content

Nightmail customers: every workspace owner on one list in the platform workspace - #991

Merged
R44VC0RP merged 3 commits into
devfrom
signups/customers-list
Nov 26, 2026
Merged

R44VC0RP merged 3 commits into
devfrom
signups/customers-list

Conversation

@R44VC0RP

@R44VC0RP R44VC0RP commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Every account that owns a workspace becomes a contact of one list, Nightmail customers, in the platform workspace (NIGHTMAIL_PLATFORM_DOMAIN_WORKSPACE), at the account's verified address. The list is for product news and service status. This sends nothing.

Do not merge until #990 (the policy and the line under the sign-in button) is live in production. Auto-merge is off.

What it does

  • Nobody sets it up. The first signups.sync run that has someone to write makes the list and records its ID in nightmail_customers_list (migration 579). This happens in one transaction under an advisory lock, so two runs at once make one list. The list is found by ID, so renaming it in the dashboard changes nothing. No new setting, secret or ID is needed in production: it is on wherever the platform workspace is configured.
  • Deleted by staff, it stays deleted. Nothing more is written, and maintenance logs CUSTOMERS_LIST_MISSING hourly. Bringing it back takes a one-line migration that deletes the row; the next run makes a new list and writes every account to it. Remaking it also takes everyone off the old list if that list still exists (renamed rather than deleted).
  • Properties and name are the contact's, so they are shared with the sign-ups list. Its contacts gain joined_via. The 8 accounts let in gain signed_up_at (their account's creation) and, where the sign-ups list holds them from the waitlist, take their account's name in place of their waitlist name.
  • Who is on it: every account with a verified address that owns a workspace, from one query. Sign-ups, sign-ups recorded before migration 459 (no address on the record), and accounts an invitation or staff let in before sign-ups opened are all on it from the first run.
    • Teammates who own no workspace are not on it (the role='owner' condition in customerAccount; dropping it adds them).
    • An address that only ever waited is not on it.
  • Properties:
    • signed_up_at (ISO 8601, UTC): the sign-up's time, or the account's creation for an account let in.
    • joined_via: sign-up or admitted, saying which of the two signed_up_at is.
    • email_domain and mailbox, as the sign-ups list has them.
    • The name is the sign-up's, else the account's.
  • Consent goes through upsertListContact. Each record's policy version names the notice it rests on, CUSTOMERS_NOTICE ("Privacy Policy and Terms of 26 November 2026", from Legal: product news and service status emails, under the sign-in button and in the policies #990). If Legal: product news and service status emails, under the sign-in button and in the policies #990 merges on a later day and its updated date changes, this constant changes with it. A record is dated when the account signed up or was made, so one dated before the notice belongs to someone who signed up before it existed; it doesn't claim they saw it. signed_up_at is what a send filters on.
    • A contact with no decision is subscribed with the source Nightmail account and the evidence "Account holder: owns a Nightmail workspace with this verified address. Product news and service status emails, on legitimate interests; not an opt-in."
    • A contact already subscribed (for example from the waitlist) gets the same record, so its history says why it is on this list. Its status doesn't change.
    • Consent is one decision per contact in the workspace, so an unsubscribe from any of the platform workspace's mail holds here too. One exception: mail sent under a topic only removes that topic.
    • Suppression is never touched. A deleted contact stays deleted.
  • Changes: an account whose address changes moves to the new address. One that is deleted, owns no workspace any more, or loses its verified address comes off within a minute. Only the membership is removed; the contact keeps its consent and suppression.
  • One job: signups.sync now writes the sign-ups list, then this list, 100 at a time within its ten-second run, and defers while more is due. A missing sign-ups list now stops only its own part. An account whose sign-up is still due for the sign-ups list waits for it, so that list's consent record comes first.

The first production run: what right looks like

Counts from the production replica before deploy (counts only):

Accounts that qualify 373: 365 signed up, 8 let in before sign-ups opened
Sign-ups without an address 0
Account address now differs from the sign-up's 2
Owners with an unverified address 0
Accounts that are only teammates 0
Already a contact in the platform workspace 366: 2 unsubscribed, 0 suppressed, 0 deleted
Topics in the platform workspace 0

Check within two minutes of the deploy

Check Expected
CUSTOMERS_LIST_CREATED log once
CUSTOMERS_LIST_SYNCED logs, summed added 7, updated 366; no skipped, deleted or invalid
nightmail_customers rows (accounts written) 373
members of the recorded list 373: 371 subscribed, 2 unsubscribed
audience_consent_audit rows with source Nightmail account in the platform workspace 371, each with the policy version above
records on a contact that is unsubscribed, suppressed or deleted 0
new contacts in the platform workspace 7
new operation.publish jobs (contact.subscription_changed) 7
sign-ups list member count and consent tallies unchanged
  • Timing: one or two ten-second runs. Someone who signed up in the minute before waits one more run, because the sign-ups list writes their first consent, so 372 at minute one and 373 at minute two is normal.
  • If added is above 7: some owners' verified address differs from the address their sign-ups contact was made with, an address changed since sign-up. That is expected, not a fault.
  • After that: the minute check queues nothing until the next sign-up, which is written within a minute. Nothing is sent.

On the replica (counts only):

WITH w AS (SELECT 'ws_90b0696c835f49fbaa9396fb726e9fe2'::text AS ws),
l AS (SELECT r.list_id FROM nightmail_customers_list r, w WHERE r.workspace_id=w.ws)
SELECT (SELECT count(*) FROM audience_lists a, w WHERE a.workspace_id=w.ws AND a.name='Nightmail customers') AS lists_named,   -- 1
  (SELECT count(*) FROM nightmail_customers c, w WHERE c.workspace_id=w.ws) AS written,                                         -- 373
  (SELECT count(*) FROM audience_list_members m, l, w WHERE m.workspace_id=w.ws AND m.list_id=l.list_id) AS members,             -- 373
  (SELECT count(*) FROM audience_list_members m JOIN audience_contacts c ON c.workspace_id=m.workspace_id AND c.id=m.contact_id, l, w
     WHERE m.workspace_id=w.ws AND m.list_id=l.list_id AND c.marketing_consent='subscribed') AS subscribed,                     -- 371
  (SELECT count(*) FROM audience_consent_audit a, w WHERE a.workspace_id=w.ws AND a.source='Nightmail account') AS account_records, -- 371
  (SELECT count(*) FROM audience_consent_audit a JOIN audience_contacts c ON c.workspace_id=a.workspace_id AND c.id=a.contact_id, w
     WHERE a.workspace_id=w.ws AND a.source='Nightmail account'
       AND (c.marketing_consent<>'subscribed' OR c.suppressed OR c.deleted_at IS NOT NULL)) AS records_on_ineligible,           -- 0
  (SELECT count(*) FROM nightmail_users u WHERE u.email_verified AND EXISTS (SELECT FROM workspace_members m WHERE m.user_id=u.id AND m.role='owner')
     AND NOT EXISTS (SELECT FROM nightmail_customers c WHERE c.user_id=u.id AND c.email=lower(u.email))) AS not_yet_written;    -- 0

Migration 579

It creates two tables (nightmail_customers_list, nightmail_customers) and takes no lock on any existing table. 578 is used by an open pull request. nightmail_customers has no foreign key to accounts on purpose: a deleted account's row stays until its membership has been removed, which takes about a minute.

Verified

  • Acceptance tests (Mac Studio lab, synthetic data): the new test Nightmail customers and the Sign-up limit test both pass. The new test covers:
    • the backfill, including a sign-up recorded without an address and an account let in by invitation;
    • a new sign-up joining within a run;
    • a teammate, an unverified address and an address that only waited staying off;
    • an unsubscribed address staying unsubscribed with no new record, a suppressed contact left suppressed, and a deleted contact staying deleted;
    • an already-subscribed contact getting the account-holder record;
    • two runs at once making one list;
    • a renamed list still being used;
    • a deleted account and an old address coming off;
    • a deleted list not being made again, and being remade only by deleting its row.
  • Backfill bench (lab, synthetic data; the bench script is not committed). The seed was 5,000 owners (4,000 sign-ups already on the sign-ups list with its consent, and 1,000 accounts let in), 300 teammates and 2,000 waiting addresses. A new account signed in every 100 ms throughout, running the sign-in's own database transaction.
    • Postgres on the same host: every owner was written, including the sign-ups that arrived meanwhile (5,693 members = 5,693 owners; 0 teammates; 0 waiting addresses), in 6 runs and 34 s, at 14 queries per account.
    • 2 ms added to every query, as a round trip from a Worker: about 17 accounts a second, 200–300 per ten-second run. A few thousand owners take about 3–5 minutes of back-to-back runs. Sign-ins at ten a second outpaced part of it, and it still ended with every owner on the list (11,799 = 11,799).
    • Locks: 0 sign-ins waited on a lock while it ran (12,686 samples of pg_stat_activity every 50 ms).
    • Sign-in transaction p50 / p95 / p99 / max, in ms, measured with the 2 ms round trip: before 3.0 / 5.8 / 11 / 27; during 2.5 / 8.6 / 28 / 118 (6,391 sign-ins); after 3.3 / 4.6 / 8.4 / 21. With Postgres on the same host, the backfill runs flat out and the tail during it grows further: p95 36, p99 60. That is shared CPU and disk, not locks.
  • Full integration-rest acceptance shard (lab): 307 pass, 0 fail, no deadlocks.
  • The second commit (policy version, README) was re-run in the lab: the customers test (now also asserting the policy version) and the sign-up limit test pass.
  • bun run check and check-premerge pass.

…m workspace

Everyone who owns a workspace is now a contact of a list named "Nightmail
customers" in the platform workspace (NIGHTMAIL_PLATFORM_DOMAIN_WORKSPACE),
at the account's verified address, for product news and service status.
It is on wherever the platform workspace is configured; nothing is set by
hand and nothing is sent.

- The list: the first signups.sync run with someone to write makes it and
  records its ID (nightmail_customers_list, migration 579) in one
  transaction under an advisory lock, so two runs make one list and a
  rename changes nothing. Deleted by staff, it stays deleted: nothing more
  is written and maintenance logs CUSTOMERS_LIST_MISSING hourly; a
  migration deleting the row makes a new one, written in full.
- Who: accounts with a verified address that own a workspace. One source
  for everyone, sign-ups and accounts let in by an invitation or staff
  alike, so sign-ups recorded before migration 459 (no address) and the
  accounts from before sign-ups opened are on it from the start. Teammates
  who own no workspace are not (one condition, customerAccount); an address
  that only waited is not.
- Each account is written once per list and address (nightmail_customers):
  signed_up_at is the sign-up's time, else the account's creation, with
  joined_via sign-up or admitted saying which; email_domain and mailbox as
  the sign-ups list has them; the sign-up's name, else the account's.
- Consent goes through upsertListContact: a contact with no decision is
  subscribed with the source "Nightmail account" (an account holder, on
  legitimate interests, not an opt-in); one already subscribed gets the
  same record (new consentAgain option), so its history says why it is on
  this list. Consent is one decision per contact in the workspace, so an
  unsubscribe from any of its mail holds; suppression is never touched; a
  deleted contact stays deleted.
- An account whose address changes moves to the new one; one deleted,
  owning no workspace or without a verified address comes off within a
  minute (removeListContact: the membership only).
- signups.sync now writes the sign-ups list, then the customers list, each
  100 at a time within the run's ten seconds; a missing sign-ups list no
  longer stops the run, only its own part. An account whose sign-up is
  still due for the sign-ups list waits for it, so that list's consent
  comes first.

Migration 579 creates two tables and locks or rewrites nothing that
exists. 578 is taken by an open pull request.

Verified (Mac Studio lab): the new acceptance test (backfill, a new
sign-up joining, a teammate, an unverified address and a waiting address
staying off, opt-out, suppression and deleted contact untouched, two runs
at once making one list, a rename, a deleted account, a changed address, a
deleted list not made again, and remaking it) and the sign-up limit test
pass. A backfill of 5,000 owners and 2,000 waiting addresses, with
sign-ins every 100 ms, wrote every owner in 7 runs (51 s), at 14 queries
an account; type-check and check-premerge pass.
The "Nightmail account" consent record now carries a policy version,
CUSTOMERS_NOTICE ("Privacy Policy and Terms of 26 November 2026": the
policy and terms that say customers get product news and service status
emails, published with the line under every sign-in button), in the
field the consent route and imports already fill. The record stays dated
when the account signed up or was made, so one dated before the notice
belongs to someone who signed up before it existed; the evidence now says
so, and signed_up_at stays what a send filters on. upsertListContact
passes a consent's policy version through to recordConsent.

api/README.md now says that bringing a deleted list back takes a
one-line migration, and that remaking it also takes everyone off the old
list if that list still exists; and that properties and name are the
contact's, shared with the sign-ups list (its contacts gain joined_via,
and an account let in that it holds from the waitlist gains
signed_up_at and the account's name).

Both are a reviewer's suggestions. Verified in the lab: the customers
test (now also asserting the policy version) and the sign-up limit test
pass; bun run check passes.
…ery record

The "Nightmail account" record is dated with the sign-up's time, or the
account's creation for an account let in. The sign-up row is written in
the transaction that creates the account and both default to now(), so
the two are the same instant: "Dated when the account was created" is
true for every record, where "signed up" was not for the 8 let-in
accounts. Only that phrase changes.

Verified in the lab: bun run check, check-premerge (base 855d159) and
the customers and sign-up limit acceptance tests pass.
@R44VC0RP
R44VC0RP added this pull request to the merge queue Nov 26, 2026
Merged via the queue into dev with commit 05ef1ea Nov 26, 2026
15 checks passed
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