mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -2280,7 +2280,9 @@ WHERE chat_id = @chat_id::uuid
|
||||
-- name: AutoArchiveInactiveChats :many
|
||||
-- Archives inactive root chats (pinned and already-archived chats skipped),
|
||||
-- cascading to children via root_chat_id. Limits apply to roots, not total
|
||||
-- rows. Used by dbpurge.
|
||||
-- rows. The Go caller passes @archive_cutoff as UTC midnight so that all
|
||||
-- chats sharing the same last-activity date are archived together.
|
||||
-- Used by dbpurge.
|
||||
WITH to_archive AS (
|
||||
SELECT
|
||||
c.id,
|
||||
@@ -2298,6 +2300,7 @@ WITH to_archive AS (
|
||||
WHERE c.archived = false
|
||||
AND c.pin_order = 0
|
||||
AND c.parent_chat_id IS NULL -- roots only
|
||||
-- Redundant filter helps the planner use the partial index on created_at.
|
||||
AND c.created_at < @archive_cutoff::timestamptz
|
||||
-- New active statuses must be added here to prevent archiving.
|
||||
AND c.status NOT IN ('running', 'pending', 'paused', 'requires_action')
|
||||
|
||||
Reference in New Issue
Block a user