Skip to content

Unify CEL today() onto the UTC clock - #2914

Merged
mstomar125 merged 2 commits into
mainfrom
issue-2843-cel-today-mismatch
Sep 23, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-2843-cel-today-mismatch

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

today() read Local::now() (the host machine's local timezone) while days_since()/days_until() read Utc::now(). Near a day boundary, that means a condition like node.due_date == today() and days_until(node.due_date) == 0 — which read as equivalent to a Play author — could disagree, depending on the host's offset from UTC.

Change

  • today() now reads Utc::now(), matching days_since()/days_until(). All three CEL date functions now agree on the same clock.
  • Removed the now-unused chrono::Local import from packages/core/src/playbook/cel.rs.
  • Recorded the rationale as a doc comment at the function definitions: UTC was chosen over "make everything local" because a rule can run on any synced device, and there is no single "local" all devices could agree on — a UTC day boundary is the same instant everywhere, a local-calendar-day boundary is not. Documented trade-off: today() no longer matches a user's own calendar day exactly at the UTC boundary.
  • Updated architecture/playbook-system.md and architecture/playbook-engine.md in nodespace-docs (pushed directly to main per that repo's own workflow) to state the UTC clock explicitly for all three functions — playbook-engine.md was also stale, still describing today() as chrono::Local::now().

Tests

  • today_reads_the_utc_clock_not_the_host_local_clock — direct check that today()'s value matches an independently computed Utc::now() date, not local time.
  • today_and_days_until_zero_agree_on_the_same_clock / today_and_days_since_zero_agree_on_the_same_clock — pin the exact agreement the issue describes (days_until(today()) == 0 / days_since(today()) == 0), reproducing the Play-author scenario from the issue.
  • Manually re-ran the new tests under TZ=Pacific/Auckland (the timezone the issue's linked flake reproduced under) to confirm the fix holds outside UTC.

Closes #2843

Co-Authored-By: Claude Sonnet 5 [email protected]

mstomar125 and others added 2 commits September 23, 2026 14:36
today() read Local::now() while days_since()/days_until() read
Utc::now(), so a condition like `node.due_date == today()` and
`days_until(node.due_date) == 0` could disagree near a day boundary
depending on the host's timezone offset.

Make today() read Utc::now() too. UTC wins over local because a rule
can run on any device in a synced setup, and there is no single
"local" all devices could agree on; a UTC day boundary is the same
instant everywhere. The rationale is recorded as a comment at the
function definitions in cel.rs.

Adds tests pinning the agreement (days_until(today()) == 0,
days_since(today()) == 0) and a direct check that today() reads the
UTC clock, verified under a non-UTC TZ.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
- today_and_days_until_zero_agree_on_the_same_clock /
  today_and_days_since_zero_agree_on_the_same_clock evaluate
  `days_until(today())`/`days_since(today())`, which makes two
  unsynchronized Utc::now() reads. A UTC midnight tick landing between
  them would make a correct implementation observe a 1-day mismatch;
  retry once rather than accept that sub-microsecond-window flake.
- The UTC-clock rationale comment was a `///` doc comment with no
  blank line before `fn cel_days_since`, so rustdoc attached it to
  that function alone rather than as a standalone section comment,
  making cel_today()'s "see the module comment above" cross-reference
  misleading. Changed it to a plain `//` comment block and reworded
  the cross-reference.

Addresses reviewer recommendations from /pragmatic-code-review on
PR #2914 (both low severity).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Address Review

Ran `/pragmatic-code-review` (medium effort) on PR #2914. Both findings were low severity; addressed both:

  1. Flaky agreement tests — `today_and_days_until_zero_agree_on_the_same_clock` / `today_and_days_since_zero_agree_on_the_same_clock` evaluate a CEL expression that makes two unsynchronized `Utc::now()` reads (once in `today()`, once in `days_until`/`days_since`). A UTC-midnight tick landing in the microsecond gap between them would make even a correct implementation observe a 1-day mismatch. Fixed by retrying once on failure rather than accepting that sub-microsecond-window flake.
  2. Misleading doc cross-reference — the UTC-clock rationale block was written as a /// doc comment with no blank line before fn cel_days_since, so rustdoc attached it to that function alone rather than treating it as a standalone section comment. cel_today()'s "see the module comment above" reference was therefore inaccurate. Changed the block to a plain // comment and reworded the cross-reference.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: Both changes are low-risk, localized, non-functional fixes to test robustness and doc-comment accuracy within the same file already reviewed — no new logic, no architectural change, no new call sites. Full test suite (cargo test -p nodespace-core --lib playbook::cel::, 40/40 passing) and bun run quality:fix (clippy + fmt + full workspace) re-verified clean after the changes, and the pre-push gate (full test pyramid + cargo build --bin nodespaced + e2e) passed on push.

Ready for merge.

@mstomar125
mstomar125 merged commit 583c304 into main Sep 23, 2026
@mstomar125
mstomar125 deleted the issue-2843-cel-today-mismatch branch September 23, 2026 13:05
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.

Unify CEL's two definitions of "today": today() is local, days_since/days_until are UTC

1 participant