Skip to content

Phase 2b+2c: announcement queue and delivery events - #1916

Merged
neuromechanist merged 15 commits into
feature/issue-1893-epic-email-cffrom
feature/issue-1895-phase2b-outbox
Oct 24, 2026
Merged

neuromechanist merged 15 commits into
feature/issue-1893-epic-email-cffrom
feature/issue-1895-phase2b-outbox

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two parts of Phase 2 in one PR to save a CI cycle.

2b, announcements on a Queue. When the Cloudflare email provider is active and EMAIL_OUTBOX is bound, nemar admin notify records the broadcast as queued and enqueues one message per allowed, de-duplicated recipient on nemar-email-outbox (-dev on staging). The same Worker consumes it and sends through sendEmail, so the dev fence and [DEV] wrap still apply.

  • Migration 0100: status, queued_count, delivered_count, unknown_count on broadcast_emails, and broadcast_outcomes (one row per broadcast and recipient hash) so a redelivered message is never re-sent or double-counted.
  • Outcomes: delivered; a rate or daily limit retries with a growing delay and defers the rest of the batch, giving up as a failure on the final attempt; other certain non-delivery is a failure with the address redacted; anything that may have been accepted is counted unknown and never retried.
  • A partial enqueue returns 200 with queue_enqueue_failed, the broadcast id and counts.
  • GET /admin/notify/:id and nemar admin notify --status <id>.

2c, delivery events. Cloudflare publishes message.bounced and message.complained for each sending domain to nemar-email-events (-dev); the Worker stores them in email_delivery_events (migration 0101, INSERT OR IGNORE on the event id, no subject, SMTP response clamped) and prunes rows after 180 days. ADR 0110 and the epic notes are amended for the fallback set, the queue and the events.

Operator steps already done: all queues and dead-letter queues exist; subscriptions for test.nemar.org and nemar.org are created.

Part of #1895, epic #1893.

Test plan

  • Outbox, broadcast queue, events, status route, CLI notify, export surface and route inventory tests
  • Full backend suite on the combined branch: 8406 pass, 0 fail
  • bun run typecheck, bun run lint, ADR index test
  • 2b review: two rounds, all findings fixed
  • 2c review (delta), CI
  • Staging after epic to dev: a queued --user announcement arrives and reaches done; a bounce lands in dev D1

🤖 Generated with Claude Code

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.
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.
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.
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR1916

Version: 0.10.24-PR1916.b9e15f8
Commit: b9e15f8


🤖 Updated on each push.

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.
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.
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.
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.
@neuromechanist neuromechanist changed the title Phase 2b: announcements on a Queue Phase 2b+2c: announcement queue and delivery events Oct 24, 2026
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.
@neuromechanist
neuromechanist merged commit 6ba0f00 into feature/issue-1893-epic-email-cf Oct 24, 2026
14 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-1895-phase2b-outbox branch October 24, 2026 08:04

This branch was previously deployed

1 inactive deployment
npm — b9e15f8d Deployed Oct 24, 2026 by neuromechanist via publish #3838
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