Skip to content

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

Closed

Description

@malibio

Overview

CEL exposes two different definitions of "today", and they disagree by up to a day depending on the host's timezone.

  • today() — Local::now() (packages/core/src/playbook/cel.rs:578)
  • days_since() / days_until() — Utc::now().date_naive() (packages/core/src/playbook/cel.rs:595)

A Play author has no way to know which function follows which clock. Two conditions that read as equivalent are not:

node.due_date == today()          // local
days_until(node.due_date) == 0    // UTC

East of UTC after local midnight, and west of UTC before it, these disagree.

Why this is worth fixing rather than documenting

Found as the root cause of a test flake in #2777: a fixture built a date from Utc::now() while the condition it fed used today(). The mismatch was invisible under the host timezone and reproduced deterministically under TZ=Pacific/Auckland. That instance was patched downstream, but the underlying inconsistency is still there for the next author.

The failure mode is bad: a Play works for months, then misfires for users in one hemisphere, on some days, with no error. Nothing in the condition text hints that two date functions disagree.

Not urgent

No shipped Play mixes the two. The Linear recipe uses today() only. This is a latent trap rather than a live bug.

Deciding which way to unify

Both directions are defensible and the choice has real consequences:

  • Local everywhere — matches what a user means by "today" when they look at a calendar. But cron scheduling and derived identity (ADR-074) reason about wall clock across devices, so a local-date rule fires at different absolute instants per device.
  • UTC everywhere — consistent across devices and sync, but today() would stop meaning the user's today, which is almost certainly what a Play author intends when they compare against a due_date a human typed.

Worth deciding deliberately rather than by whichever call site is edited next.

Acceptance Criteria

  • today(), days_since() and days_until() agree on which clock defines a date
  • The choice is recorded with its rationale (ADR or a comment at the definitions), including what it means for multi-device firing
  • A test pins the agreement — ideally one that fails under a non-UTC TZ if they diverge again
  • architecture/playbook-system.md's Built-in CEL Functions table states which clock applies

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions