Repository navigation
Description
Why
Provisioned teams (for example, each school on a course platform) send through the organization's shared ESP and its single From domain. Bounces, complaints, suppressions, quotas and automatic pauses are already per team. Two things are still shared:
- Mailbox-provider reputation. Gmail and Microsoft score mail by its DKIM signing domain, so every team on the shared From domain shares one reputation.
- ESP account standing. ESPs enforce bounce and complaint limits on the whole account (SES reviews at about 5% bounces / 0.1% complaints). One team with a bad list can get the shared account paused, which stops every team.
Team-owned ESPs stay the full-isolation option. This issue adds the middle tier (shared ESP, per-team domain), guards the shared account, and shows the per-team numbers to the organization. It stays provider-neutral, and IP pools stay out of scope (ADR 0005).
Subtasks
1. Guard the shared ESP account
- Rolling 7-day bounce and complaint rate for each organization-owned ESP, summed across its teams, from the outbound ledger.
- Thresholds from config, set below what ESPs enforce (for example, warn at 2% / 0.05%, act at 4% / 0.08%).
- When over the line, pause marketing for the teams causing it, ranked by their share of bounces and complaints. Pause marketing on the whole shared ESP only if the rate is still over after that.
- Small teams on a shared ESP: catch them with a lower floor or absolute counts, not only rates after 500 accepted sends. Transactional (API) sends count too.
- Let self-hosted operators turn the team and ESP checks on for organization ESPs (today the team check only runs in cloud).
Done when: one team mailing a bad list ends with that team paused, the other teams still sending, and the shared ESP's rate held under the ESP's own limit.
2. Show per-team health to the organization
- Provisioned-team and usage responses include the reputation status (
normal/warned/marketing_paused/all_paused, with the reason) and 7-day sent, bounce and complaint figures. - Org mail activity reads the outbound ledger, so it covers campaigns and complaints, not only transactional mail.
- MCP tools,
openapi.jsonand the headless provisioning docs updated.
Done when: one provisioning call shows each team's health and quota.
3. Hold only the team that made a flagged import
-
assertNoImportUnderReviewis scoped to the team, so a flagged import holds only that team's campaigns. The org-wide new-account ramp stays as it is.
Done when: a flagged import at team A leaves team B's broadcasts sending.
4. Per-team sending domains on the shared ESP
- Data:
sending_domains.team_id, plusfrom_emailandsending_domain_idonesp_config_team_grants. Additive only, so the previous release keeps working. - Provider adapters (
register/records/verify/remove) using a separately stored, encrypted management credential on the org ESP. SES first, then SendGrid, then Resend and Postmark, then Mailgun (which needs an SMTP login per domain). Plain SMTP stays manual. SES is built (Isolate teams on a shared organization ESP (#220) #226); SendGrid, Resend, Postmark and Mailgun move to Team sending domains for SendGrid, Resend, Postmark and Mailgun shared mailboxes #227. - Provisioning API:
PUT/GET/DELETE /provisioning/teams/:teamId/sending-domain, returning the DNS records to add and the status. - Sending: use the team's
from_emailonly while its domain is verified and DKIM and DMARC pass. If it later fails, give a grace period, then pause that team's marketing mail. Never quietly fall back to the shared domain. - Org policy
requireTeamSendingDomain(off/marketing/all), defaultoff, plus an optional monthly cap on sending through the shared domain. - Team sending domains added to the Postmaster Tools sync.
- Dashboard: a team sending-domain dialog following the domain authentication dialog, and its status in the org's team list.
Done when: a provisioned team enters a domain, adds the records, and its next broadcast is signed d= its own domain, while other teams are unaffected.
Also
- ADR: "Isolating teams on a shared organization ESP" (items 1 and 4). docs/decisions/0013-isolate-teams-on-a-shared-organization-esp.md
Out of scope: IP pools or dedicated IPs, changes to team-owned ESPs, one-click DNS setup (Domain Connect / Entri). Revisit one-click setup if teams drop off at the DNS step.
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
s3rot0n1n commentedon Nov 25, 2026
Progress on branch
t3/school-team-provisioning-isolation(local commits, not pushed yet):3beb013. Also fixes a deadlock in shared-mailbox quota locking: reserving and committing a send locked the usage buckets in different orders. A stress test against real Postgres went from hundreds of deadlocks to none.ef9cd5b.GET /provisioning/teams/:idand/usagereturnhealth(status, reason, scope, 7-day sent, bounced and complained counts).GET /organizations/:id/mail-activitynow reads the outbound ledger (campaigns plus transactional, with complaints) and carries each team'shealthandquota, so one call covers every team. These routes stay REST-only by design (MCP parity lists them asrestOnly), so no MCP tool changed.Both pass a local browser smoke. The QA smoke runs once for the whole issue, after the release is deployed to QA.
s3rot0n1n commentedon Nov 25, 2026
Subtasks 1–3 are deployed to QA (
codelit/sendlit:qa-issue-220-04b323a,codelit/sendlit-web:qa-issue-220-04b323a, arm64, built from04b323a) and pass an e2e browser smoke there. Nothing is merged or pushed yet.The QA smoke used the existing "Pro Team 1" organization (Pro plan) and its "Mailpit QA" shared mailbox, with three teams granted to it:
shared_esp_team_breach), and no other organization or mailbox on QA was affected. Its broadcast was refused with the shared-mailbox message, its transactional email still went out, and the owner got "Marketing email paused for prola 1". After an operator release (billing CLI), the owner got "Marketing email resumed for prola 1" and its broadcast delivered.scope: team). Its broadcast was refused withimport_under_review, while "QA smoke 220" in the same organization sent its broadcast (20 emails, all in Mailpit). The organization is 86 days old, so its real flag was medium. To exercise the hold I raised that flag to high for the test and set it back to medium afterwards.Bug found and fixed during the QA smoke (
04b323a). This was a deadlock that predates this branch. Each send's outbound insert takes a foreign-key share lock on the team's grant, and the quota reservation then locked that same grantFOR UPDATE, so every broadcast through a shared mailbox deadlocked and paused itself. The fix locks the grantFOR NO KEY UPDATEinstead. On real Postgres, 199 of 200 concurrent sends deadlocked before the fix and none of 4,000 after.Subtask 4 is next.
s3rot0n1n commentedon Nov 26, 2026
Subtask 4 (teams' own sending domains on a shared mailbox) is on QA as
pr-226-2345618and passed an e2e smoke with a real Amazon SES account (ap-southeast-1):GetEmailIdentityand stores it encrypted.news@schoola.clqa.sitecreated the SES identity and showed 3 DKIM CNAMEs plus DMARC. Once DNS was published, the dialog showed 2 of 2 done.news@schoola.clqa.site; the "Send via" label showed the team address.news@district.clqa.siteagain. The policy is back to "Nothing".The SES mailbox's SMTP host is QA Mailpit, so no email went through SES. The SES API calls were a handful of identity calls.
Still open from this subtask: domain adapters for SendGrid, Resend, Postmark and Mailgun (SES only so far).
s3rot0n1n commentedon Nov 26, 2026
Review pass on the whole branch: removed duplicated and unused code and docs, and fixed what the review found (
60268f0, on QA aspr-226-60268f0).Fixes:
domain_exists_at_provider(409), and a team can't use the shared mailbox's own domain (domain_in_use).esp_provider_error(422) instead of an undeclared 502.QA smoke with real SES (ap-southeast-1):
news@schoolb.clqa.sitewas registered and verified (2 of 2 done).news@schoolb.clqa.site. Email went to QA Mailpit, not through SES.Migration 0036 was edited before release to drop two unused columns, so QA still has them, unused.
Let teams send from their own domain on a shared SES mailbox (#220)
docs: create the SES IAM key for teams' own sending domains (#220)
Keep teams' own domains out of the organization's domain list (#220)
Trim the shared-ESP isolation code and fix what the review found (#220)
s3rot0n1n commentedon Nov 26, 2026
Code review findings fixed in
41513fb, deployed to QA aspr-226-41513fb.409 esp_management_credentials_in_use.domain_in_use.QA smoke with real SES, with no DNS needed:
news@schoolc.clqa.sitefor a team.domain_in_use.Fix the code review findings on team sending domains (#220)
Decide shared-ESP pauses only after locking the controls (#220)
Merge pull request #226 from codelitdev/t3/school-team-provisioning-i…
s3rot0n1n commentedon Nov 28, 2026
Done in #226 (merged as 4bb0b23).
v0.0.0is deployed to QA and the QA smoke test passed. The prod deploy of the same tag is still to come.