Date: 2026-10-23
Baseline: 0.3.0 release candidate (supersedes development snapshot 1b8f168)
Roadmap: docs/service-improvement-plan.md
Lifecycle decision: docs/adr/0001-delivery-lifecycle.md
This inventory describes the implementation as it exists, not the target architecture. It is the reference point for the service improvement roadmap.
bun run typecheck: pass.- Release qualification: 369 tests passed across 65 files, with no skips, on Node 22.23.1 and PostgreSQL 16. See the release checklist.
- Effect diagnostics: zero errors and warnings; two informational suggestions.
bun run smoke: pass against the built package.- Package entry-point guard: pass; the root entrypoint exports core modules only and does not load providers, Node adapters, or server modules.
| Level | Assembly | Durability | Current guarantee |
|---|---|---|---|
| Direct | Email.layerTransport or Email.layer with static routes |
None | Prepares and submits one attempt through the selected transport |
| Resilient | Direct plus EmailTransport policy wrappers |
None | Adds bounded local retry, fallback, throttling, or circuit breaking |
| Durable | SubmissionAdmission + DeliveryStore + persisted queue + worker/publisher/reconciler |
Depends on store and queue layers | Admission is durable; dispatch and recovery are tracked, but external delivery is not exactly once |
Memory-backed stores, queues, workflow engines, and spools do not survive process
loss. WorkflowEngine.layerMemory is a development facility.
| Area | Entry points | Current behavior | Source |
|---|---|---|---|
| Message preparation | Message, Email.send, Email.sendBatch, admission |
Normalizes addresses, validates content, renders templates, checks capabilities; admission now uses the same preparation path | src/Message.ts, src/Email.ts, src/queue/Submissions.ts, src/render/Template.ts |
| Direct send | Email.layer, Email.layerTransport, Email.send |
Resolves a static route and returns a SubmissionReceipt |
src/Email.ts |
| Batch and stream | Email.sendBatch, Email.sendStream |
Retains original slot indexes and maps native batches; bounded stream chunks | src/Email.ts |
| Policies | withRetry, withFallback, withRoundRobin, withTee, withRateLimit, withCircuitBreaker |
Local policies over transport values; native batch dispatch is preserved by retry; fallback revalidates the secondary; partial batch retry is opt-in | src/EmailTransport.ts, src/Capabilities.ts |
| Registry | TransportRegistry, Email.layerFromRegistry, Email.layerFromRegistryLayer |
Routes are resolved while the Email layer is built; there is no hot reconfiguration | src/TransportRegistry.ts, src/Email.ts |
| Routing diagnostics | Routing.explain, Routing.requirementsOf |
Reports hard requirements, capability rejections, explicit-route exclusions, and preferences without sending | src/Routing.ts, src/Capabilities.ts |
| Providers | Provider-specific make, layer, client, and transport constructors |
24 provider/infrastructure adapters plus local catchers and Mock |
src/providers/ |
| Admission | SubmissionAdmission.accept, acceptRaw, get, cancel, redrive |
Authorizes, optionally checks suppression, snapshots content, and persists an intent | src/SubmissionAdmission.ts |
| Delivery store | DeliveryStore with memory and SQL layers |
Durable intent, claim, attempt, correlated event, cancellation, retention, tenant-scoped paging, and redrive audit state; memory and SQL share pure lifecycle transitions | src/DeliveryStore.ts, src/DeliveryStoreSql.ts, src/DeliveryTransitions.ts |
| Queue and recovery | src/queue/Submissions.ts |
Persisted submission jobs, bounded publisher and stale-claim pages, worker, reconciliation, redrive | src/queue/Submissions.ts |
| Workflows | SubmitAfterDelay, WaitForDeliveryEvent |
Durable delay and typed event matching on WorkflowEngine; waits re-check stored events before blocking |
src/workflow/Submissions.ts |
| Gateway and SMTP | Gateway, Catcher, Smtp client/server |
Authenticated submission paths with deny-by-default authorization; slow-client and invalid-command coverage | src/server/, src/smtp/ |
| Suppression | SuppressionStore |
Admission-time check when a suppression store is present | src/Suppression.ts |
| Retention | DeliveryStore.prune |
Prunes intents/events by time; does not yet model content/attempt/event retention separately | src/DeliveryStore.ts |
| Errors | Certainty | Local retry | Worker behavior today |
|---|---|---|---|
DeliveryUncertain, MalformedProviderResponse |
unknown |
Never | Records uncertain; no automatic resend or fallback |
ProviderRejected, AuthenticationFailed, IdempotencyConflict |
rejected |
Only explicitly retryable rejections | Records rejected; retryable rejections defer while attempts remain |
InvalidMessage, UnsupportedCapability, TemplateError |
not-submitted |
No | Stops immediately and records failed |
RateLimited, TransportUnavailable |
not-submitted |
Yes, bounded and Retry-After aware |
Defers when attempts remain |
StoreUnavailable, RecipientSuppressed, SubmissionCanceled |
not-submitted |
No | Stops immediately and records failed; a failing store may prevent the write |
Sources: src/EmailError.ts, src/RetryDecision.ts, src/EmailTransport.ts,
src/queue/Submissions.ts.
Production provider HTTP request failures that occur before a response are
classified as DeliveryUncertain unless an adapter can prove the request was
not submitted. A received HTTP error status is still classified from that
status. Local Mailcrab and Mailpit catchers retain their development-oriented
transport failure behavior.
DeliveryStatus values are pending, in-progress, accepted, rejected,
uncertain, failed, canceled, delivered, bounced, and complained.
pending -> in-progress -> accepted -> delivered | bounced | complained
-> rejected
-> uncertain
-> failed
pending -> canceled
acceptedmeans the provider accepted responsibility for submission. It does not mean the recipient received the message.in-progressrecords that dispatching started. Process death during this state does not prove rejection.uncertainis terminal for automatic dispatch. Recovery requires provider lookup, verified events, or an explicit redrive with duplicate risk.delivered,bounced, andcomplainedare projected from provider events.openedandclickedare stored but do not change delivery status.dispatchGenerationguards stale queue work and stale attempt completions.claimIdandclaimExpiresAtguard active attempts. A second worker cannot claim an in-progress delivery, and a stale claim cannot record an outcome.- An expired claim requires reconciliation before redrive; an in-progress intent rejects redrive. Lease expiry does not authorize an automatic resend.
Sources: src/DeliveryStore.ts, src/DeliveryStoreSql.ts, src/queue/Submissions.ts.
- Admission commits an intent before returning an admission receipt.
- The outbox publisher can recover committed intents that were not yet queued.
- A provider-accepted message with a persistence failure is logged and the queue item is acknowledged to avoid an automatic duplicate submission.
- An uncertain result is never automatically retried or failed over.
- Policy wrappers and the durable worker use
src/RetryDecision.ts; permanent local failures stop without consuming further queue attempts. - Fallback revalidates the target and preserves original batch indexes.
- Native batch retry preserves accepted, uncertain, and invalid slots. Partial
retry requires the provider to advertise
partialBatchRetry. - Original batch slots receive one normalized outcome each.
- Memory and SQL stores apply the same pure lifecycle transitions; SQL no longer restores or snapshots through a memory store.
- Concurrent identical intent creation returns one intent; different content
returns
IdempotencyConflict. SQL creation uses an atomic insert. - Publisher and reconciler process tenant/outbox and stale-claim queries in bounded delivery-ID pages rather than scanning all intents.
- Admission and direct sending share message normalization, validation, and template snapshot rules.
- Routing diagnostics expose capability reasons without network I/O.
- Provider events correlate by receipt provider message ID and destination, and deterministic projection prevents older or contradictory events from regressing terminal delivery state.
- Event waits can require explicit event types and re-check stored events before blocking.
- The worker re-checks suppression immediately before dispatch.
- Verified complaint events automatically suppress recipients when a suppression
store is assembled; bounce suppression is opt-in via
suppressOnEvents. - Cancellation reports
canceled-before-dispatch,cancellation-requested, oralready-submitted; uncertain redrive requires duplicate-risk acknowledgment. examples/postgres-service.tsassembles SQL admission, queue, worker, publisher, reconciler, scoped shutdown, and status lookup.- Operator queries can page by tenant and status; redrive records actor/reason; pruning retains non-terminal work.
- Admission and worker emit bounded Effect counters for admissions, attempts, acceptance, rejection, uncertainty, retries, and failures.
Submissions.reconcileUncertainpages uncertain intents and applies provider lookup results as correlated events.- Gateway diagnostics and health use grouped status counts instead of loading all pending, failed, and uncertain intents.
Email.layerValidatedreturns typed configuration failures for invalid senders, empty routes, and unknown default routes.Service.startexposes scoped publisher/worker/reconciler health and explicit shutdown without hiding listeners.- Provider support is labeled by evidence in
docs/provider-support.md; SMTP covers slow clients and invalid-command recovery. - Cancellation prevents future dispatch when the worker observes it; it cannot recall a submitted message.
- Suppression is enforced when a
SuppressionStoreis present.
| Gap | Current evidence | Consequence |
|---|---|---|
| Tenant identity is stored but not required for lookup | DeliveryIntent.tenantId, tenant_id column |
A caller can still address a delivery without tenant scoping |
| Event subscriptions require workflow-engine context | workflow/Submissions.ts, gateway |
The gateway wakes matching stored subscriptions only when its workflow engine is provided |
| Suppression discovery is optional | Admission and worker use serviceOption |
A production assembly can accidentally omit enforcement |
| Bounce suppression is policy-gated | Complaints suppress automatically; bounces require suppressOnEvents |
Soft bounces are not suppressed by default |
Development catcher still uses listAll |
server/Catcher.ts is development-only |
Not suitable as a production listing endpoint |
| Provider lookup is caller-supplied | reconcileUncertain accepts a lookup function |
No universal provider-status mapping or automatic schedule |
| No live provider sandbox suite | Contract tests use local fixtures | Sandbox parity remains release hardening |
| Registry routes are assembly-time | Email.layerFromRegistry |
Route changes require rebuilding the layer |
| Storage schema is intent-oriented | migrations 0001-0008 |
Attempt history is embedded JSON; wait subscriptions have a separate table; normalized attempt and recipient outcomes remain future work |
| No provider advertises partial batch retry yet | partialBatchRetry defaults to false |
The safe subset-retry path is available to custom transports but is not used by shipped adapters |
| Remote attachment snapshots are not content-addressed | URL attachments remain mutable references | Durable replay can observe changed remote content |
Legacy Email.layer still throws |
Email.layerValidated provides typed failures |
Prefer layerValidated for production assembly |
These gaps are addressed by the workstreams and PR sequence in
docs/service-improvement-plan.md. They are not release blockers by themselves;
they become release gates when the reliability beta criteria are applied.