Files
coder/docs/ai-coder/agents/platform-controls/chat-retention.md
T
Cian Johnston a876287d36 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.

> 🤖
2026-04-24 14:18:28 +01:00

2.3 KiB

Conversation Data Retention

Coder Agents automatically cleans up old conversation data to manage database growth. Archived conversations and their associated files are periodically purged based on a configurable retention period.

Conversations become eligible for purging only after they are archived. Old conversations can be archived manually, or automatically. See Auto-Archive for how the two controls interact.

How it works

A background process runs approximately every 10 minutes to remove expired conversation data. Only archived conversations are eligible for deletion — active (non-archived) conversations are never purged.

When an archived conversation exceeds the retention period, it is deleted along with its messages, diff statuses, and queued messages via cascade. Orphaned files (not referenced by any active or recently-archived conversation) are also deleted. Both operations run in batches of 1,000 rows per cycle.

Configuration

Navigate to the Agents page, open Settings, and select the Behavior tab to configure the conversation retention period. The default is 30 days. Use the toggle to disable retention entirely.

The retention period is stored as the agents_chat_retention_days key in the site_configs table and can also be managed via the API at /api/experimental/chats/config/retention-days.

What gets deleted

Data Condition Cascade
Archived conversations Archived longer than retention period Messages, diff statuses, queued messages deleted via CASCADE.
Conversation files Older than retention period AND not referenced by any active or recently-archived conversation

Unarchive safety

If a user unarchives a conversation whose files were purged, stale file references are automatically cleaned up by FK cascades. The conversation remains usable but previously attached files are no longer available.