Repository navigation
fix(reminders): skip reminders whose time has already passed - #277
dominik-myszkowski wants to merge 1 commit into
Conversation
…#266) enqueueReminder and replaceReminderJobs clamped a past run_at to now, so a booking made 5 hours out with reminders [24, 2] got the 24-hour reminder right next to the confirmation email, saying "tomorrow" for a meeting that afternoon. A reschedule onto a nearer slot had the same problem. Both paths now go through reminderRunAt: a reminder due more than reminderGrace (5 min) ago is skipped, one inside the grace window still runs now, to absorb clock skew and job timing.
There was a problem hiding this comment.
ℹ️ No defects found — one informational note on how far the documented guarantee reaches.
Approach: sound — the decision is made once, at the enqueue seam that every create and reschedule path already funnels through (dispatchBookingConfirmation / rescheduleSideEffects), and the 5-minute grace window keeps a reminder that is only just late from being dropped.
Reviewed changes
reminderRunAthelper — one pure function owns both the skip and the clamp-to-now decision, so create and reschedule cannot drift;TestReminderRunAtpins both sides of the grace edge.- Create path —
enqueueReminderbails out before writing the job when the reminder moment is dead, which also covers the[24]fallback used by event types with no reminder list. - Reschedule path —
replaceReminderJobskeeps its delete-then-insert shape butcontinues past skipped entries, and I confirmed all three reschedule entry points (REST, MCP, manage token) reach it. - Docs and tests —
ARCHITECTURE.md§12 describes the new default, and the two integration tests assert the exact remaininghours_beforeset rather than just "a job exists".
ℹ️ The new doc sentence promises a guarantee the worker does not enforce
The bullet added at docs/ARCHITECTURE.md:779 reads as a property of the system ("A reminder whose moment passed more than reminderGrace ago is skipped, not sent at once"), but the skip exists only at enqueue time. sendReminder sends every pending job whose run_at <= now and never looks at start_at, so a job that was enqueued on time and then waited out downtime (or a long queue stall) is still delivered — potentially after the meeting has ended. Either scope the sentence to scheduling, or add the mirror guard on the send side so the documented behaviour is actually true.
Technical details
# Reminder staleness after downtime
## Affected sites
- `internal/worker/worker.go:290` — `sendReminder` loads `b.start_at` but only parses it for `d.StartAt`; no past-start check before `mailer.SendReminder`.
- `internal/worker/worker.go:192` — poll selects `status = 'pending' AND run_at <= ?` with no age bound, so an arbitrarily old reminder is claimed on the first poll after a restart.
- `docs/ARCHITECTURE.md:779` — the added sentence states the skip as a system-wide guarantee.
## Required outcome
- Either the ARCHITECTURE wording is limited to what the change enforces (skipped at scheduling, not at delivery), or the worker suppresses a reminder whose booking has already started and marks the job done so it does not retry.
- If a guard is added, it must not regress the "keep sending after a brief worker hiccup" case that exists today for reminders that fire a few minutes late.
## Open questions for the human
- Is the post-downtime late send intended to stay as-is (#266 scope), or does it want the same treatment in a follow-up?deepseek-v4.1-flash | 𝕏

Implements #266: a reminder whose time has already passed is skipped instead of sent straight away. As agreed there, this is the default, with no setting.
What it does
reminderRunAt(startAt, hoursBefore, now)inbooking_handler.go, used by bothenqueueReminder(create) andreplaceReminderJobs(reschedule via API, MCP and the manage page, which all go throughrescheduleSideEffects).reminderGrace(5 min) ago is skipped. One inside the grace window still runs now, so clock skew and job timing don't drop a reminder that is only just late.[24, 2]now gets only the 2-hour reminder. The confirmation email covers the rest.docs/ARCHITECTURE.md§12: a short note next to "Reminders: scheduled asjobs".The worker side is unchanged: a job that was enqueued on time and is picked up late (e.g. after downtime) is sent as before. This only changes what gets enqueued.
Tests
TestCreateBooking_skipsReminderAlreadyPast: reminders[24, 2], booking 5–6 h ahead → only the 2-hour job is enqueued.TestRescheduleBooking_skipsReminderAlreadyPast: a booking 10 days out has both jobs; after moving it 5–6 h ahead, only the 2-hour job is left.TestReminderRunAt: table test for the helper, including both sides of the grace edge.I checked that both integration tests fail without the fix (
map[2:true 24:true]).gofmt,go vet ./...,go build ./...,go test ./...andgo run ./cmd/i18n-coveragepass locally. There are no UI or i18n changes, so I didn't run the pnpm steps.