fix: use UTC day boundaries for chat auto-archive eligibility (#25597)

Fixes CODAGT-311.

Users receive too many auto-archive notification emails because the
dbpurge loop runs every 10 minutes and archives chats on each tick using
timestamp-precise cutoffs, causing chats to trickle past the threshold
continuously.

Switch archive eligibility from timestamp arithmetic to date arithmetic
(UTC day boundaries). All chats whose last activity falls on the same
UTC date are now archived together on the first tick after midnight UTC,
reducing notification emails to ~at most~ probably one per day.
(Exception: if we hit the auto-archive limit)

- SQL compares `(last_activity AT TIME ZONE 'UTC')::date` against cutoff
date
- Go truncates current time to start-of-day before subtracting archive
days
- Tests verify date boundary semantics including late-activity and batch
edge cases
- Docs updated to describe UTC day boundary behavior and at-most-daily
notification cadence

> [!NOTE]
> Generated by Coder Agents
This commit is contained in:
Cian Johnston
2026-05-22 11:39:44 +01:00
committed by GitHub
parent 0ba702c43f
commit c8b1fa3196
6 changed files with 221 additions and 33 deletions
@@ -7,10 +7,13 @@ out of the separate retention window, at which point they are purged.
## How it works
A background process runs approximately every 10 minutes. On each tick
it scans the chat database for root conversations whose most recent
non-deleted message is older than the configured auto-archive window
and flips them from "active" to "archived". Cascaded children (chats
A background process periodically scans the chat database for root
conversations whose most recent non-deleted message predates the
configured auto-archive window and flips them from "active" to
"archived". Eligibility is evaluated at UTC day boundaries: all
conversations whose last activity falls on the same UTC date are
archived together on the first tick after midnight UTC following the
expiration of their archive window. Cascaded children (chats
linked into a larger conversation via `root_chat_id`) are archived
alongside their parent so the conversation stays coherent.
@@ -30,7 +33,12 @@ root.
When your chats are auto-archived, you receive a digest notification
listing the titles of the archived conversations and the
auto-archive window currently configured.
auto-archive window currently configured. Because eligibility uses
UTC day boundaries, in steady state this notification fires at most
once per day (on the first tick after midnight UTC that finds newly
eligible chats). A large backlog (initial enablement or bulk
inactivity) may span multiple ticks, producing multiple notifications
until the backlog drains.
If you find the digest noisy, you can disable the "Chats
Auto-Archived" notification entirely from your notification preferences.