feat: auto-archive inactive chats with audit trail (#24642)

Adds a background job in `dbpurge` that periodically archives chats
inactive beyond a configurable threshold. Each archived root chat gets a
background audit entry tagged `chat_auto_archive`. Disabled by default.

* New `AutoArchiveInactiveChats` SQL query with LATERAL last-activity
subquery and partial index on archive candidates
* `site_configs`-backed `auto_archive_days` setting with admin-only PUT,
any-authenticated-user GET
* Cascade archive via `root_chat_id`; pinned chats and active threads
exempt
* Root-only audit dispatch on detached context, matching manual archive
(`patchChat`) behavior
* 11 subtests covering disabled no-op, boundary, deleted messages, child
activity, pinned exemption, multi-owner, idempotency, and batch
pagination

PR #24643 adds per-owner digest notifications.
PR #24704 adds the requisite UI controls.

> 🤖
This commit is contained in:
Cian Johnston
2026-04-24 14:18:28 +01:00
committed by GitHub
parent 346b46228f
commit a876287d36
26 changed files with 1504 additions and 46 deletions
+25
View File
@@ -1291,6 +1291,14 @@ export interface ChatAgentModelOverrideResponse {
readonly is_malformed: boolean;
}
// From codersdk/chats.go
/**
* ChatAutoArchiveDaysResponse contains the current chat auto-archive setting.
*/
export interface ChatAutoArchiveDaysResponse {
readonly auto_archive_days: number;
}
// From codersdk/chats.go
export type ChatBusyBehavior = "interrupt" | "queue";
@@ -3403,6 +3411,14 @@ export interface DebugProfileOptions {
readonly Profiles: readonly string[];
}
// From codersdk/chats.go
/**
* DefaultChatAutoArchiveDays is the default auto-archive window, in
* days, applied when no site config row exists. Zero disables
* auto-archival.
*/
export const DefaultChatAutoArchiveDays = 0;
// From codersdk/chats.go
/**
* DefaultChatWorkspaceTTL is the default TTL for chat workspaces.
@@ -7685,6 +7701,15 @@ export interface UpdateChatAgentModelOverrideRequest {
readonly model_config_id: string;
}
// From codersdk/chats.go
/**
* UpdateChatAutoArchiveDaysRequest is a request to update the chat
* auto-archive period.
*/
export interface UpdateChatAutoArchiveDaysRequest {
readonly auto_archive_days: number;
}
// From codersdk/chats.go
/**
* UpdateChatDebugLoggingAllowUsersRequest is the admin request to