notifications: render date placeholders deterministically - #235
Open
constkolesnyak wants to merge 1 commit into
Open
notifications: render date placeholders deterministically#235constkolesnyak wants to merge 1 commit into
constkolesnyak wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 moduletests/test_notification_date_render.py— unit testsWhy
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).