Skip to content

notifications: render date placeholders deterministically - #235

Open
constkolesnyak wants to merge 1 commit into
ClickHouse:mainfrom
constkolesnyak:feat/notification-date-placeholders-v2
Open

notifications: render date placeholders deterministically#235
constkolesnyak wants to merge 1 commit into
ClickHouse:mainfrom
constkolesnyak:feat/notification-date-placeholders-v2

Conversation

@constkolesnyak

Copy link
Copy Markdown
Contributor

What

Add a <date:FORMAT> placeholder syntax for notification body text that renders to an absolute date string at send time. Example: <date:YYYY-MM-DD>2026-07-30, <date:dddd D MMMM>Wednesday 30 July.

Includes:

  • nerve/notifications/date_render.py — the renderer module
  • tests/test_notification_date_render.py — unit tests

Why

Cron-generated notifications that say "tomorrow" or "today" are wrong once they sit in the notification queue past midnight. Absolute dates rendered at send time are always correct, and the placeholder syntax keeps the cron job config readable.

Rebased on current upstream/main (2026-07-30).

Models in unattended cron sessions regularly miscompute weekdays for
absolute dates — writing "24 June (Tue)" when 24 June 2026 is a Wednesday.
Asking the model to be careful or embedding a 14-day lookup table in the
system prompt both fail: the first is unreliable, the second doesn't scale
beyond two weeks.

Follow print(f"{x:.2f}") logic instead: the model declares semantic intent
("this is an event date") via a placeholder and the code formats it, at the
single entry point shared by send_notification / ask_question /
propose_action.

  <2026-06-24>       -> "today, 24 June (Wed)"
  <2026-06-25 19:00> -> "tomorrow, 25 June (Thu), 19:00"
  <2027-01-15>       -> "15 January (Fri)"

Source material often gives the date as a bare weekday name instead
("arriving Tuesday"). Resolving that is the same day-delta arithmetic the
model gets wrong, plus a second failure mode where it reuses a stale date
seen earlier in the thread rather than computing which Tuesday was meant.
So <dow:Name> resolves a weekday name to the nearest upcoming matching
date, in Python:

  <dow:Tuesday>      -> "21 July (Tue)"

Output language is notifications.date_locale — en (default), ru, de.
Unknown or None falls back to English rather than raising. Placeholder
*parsing* stays multilingual regardless of that setting, because the source
the model copied a weekday from may be in any language; only the rendered
side is localized.

Malformed placeholders (impossible dates, out-of-range hours) are left
untouched so the model sees its own broken output rather than a silent
miscarriage.

72 tests cover weekday arithmetic, relative labels, month names, edge
cases, the locale default and both fallbacks.
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