Repository navigation
Email on Cloudflare: Phase 2 (production sending prepared) - #1923
Merged
Merged
Conversation
* Fall back to Resend on Cloudflare quota refusal * Bind Cloudflare email in production, no switch * Sort imports in email-provider test * Log and harden the Resend fallback
* feat: queue announcements on the outbox Migration 0100 adds status and outcome counters to broadcast_emails. sendBroadcast enqueues one message per allowed recipient when the Cloudflare provider and EMAIL_OUTBOX are both present. Tested with real D1 and a recording Queue binding. * feat: consume the announcement outbox queue() dispatches broadcast messages to handleOutboxBatch, which sends through sendEmail and records each outcome on the audit row. Rate limits retry after 300s; unknown outcomes are never retried. Exports CLOUDFLARE_LIMIT_CODES. * feat: announcement status route and CLI GET /admin/notify/:id reports a queued announcement's counts; nemar admin notify prints the queued result and gains --status. POST answers 502 when enqueueing fails. * fix: idempotent announcement outcomes Add broadcast_outcomes keyed by recipient hash; counters move only when the outcome insert took. A partial enqueue records unqueued outcomes and answers 200 with the counts. * fix: bound outbox retries and pace limits max_retries 10 with growing limit delay, give up and record a failure on the final attempt, defer the rest of a batch after a limit refusal, skip already-recorded recipients. Names the queues in wrangler and tags the unrecognised-message log. * fix: show enqueue failure and redaction in CLI * test: allow 0100's outcomes table after 0098 * fix: dedupe queued recipients by hash key * test: pin getBroadcastStatus export Adds the new CLI API export to the per-module pin and the post-split list. Tested: api export surface, notify CLI and route inventory tests. * feat: store email bounce and complaint events * feat: route email events, prune after 180 days * docs: amend ADR 0110 for the soak and events * test: account for 0101 and events consumers The outbox retry check now reads only the outbox consumers, and the 0098 schema check lists 0101's table and indexes as a later migration's. Tested: events, outbox, 0098 migration and provider suites. * fix: delay event retries, tighten ADR 0110 A failed D1 write now retries after a growing delay instead of at once; the ADR states the outbox retry bound, the de-duplication, and that every other event type is dropped. Tested: events and outbox suites, ADR index, typecheck.
7 of 13 tasks
4 tasks done
This branch was previously deployed
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.
Summary
Phase 2 of epic #1893. Production still sends through Resend after this merge; the switch is a later config PR, after the Cloudflare limit increase and a clean staging soak.
sendEmailfalls back to Resend once, only when Cloudflare refuses with a rate limit, daily limit, account pause or unavailable sending domain, gated byEMAIL_FALLBACK=resend(production only, set in the flip PR). Production gets thesend_emailbinding restricted tonoreply@and[email protected].nemar admin notify --status; bounce and complaint events from Cloudflare are stored in D1 for 180 days. Migrations 0100 and 0101.Already provisioned: the outbox and events queues with dead-letter queues (production and staging), event subscriptions for
test.nemar.organdnemar.org, andnemar.orgonboarded for Email Sending (onlycf-bouncerecords added; apex records unchanged).Deploy note: the first dev deploy with queue bindings needs Queues permission on the CI Cloudflare token; if it fails with code 10000, that permission is missing.
Part of #1895, epic #1893.
Test plan
nemar admin notify --userannouncement arrives and--statusreachesdone🤖 Generated with Claude Code