Repository navigation
Isolate teams on a shared organization ESP (#220) - #226
Merged
Merged
Conversation
Each organization-owned ESP gets a rolling 7-day bounce and complaint check summed across its teams. Teams over the line pause marketing on that mailbox, worst first; the whole mailbox pauses only if the rest is still over. Transactional email keeps sending. Small teams are judged on absolute bounce and complaint counts. Self-hosted operators turn it on with SHARED_ESP_GUARD=on; cloud runs it by default. Operators release a pause with the billing CLI; for 7 days after, only sends made after the release count. The dashboard explains a shared-mailbox pause when a broadcast or sequence is refused. Also fixes a deadlock in shared-mailbox quota locking: reserving and committing a send locked the usage buckets in different orders, so API sends and the mail worker could deadlock each other. Every path now locks them in one order. ADR 0013 records the design. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Provisioned-team and usage responses now include the team's health: its strictest sending control (its own reputation or the shared mailbox's guard), the reason and where it comes from, and its last 7 days of sent, bounced and spam-complaint counts. Organization mail activity now reads the outbound ledger, so it covers broadcasts and sequences as well as transactional email and counts spam complaints. Each team also carries its health and shared-mailbox quota, so one call shows every team. The dashboard's Activity tab shows both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new account's large import used to hold campaigns for the whole organization. Each team is now judged on its own imports, and the flag holds only that team, so other teams keep sending. Import flags are kept per team, so a second team's large import still gets its own flag. A list split across teams is still caught: the imports of teams that aren't over on their own are judged together, and that flag holds the whole organization, as before. Flags raised before this change have no team and also still hold the whole organization. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each send inserts its outbound row, whose foreign key takes FOR KEY SHARE on the team's grant, and then reserves quota with SELECT ... FOR UPDATE on that same grant in the same transaction. FOR UPDATE conflicts with the other sends' key-share locks, so concurrent sends through a shared mailbox (any broadcast) deadlocked and the broadcast paused itself. Found in the QA smoke for #220; it predates this branch. Lock the grant FOR NO KEY UPDATE instead, as reserveSend already does for the team row. Reservations still serialise on the grant. On real Postgres, 10 concurrent senders went from 199 deadlocks in 200 sends to none in 4,000. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 04b323ac2e
ℹ️ 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".
A team on an organization's Amazon SES mailbox can now register its own From domain. SendLit creates the SES identity with Easy DKIM through a management API key stored encrypted on the mailbox (separate from the SMTP secret) and returns the DKIM CNAMEs and a DMARC record to publish. Once SES verifies DKIM and DMARC is published, the team's mail goes out from its own address, signed for its own domain, so its sender reputation is its own. If the domain later fails, the team keeps it for a grace period (TEAM_SENDING_DOMAIN_GRACE_HOURS, 72 by default), then its marketing pauses; it never falls back to the shared domain on its own. The delivery policy gains requireTeamSendingDomain (off/marketing/all, default off) and an optional monthly cap on marketing through the shared domain. - API: PUT/GET/DELETE /provisioning/teams/:teamId/sending-domain and the same under /organizations/:id/teams/:teamId, plus PUT/DELETE /organizations/:id/esps/:espId/management-credentials. - Team domains are re-checked hourly and included in the Google Postmaster Tools sync. - Dashboard: a sending-domain dialog per team, an SES API key dialog per mailbox, the team's domain status in the Teams tab, and the new policy fields. - Migration 0036 only adds columns, foreign keys and an index. Other providers (SendGrid, Resend, Postmark, Mailgun) plug into the same adapter later. ADR 0013 is updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A step-by-step page for self-hosters and organization owners: the scoped IAM policy, the user and access key, where the key goes (dashboard or API), the region, and the related settings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Team sending domains are proven by the ESP's DKIM and managed per team, so the organization's Sending domains list no longer shows them with Verify and Revoke, and the TXT-challenge verify and revoke cannot reach them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 of 17 tasks
Fixes: - Never adopt or delete an SES identity SendLit didn't create: register refuses an existing identity (domain_exists_at_provider, 409), and a team can't take the shared mailbox's own domain (domain_in_use). - Switching or removing a team domain removes the old identity only after the change is committed. - Claim due team domains before checking them, so replicas don't double check. - Provider errors map to 422 esp_provider_error on every route, instead of an undeclared 502. - A team released before a later ESP-wide release is counted from the later release. - Sequence list actions show the same send-refusal messages as the editor. Cuts, no behaviour change: one ledger count query for the guard, team health and reputation; reused rate, rank, day and deferral helpers; drop the unused sending_domains columns authenticated_at and provider from the unreleased 0036; drop dead exports and test hooks; reuse the existing access, actor, scheduler, DialogSection, STATUS_STYLE and DNS records table; state each docs topic once and link to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 tasks
- Cancelling a team's grant (team archived, organization closed) or retiring a shared mailbox removes the team's own domain from the ESP, so its identity isn't left in the customer's account and checked forever. Retiring a mailbox and deleting an organization also wipe the provider API key. - A team moved to another mailbox registers its domain there; a domain row on another ESP is never used to send. - The SES API key can't be removed while team domains need it (esp_management_credentials_in_use, 409). - The shared-domain monthly cap counts only broadcast and sequence sends from the shared domain, queued ones included. - A sequence paused because the organization requires a team domain says so, instead of pointing at organization domain verification. - Import flags raised before flags were per team keep holding the whole organization. - Reading a team domain re-checks the provider at most every 30 seconds. - The organization can add a domain a team used before; one a team still uses returns domain_in_use. - The provisioned-team contract comment now says what health reveals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The guard read release state and metrics before taking the row lock, so an operator release that committed while an evaluation waited for the lock was re-paused straight away on the older numbers. It now reads the locked rows and computes the metrics inside the same transaction. Reproduced on Postgres: release committed while an evaluation waited on the lock; before, the team was paused again; now it stays released. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the work in #220, except domain support for providers other than Amazon SES. SendGrid, Resend, Postmark and Mailgun come in a follow-up PR.
What changes
1. Guard the shared ESP account (
3beb013)SHARED_ESP_GUARD=on; it's on by default in cloud mode. Operators release a pause with the billing CLI.2. Per-team health for the organization (
ef9cd5b)GET /provisioning/teams/:idand/usagereturnhealth: status, reason, scope, and 7-day sent, bounced and complained counts.GET /organizations/:id/mail-activitynow reads the outbound ledger, so it covers campaigns as well as transactional email, plus complaints. It also returns each team's health and quota, so one call covers every team. The Organizations → Activity dashboard shows both.3. Hold only the team that made a flagged import (
08081f9)4. A team's own sending domain on a shared Amazon SES mailbox (
697007a, docsa9fd80a)PUT /organizations/:id/esps/:espId/management-credentials.PUT/GET/DELETE /provisioning/teams/:teamId/sending-domain. SendLit registers the domain in SES (Easy DKIM) and returns the DNS records to add.requireTeamSendingDomain(off,marketingorall; defaultoff) and an optional monthly cap on marketing sent through the shared domain.domain_exists_at_provider, 409). A team can't use the shared mailbox's own domain.Fixes found during the QA smoke
04b323a: concurrent sends through a shared mailbox deadlocked on the grant row. The lock is now FOR NO KEY UPDATE. On real Postgres, 10 concurrent senders went from 199 deadlocks in 200 sends to none in 4,000.2345618: team domains no longer appear in the organization's own Sending domains list, and the organization's TXT-challenge verify and revoke can't reach them.Review pass (
60268f0)DialogSection,STATUS_STYLEand DNS-records-table code;sending_domainscolumns, dropped from the unreleased migration 0036.Code review fixes (
41513fb)409 esp_management_credentials_in_use).domain_in_use.Migrations
0035and0036are additive.Testing
API suite: 1145 pass, 0 fail. Web suite: 124 pass. Typecheck, Biome, drift, conformance,
openapi:check,drizzle-kit generate(no changes) and the FrontLit docs check all pass.A local browser smoke passed for each subtask. For subtask 4 it used an SESv2 mock and covered both refusals, switching domains, verification, sending from the team domain, the provisioning routes, and removal.
QA, with a real Amazon SES account (ap-southeast-1), arm64 images:
pr-226-697007a: storing the API key; registering a domain and verifying it once DNS was published; transactional email and a 20-recipient broadcast sent From the team domain; the organization policy refusing a team without its own domain; removing the domain, which deleted the SES identity.pr-226-41513fb(deployed now): registering a domain, the SES API key refused for removal while it's in use, the organization refused that domain, then cancelling the grant deleted the SES identity, the organization could add the domain, and after a re-grant the team sends from the shared domain.pr-226-60268f0: refusing the shared mailbox's domain; registering and verifying a new domain; transactional email sent From it; removing it, which deleted the SES identity.The mailbox's SMTP host was QA Mailpit, so no email went through SES. Subtasks 1–3 were smoked on QA earlier. Details are in the comments on Isolate provisioned teams that share an organization ESP #220.
🤖 Generated with Claude Code