Skip to content

fix(reminders): skip reminders whose time has already passed - #277

Open
dominik-myszkowski wants to merge 1 commit into
Calnode:mainfrom
dominik-myszkowski:fix/skip-past-reminders
Open

dominik-myszkowski wants to merge 1 commit into
Calnode:mainfrom
dominik-myszkowski:fix/skip-past-reminders

Conversation

@dominik-myszkowski

Copy link
Copy Markdown

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

  • New reminderRunAt(startAt, hoursBefore, now) in booking_handler.go, used by both enqueueReminder (create) and replaceReminderJobs (reschedule via API, MCP and the manage page, which all go through rescheduleSideEffects).
  • A reminder due more than 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.
  • A booking made 5 hours out with reminders [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 as jobs".

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 ./... and go run ./cmd/i18n-coverage pass locally. There are no UI or i18n changes, so I didn't run the pnpm steps.

…#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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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

  • reminderRunAt helper — one pure function owns both the skip and the clamp-to-now decision, so create and reschedule cannot drift; TestReminderRunAt pins both sides of the grace edge.
  • Create path — enqueueReminder bails 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 — replaceReminderJobs keeps its delete-then-insert shape but continues 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 remaining hours_before set 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?

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

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