Skip to content

Notices: same-day expiry never takes effect (ISO vs datetime('now') string compare) #1024

Closed

Description

@neuromechanist

Summary

A notice with an expires_at later today keeps being served as active until the next calendar day (UTC). Expiries on a previous date work correctly, so this looks like it works most of the time.

Root cause

expires_at is stored in ISO-8601 with a T separator, because POST /admin/notices validates it with z.string().datetime({ offset: true }) (backend/src/routes/admin/notices.ts:32) and createNotice binds the value through unnormalized (backend/src/services/notices.ts:79).

getActiveNotices then filters with:

WHERE (expires_at IS NULL OR expires_at > datetime('now'))

datetime('now') emits YYYY-MM-DD HH:MM:SS — a space separator, no Z. Both sides are TEXT, so this is a byte comparison under the default BINARY collation. T is 0x54, space is 0x20, so whenever the date portions are equal the ISO value always compares greater and the notice is treated as unexpired.

Verified:

sqlite3 :memory: "SELECT '2026-07-25T00:00:00.000Z' > '2026-07-25 09:00:00';"  -- 1  (expired, reported active)
sqlite3 :memory: "SELECT '2026-07-24T00:00:00.000Z' > '2026-07-25 09:00:00';"  -- 0  (correct)

The first row is a notice that expired at midnight still being served at 09:00.

Impact

Bounded but real: an expired notice keeps showing to CLI users (and to GET /notices consumers) for the remainder of the UTC day. It self-corrects at the next date rollover, which is probably why it hasn't been noticed. A same-day "maintenance window ends at 14:00" notice is exactly the case that misbehaves.

Worth noting the CLI already sidesteps this: src/commands/admin.ts:5334 computes expiry client-side with new Date(notice.expires_at) < new Date() rather than trusting the server's filter, so nemar admin notices list disagrees with what GET /notices actually serves.

Suggested fix

Either normalize on write so the stored format matches what SQLite's date functions emit:

INSERT INTO notices (..., expires_at) VALUES (..., datetime(?))

or compare in the same format as the stored value:

WHERE (expires_at IS NULL OR expires_at > strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))

Normalizing on write is the sturdier of the two — it also makes the existing idx_notices_expires index comparisons well-defined — but it needs a backfill for rows already stored in ISO form.

Found via

Scoping the website admin portal's notices tab (nemarOrg/website epic #158 Phase 5). The website will compute expiry client-side in its admin list for the same reason the CLI does, so admins see the true state regardless of which fix lands.

Activity

  1. added
    bug
    on Jul 25, 2026
  2. neuromechanist commented on Jul 25, 2026

    @neuromechanist
    ContributorAuthor

    Merged to dev in #1027 (a93d330). Closing by hand — Closes #N doesn't fire for PRs merged into a non-default branch.

    Fixed by normalizing expires_at on write (datetime(?) plus migration 0064 to backfill) so the comparison against datetime('now') is like-for-like, and projecting both timestamps back as explicit-UTC RFC3339 so no JS consumer parses them as local time.

    Reaches production when dev is promoted to main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions