Everything so far has been storage and date math. If I get a recurrence wrong, a calendar shows the wrong Thursday, somebody notices, I fix it, and nobody's phone buzzes.
Sending a message is different. A message is the one thing in this system I can't roll back. It leaves, and it lands in a person's pocket at 6:30 in the morning, and the only thing worse than sending it twice is sending the wrong one with total confidence.
So this part is about the two kinds of message a calendar sends, and how I try to make each of them go out once, to the right person, in their own language and their own clock, or not at all.
Two messages, one outbox
A reminder is standing configuration. An administrator says "email 24 hours before every event on this calendar," and that's a rule. If there's no rule, there's no reminder. Nothing is ever created implicitly.
A change notice is a one-shot message about a specific edit, and it is never automatic. There is exactly one way to send one: an administrator ticks "notify recipients" in the same request that saves the edit. An absent value, a blank value and an unrecognized value all mean no. A background feed sync, which can change a hundred events at 3 a.m. because a coach edited a spreadsheet, notifies nobody. Nobody approved that message.
Both kinds share one outbox table, and I should say what that table isn't. Calendar notifications don't go through the durable communication queue that regular messages use. They use the Communication tables for rows, recipients, preferences and suppression, and the drain calls queueSend and processSend synchronously inside its own leased job. It's a second, older delivery path with its own bookkeeping. I'll get to why that matters.
Don't generate the season
The naive design generates every reminder when the rule is created. A weekly practice with a two-year recurrence rule is about 104 occurrences. Four reminder rules across two channels is 832 rows the moment somebody ticks a box, almost all of which will be wrong by next month, because somebody will move a practice.
So reminders materialize on a rolling horizon. Every minute, each node asks which events have an occurrence starting in the next 21 days and which reminder jobs they ought to have:
variables.HORIZON_DAYS = 21;
variables.GRACE_MINUTES = 15;for ( var occurrence in occurrences ) {
var event_id = toString( occurrence.event_id ?: "" );
if ( !structKeyExists( master_by_id, event_id ) ) continue;
var master = master_by_id[ event_id ];
// An occurrence that has already started can never be reminded about, an all-day one until its day is over.
if ( isDate( occurrence.occurrence_start_utc ?: "" )
&& calendar_reminder_schedule_service.reminderTooLate( occurrence.occurrence_start_utc, ( occurrence.is_all_day ?: false ) == true, now_utc ) ) {
continue;
}
// ...and one beyond the rolling horizon is not this tick's work. The
// batched loaders already bound the SCOPE sweep; reconcileEvent()
// reaches a single event directly, so the bound is applied here too or
// a two-year-out event would materialize the moment it is saved.
if ( isDate( occurrence.occurrence_start_utc ?: "" ) && dateCompare( occurrence.occurrence_start_utc, arguments.window.to_utc ) >= 0 ) {
continue;
}The grace period is the part I care about. If a reminder's due time is already more than 15 minutes in the past, I don't create it:
if ( dateCompare( due.due_utc, grace_floor ) < 0 ) {
// Materializing this now would send a stale reminder. Counted,
// never silent.
work.stale_skipped++;
continue;
}A "24 hours before" reminder for an event somebody created this morning for tomorrow is already late. Sending it three hours late says "your practice is in 21 hours," which is not a reminder, it's a status update. It's counted and logged, never silent, and never sent.
Due time is arithmetic, until it isn't
For a timed event, the due time is pure instant arithmetic. No zone is involved:
var due_milliseconds = start_utc.getTime() - ( javacast( "long", minutes ) * 60000 );
var due = createObject( "java", "java.util.Date" ).init( javacast( "long", due_milliseconds ) );
if ( dateCompare( due, start_utc ) >= 0 ) {
return fail( "start_passed", arguments.signature );
}
return { ok: true, due_utc: due, timing_signature: arguments.signature, code: "" };That has a consequence worth stating out loud. A reminder set to "24 hours before" is exactly 24 absolute hours before the event. Across a daylight saving change, the wall clock hour of the reminder shifts by one. A parent whose 7:00 practice always comes with a 7:00 reminder the evening before will get the reminder for the first practice after the clocks spring forward at 6:00. That's the correct answer to the question I asked, and I've decided it's better than the alternative, where "24 hours before" is sometimes 23 or 25.
For an all-day event there's no start time to subtract from. The administrator chose "the day before, at 9:00", which is a wall-clock time in the event's zone. That goes through the same machinery as part one: the scheduler's policy, ZonedDateTime.of, which shifts a gap forward and takes the earlier time in an overlap. The JVM's default zone is never consulted. A zone Java doesn't recognize is a hard failure with its own code.
There's one more all-day wrinkle, and it's the kind I only find by asking what the code does with a case my specs never tried. An all-day event starts at local midnight, so a reminder set for "on the day, at 9:00" is due after the event has formally started. The materializer's guard above, and the delivery guard I'll show in a moment, both used to read that as "already started" and quietly refuse it. Both now ask one shared check, reminderTooLate, which gives an all-day event until its day is over.
An edit moves the same row
Here's the question that decides the whole design: what happens to a reminder when the event changes?
If the identity of a reminder job were "this occurrence at this time," moving the practice would orphan the reminder and create a second one. Two reminders for one practice.
So a job's identity uses the original occurrence key, the same slot identity from part two, never the moved time. An edit becomes an in-place update of the same pending row. The database enforces the identity with two partial unique indexes:
CREATE UNIQUE INDEX IF NOT EXISTS ux_calnotjob_reminder_identity
ON public.calendar_notification_job USING btree (
reminder_rule_id, calendar_event_id, occurrence_key, channel,
COALESCE( recipient_user_id, '00000000-0000-0000-0000-000000000000'::uuid )
)
WHERE job_kind = 'reminder'
AND deleted IS NULL
AND status NOT IN ( 'cancelled', 'superseded' );
CREATE UNIQUE INDEX IF NOT EXISTS ux_calnotjob_change_identity
ON public.calendar_notification_job USING btree (
change_notification_id, channel,
COALESCE( recipient_user_id, '00000000-0000-0000-0000-000000000000'::uuid )
)
WHERE job_kind = 'change_notification'
AND deleted IS NULL
AND status NOT IN ( 'cancelled', 'superseded' );Read the WHERE clause. A job holds its identity in every status except cancelled and superseded. A pending job, a claimed job, a sent job, a skipped job and a failed job all keep it. That's the whole point. Once a reminder has gone out, nobody can create "another one" for the same occurrence, rule and channel.
And the write path is an upsert that only touches a row that's still pending:
ON CONFLICT #conflict_target#
DO UPDATE SET
scheduled_send_utc = EXCLUDED.scheduled_send_utc,
occurrence_start_utc = EXCLUDED.occurrence_start_utc,
occurrence_end_utc = EXCLUDED.occurrence_end_utc,
occurrence_starts_on = EXCLUDED.occurrence_starts_on,
occurrence_is_all_day = EXCLUDED.occurrence_is_all_day,
occurrence_stamp = EXCLUDED.occurrence_stamp,
event_timezone_iana = EXCLUDED.event_timezone_iana,
calendar_id = EXCLUDED.calendar_id,
audience_type = EXCLUDED.audience_type,
audience_payload = EXCLUDED.audience_payload,
timing_signature = EXCLUDED.timing_signature,
rule_row_version = EXCLUDED.rule_row_version,
publication_revision = EXCLUDED.publication_revision,
last_error_code = NULL,
last_error_detail = NULL,
row_version = public.calendar_notification_job.row_version + 1
WHERE public.calendar_notification_job.status = 'pending'
RETURNING CAST(id AS text) AS id, ( xmax = 0 ) AS was_inserted;The consequence is something I want to be honest about. If an event moves after its reminder has gone out, the sent row keeps its identity and no second reminder is created. The reminder isn't the tool for correcting the record. The change notice, if the administrator asked for one, is.
Sending is a fresh decision
Creating a job is not permission to send it. That distinction is the first line of the delivery service's header, in capital letters: materializing is not authorizing.
Between "this job was created three weeks ago" and "this job is being delivered now" the event can be unpublished, cancelled, made private, deleted, moved to another calendar, or excluded; the rule can be disabled; the occurrence can be cancelled or orphaned. The delivery service re-reads the live state and decides again:
var occurrence_check = checkOccurrence( work_job, cal_event );
if ( !occurrence_check.ok && !( is_change && change_kind == "occurrence_cancelled" && occurrence_check.code == "occurrence_cancelled" ) ) {
return deny( occurrence_check.code );
}
// ── time ────────────────────────────────────────────────────────────
// A reminder about something that has already started is not a reminder.
// A CHANGE notification is exempt: telling people an event was cancelled
// or moved is still useful right up to (and past) the original time.
if ( work_job.job_kind == "reminder" && isDate( occurrence_check.start_utc ) ) {
var all_day = ( cal_event.getIs_all_day() ?: false ) == true;
if ( wirebox.getInstance( "calendar_reminder_schedule_service" ).reminderTooLate( occurrence_check.start_utc, all_day ) ) {
return deny( "start_passed" );
}
// ...
}A denied job isn't failed. It's skipped with a stable reason code, and that status is terminal, so it keeps its identity too. Then the audience is resolved again from live membership, suspended and disabled members are dropped, quiet hours are applied per recipient, and per-channel opt-in is decided by the Communication pipeline, where a missing preference row means the member opted out.
That last part has a consequence I'd want a client to understand: a rule that says "all members" reaches the members who opted in to schedule changes on that channel, not literally everyone. If zero members are eligible, the job is skipped as preference_disabled, which is accurate and which an administrator would reasonably find surprising.
Everyone reads their own clock
The first version of the schedule-change email went to production and said this:
Start: was 2026-08-25T13:00:00Z, now 2026-08-25T13:15:00ZThat is a correct statement of fact. It's also an email sent to a volunteer who wanted to know whether to leave the house at 9:00 or 9:15. Reminders had a subtler version of the same bug: they were formatted in the event's zone, so a member in Vancouver was told a Halifax clock time, with a Halifax zone label, which is accurate and no help to anyone.
The fix has one rule: a notification renders in the recipient's clock, in the recipient's language. Not the event's zone, not the server's.
// A timed occurrence, in the MEMBER's zone - not the event's. Two
// members in one language and two provinces get two correct times.
var start_utc = arguments.job.occurrence_start_utc;
var long_label = locale_date_service.formatInstantWithMask(
utc_date = start_utc,
zone_iana = presentation.zone,
date_format_mask = presentation.mask,
language_code = language_code,
include_time = true,
include_zone = true
);
var short_label = locale_date_service.formatInstantWithMask(
utc_date = start_utc,
zone_iana = presentation.zone,
date_format_mask = presentation.mask,
language_code = language_code,
include_time = true,
include_zone = false
);
return { short_label: short_label, long_label: long_label };And the fallback chain is deliberate about what happens when a member hasn't told me anything:
private struct function presentationFrom( required struct job, required struct context ) {
var zone = locale_date_service.normalizeZoneId( arguments.context.recipient_timezone ?: "" );
if ( !len( zone ) ) {
zone = locale_date_service.normalizeZoneId( arguments.job.event_timezone_iana ?: "" );
}
if ( !len( zone ) ) zone = "UTC";
var mask = locale_date_service.normalizeDateMask( arguments.context.recipient_date_format ?: "" );
if ( !len( mask ) ) mask = locale_date_service.defaultDateMask();
return {
zone: zone,
mask: mask,
language: toString( arguments.context.language_code ?: "" )
};
}The member's own zone, then the event's zone, then UTC as a last resort. All-day dates are never zone-converted at all. A date is a date.
The email that was sent twice
This one came out of an independent review, and it's a lovely bug because every individual piece was correct.
The first localized version resolved each recipient's language from their live preferences on every delivery attempt, split the audience into one bucket per language, and used a deterministic idempotency key per bucket. Here's the failure, in the source's own words:
* This resolved each recipient's locale from LIVE preferences on every
* delivery attempt, partitioned the audience into locale buckets, and derived
* one Communication idempotency key per bucket:
*
* caljob:<job public id>:<locale>
*
* Deterministic - as long as nothing moves. Then:
*
* 1. the en-CA bucket sends successfully;
* 2. the fr-CA bucket hits a transient provider failure;
* 3. the job is finalized `retried` (correctly - stranding a language would
* be worse);
* 4. before the retry, one of the members who already received the English
* message changes their language to French. Or an administrator changes
* the club's primary website language, moving everybody who had expressed
* no preference;
* 5. the retry re-resolves live preferences. That member is now in the fr-CA
* bucket, whose idempotency key they were not part of;
* 6. `createSystemDraft` finds the fr-CA communication, `queueSend` sees no
* recipient row for them, and creates one;
* 7. they are told the same thing twice.
*
* Sorting the buckets does not fix this and never could: the ordering was never
* the mutable part. The INPUT was. The only fix is to stop re-deriving the
* answer.The fix is that a recipient's presentation (language, time zone, date format) is frozen into an assignment row before the first send attempt. A retry reads that row. It doesn't ask a member's current preferences again. And the bucket key carries a hash of the presentation, so it's still deterministic across retries and nodes:
var normalized = calendar_recipient_locale_service.normalize( arguments.bucket.locale ?: "" );
if ( !len( normalized ) ) {
return key;
}
key &= ":" & normalized;
// LEGACY (pre-V154) buckets stop here, and that is the whole
// compatibility story: their key is byte-identical to the one V151
// produced, so a job that was part-delivered across the deploy resolves
// to the communication it already has instead of minting a second one.
if ( ( arguments.bucket.legacy ?: false ) == true ) {
return key;
}
// Everything else carries a presentation discriminator. It is HASHED,
// not spelled out: a timezone and a date-format choice are the
// recipient's own settings, and an idempotency key is written to a
// communication row and read by operators. The hash is stable, so the
// key is still deterministic across retries and across nodes.
var material = toString( arguments.bucket.timezone ?: "" ) & "|" & toString( arguments.bucket.date_format ?: "" );
return key & ":p1-" & lCase( left( hash( material, "SHA-256" ), 12 ) );"Idempotency" is a promise about inputs. If any input to the key is read live, the promise belongs to somebody else's settings page.
A change notice is a snapshot
Now the other kind of message. Here's the path from "administrator clicks Save" to "somebody's phone buzzes", and every arrow in it is a place I decided to say no:
Admin saves the event form, with "notify recipients" ticked
|
v processUpdate
1. capture the event's state BEFORE (the server reads it; the client sends no diff)
2. validate, apply, UPDATE guarded by row_version -> stale? stop
3. reconcile reminders (always, inline, never fails the save)
4. maybeNotifyChange
notify flag not an explicit yes ............ nothing is queued
invalid channels / audience ................ "not told"
re-read the event AFTER the write
diff BEFORE vs AFTER over a fixed field list . nothing changed -> nothing queued
approve:
emergency stop engaged ................... refused before anything is stored
key already approved (double click) ...... "already_approved"
ONE transaction: write the snapshot, claim the approval identity
one job per channel, due now
|
v within a minute: the drain claims due jobs
resolve live state, re-authorize, re-resolve audience, freeze presentation,
render each bucket, create the communication, send, finalizeTwo things in that diagram carry most of the weight.
The diff is computed by the server, from two reads of its own. The browser never tells me what changed. A fixed list of meaningful fields is compared, and a change to a field not on the list (the description, a banner, a slug) produces no notice at all. "Nothing changed" is a valid answer, and the answer is to send nothing.
The approval has an identity. A key is built from the event, the occurrence, the kind of change, the before and after values, the actor, and the event's publication revision:
// publication_revision increments on every published edit, so it is
// IDENTICAL for a retry or a second node (the edit already committed
// before either asked) and DIFFERENT for a later re-approval. It is a
// small integer, not an identifier, so it leaks nothing.
//
// Optional and defaulted to 0 so the Phase 7 callers that pass four
// arguments still produce a stable key.
var material = arguments.event_public_id
& "|" & trim( arguments.occurrence_key )
& "|" & toString( arguments.diff.notification_kind ?: "" )
& "|" & toString( arguments.diff.change_fields ?: "" )
& "|" & stableJson( arguments.diff.before_values ?: {} )
& "|" & stableJson( arguments.diff.after_values ?: {} )
& "|" & trim( arguments.actor_user_id )
& "|r" & int( val( arguments.publication_revision ) );
return "calchg:" & lCase( hash( material, "SHA-256" ) );That |r at the bottom is a scar. Before it, the key was a hash of the diff and the actor. So move a game from 2 p.m. to 3 p.m., then back to 2, then to 3 again, and the third notification has the same key as the first. For 365 days. Then I made identities durable, which would have made it forever, and the third move would have been permanently unannounceable. A retry and a second node share a revision, because the edit committed before either asked. A later, deliberate re-approval doesn't.
Immutability is a database fact
Once approved, a snapshot must not change. An edit made after approval can't be allowed to rewrite a message that was already authorized. I don't enforce that with a column called locked and a promise. I enforce it in the database:
CREATE OR REPLACE FUNCTION public.calendar_change_notification_immutable() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF (
NEW.public_id IS DISTINCT FROM OLD.public_id
OR NEW.group_id IS DISTINCT FROM OLD.group_id
OR NEW.organization_id IS DISTINCT FROM OLD.organization_id
OR NEW.calendar_id IS DISTINCT FROM OLD.calendar_id
OR NEW.calendar_event_id IS DISTINCT FROM OLD.calendar_event_id
OR NEW.event_public_id IS DISTINCT FROM OLD.event_public_id
OR NEW.occurrence_key IS DISTINCT FROM OLD.occurrence_key
OR NEW.occurrence_stamp IS DISTINCT FROM OLD.occurrence_stamp
OR NEW.notification_kind IS DISTINCT FROM OLD.notification_kind
OR NEW.change_fields IS DISTINCT FROM OLD.change_fields
OR NEW.before_values IS DISTINCT FROM OLD.before_values
OR NEW.after_values IS DISTINCT FROM OLD.after_values
OR NEW.publication_revision IS DISTINCT FROM OLD.publication_revision
OR NEW.audience_type IS DISTINCT FROM OLD.audience_type
OR NEW.audience_payload IS DISTINCT FROM OLD.audience_payload
OR NEW.channels IS DISTINCT FROM OLD.channels
OR NEW.idempotency_key IS DISTINCT FROM OLD.idempotency_key
OR NEW.approved_by_id IS DISTINCT FROM OLD.approved_by_id
OR NEW.approved_at IS DISTINCT FROM OLD.approved_at
) THEN
RAISE EXCEPTION
'calendar_change_notification is immutable after approval; only status and accounting columns may change'
USING ERRCODE = '23514';
END IF;
RETURN NEW;
END;
$$;
DROP TRIGGER IF EXISTS calendar_change_notification_immutable_trg ON public.calendar_change_notification;
CREATE TRIGGER calendar_change_notification_immutable_trg
BEFORE UPDATE ON public.calendar_change_notification
FOR EACH ROW EXECUTE FUNCTION public.calendar_change_notification_immutable();I want to be careful about what that proves, because I've made the mistake of overclaiming it. The row is immutable. The diff lines in the email (which field, what it was, what it became) come from that row, so they can't change after approval.
The subject line, the heading and the link slug are not in the snapshot. They're read from the live event at send time:
return {
language_code: language_code,
event_title: effectiveTitle( arguments.job, arguments.cal_event ),
event_slug: toString( arguments.cal_event.getSlug() ?: "" ),
location_name: effectiveLocation( arguments.job, arguments.cal_event ),So if an administrator renames the event between approval and a quiet-hours-deferred delivery, the message shows the new title in its subject and the approved transition in its body. That's a real, small gap between "the snapshot is immutable" and "the email is." I'm telling you so you don't write "immutable" in your own design document and mean the email.
Exactly once is a lie, and here is the closest I got
I keep saying "once". The honest version is: each identity is created at most once, forever, and each delivery of it is attempted under a lease that fences stale workers. The hard part is the word "forever", because I also have a retention job that deletes old rows.
Look at what I've just described. Idempotency is carried by the presence of the job row, via the unique index. Retention deletes sent jobs after 180 days. So the day retention deletes a sent reminder's row, it deletes the guarantee. A bug with a delay fuse, set to go off six months after the thing it breaks.
My first fix was a tombstone: before deleting a job, write down its identity somewhere permanent. My second was a BEFORE INSERT trigger that read the tombstone and refused a re-created identity. It passed review and it passed its tests. And then, in the next migration's header, I wrote this:
-- V151 claimed that a BEFORE INSERT trigger reading calendar_notification_
-- tombstone made the identity guarantee atomic. It does not, because the
-- trigger and the unique index that the INSERT actually collides with do not
-- share a snapshot, and the trigger runs FIRST and ONCE.The race is the kind you can only find by running two sessions at once. Retention inserts a tombstone and deletes the job, and holds its transaction open. Materialization inserts a replacement. The trigger can't see an uncommitted tombstone, so it passes. The insert then waits on the unique index for the retention transaction to finish, and when that commits, PostgreSQL re-checks the index, finds no conflict, and doesn't run the BEFORE trigger again. The result: one committed tombstone and one live pending job, for the same identity. It was reproduced deterministically with two backends. The test I'd written for the earlier version ran the same steps sequentially, on one connection.
The fix was to stop reading the answer and start claiming it. Every identity gets a row in a permanent ledger. A unique index on the ledger decides who owns it, and FOR UPDATE waits out an in-flight promotion and then reads the latest committed state. Neither depends on a snapshot:
FOR v_try IN 1..3 LOOP
INSERT INTO public.calendar_notification_identity (
identity_key, job_kind, state, group_id, organization_id,
calendar_event_id, recipient_user_id
) VALUES (
v_key, NEW.job_kind, 'live', NEW.group_id, NEW.organization_id,
NEW.calendar_event_id, NEW.recipient_user_id
)
ON CONFLICT ( identity_key ) DO NOTHING
RETURNING state INTO v_state;
-- We created it. Nobody else can now, and we hold the row.
EXIT WHEN v_state IS NOT NULL;
-- Somebody holds it. FOR UPDATE waits out any in-flight promotion and
-- then reads the LATEST committed version, which is the whole point.
SELECT i.state INTO v_state
FROM public.calendar_notification_identity i
WHERE i.identity_key = v_key
FOR UPDATE;
EXIT WHEN FOUND;
-- Vanished between the two statements: only a tenant purge does that.
-- Loop and claim it again.
v_state := NULL;
END LOOP;
IF v_state IS NULL THEN
RAISE EXCEPTION 'calendar_notification_identity_unresolved'
USING ERRCODE = 'unique_violation',
HINT = 'The identity ledger row for this notification could neither be claimed nor read. Refusing the insert rather than risking a duplicate delivery.';
END IF;
IF v_state = 'spent' THEN
RAISE EXCEPTION 'calendar_notification_identity_tombstoned'
USING ERRCODE = 'unique_violation',
HINT = 'This notification identity has already reached a terminal state and been pruned. Re-creating it would re-deliver.';
END IF;The rest is an ordering rule rather than code: every path touches the identity ledger before it touches the job table. Retention marks an identity spent first, and only then deletes the job. If the process dies between those steps, the identity is spent and the job still exists, which is safe. The reverse order is the one that sends a message twice.
Note the shape of both failure branches. If the ledger row can't be claimed or read, the insert is refused. If it's already spent, the insert is refused. I don't have a branch that says "assume it's fine."
The scheduler that has to phone itself
A small, strange one, because every ColdFusion developer eventually meets it.
The reminder drain is a scheduled task. A scheduled task runs in the scheduler's executor thread, where cfmail throws, because the response facade it expects has been recycled. The mail has to be sent from inside a real servlet request.
So every minute, the scheduler makes an HTTP request to itself:
cfhttp( method = "POST", url = "http://127.0.0.1/system/calendar-notification-drain", timeout = "90", result = "local.calendar_drain_res" ) {
cfhttpparam( type = "header", name = "Host", value = "app.rosterli.com" );
cfhttpparam( type = "header", name = "X-Rosterli-Drain-Token", value = ( isNull( drain_token ) ? "" : drain_token ) );
}It's a loopback call with a shared-secret header, and a Host header so the application resolves to the right site. It's ugly, and every part of it is there for a reason I learned the hard way. The endpoint is token-gated and loopback-only, and it writes its own JSON, because ColdFusion can throw a bizarre error after a handler has returned, turning a successful send into a 500 for the caller.
Delivered, allegedly
I'll end with the one that cost the most trust, because I'd like you to avoid it.
ColdFusion's cfmail has a spool. With the spool enabled, which is the engine default, cfmail writes the message to disk and returns success. Actual SMTP delivery happens later on a spooler thread. If that fails, the file is moved to an undelivered folder and never retried. ColdFusion has no redelivery. The caller is told nothing.
Every caller in my code treated "the include returned" as "the message was sent", and several wrote that to the database. A reminder could be recorded as delivered, counted as delivered in the operator diagnostics, and tombstoned as spent by retention, while sitting undelivered on a disk. I found 84 real customer messages that had dead-lettered across both nodes over five days, after the mail provider answered the spooler thread with a timeout. Every sampled file was a sign-in link.
The spool now defaults to off, and the comment above that default is the whole post-mortem:
// ── Delivery is SYNCHRONOUS by default, and that is a correctness contract ──
// WHY: with ColdFusion's spool enabled (the engine default), <cfmail> only
// writes the message to {cf}/Mail/Spool and returns success. Real SMTP
// delivery happens later on the engine's own MailSpooler thread, and if it
// fails the file is moved to {cf}/Mail/Undelivr and NEVER RETRIED - ColdFusion
// has no redelivery. The caller is told nothing.// The spool is a LATENCY-HIDING mechanism, not a resilience one - it retries
// nothing - so disabling it forfeits only asynchrony and buys back a truthful
// success signal plus the retry the application already implements.
//
// A caller that genuinely wants fire-and-forget must ask for it explicitly with
// `mail_payload.spool = true` and must not record the result as delivered.
local.mail_spool = ( structKeyExists( local.mail_message, "spool" ) && isBoolean( local.mail_message.spool ) )
? local.mail_message.spool
: false;
local.mail_spool_attribute = local.mail_spool ? "true" : "false";The monitoring fix is the one I'd copy. There's now an alert on undelivered mail, and its threshold is one. Not "more than ten." One. A tolerance band is exactly what let 84 of them accumulate unnoticed.
What I'd keep
- A reminder is configuration; a change notice is a decision a person made. Never let a machine make the second one.
- Don't generate the season. Materialize on a rolling horizon, and refuse a stale reminder instead of sending it late.
- Job identity is the original slot. Edits move the row; sent rows keep their identity.
- Materializing is not authorizing. Re-read the live state at send time, and let denial be terminal.
- Render in the recipient's clock and language. Freeze that before the first attempt.
- Idempotency is a promise about inputs. If an input is read live, it isn't a promise.
- Don't read the guarantee, claim it. A trigger that reads can be raced. A unique index plus a row lock can't.
- If you delete the row that carried a guarantee, you've deleted the guarantee.
- "The function returned" is not "the message was delivered". Make your success signal truthful, and alert at one.
Next, the last part: what it takes to run this thing, how I count every query it makes, and the list of features I decided not to build.
