Retention
How long messages, attachments and other records are kept, and how they are cleaned up.
Decided Messages are kept for 30 days by default. Each project can set its own retentionDays from 1 to 365 (RETENTION_DAYS in packages/contract/src/project.ts).
Rules
| Record | Kept until |
|---|---|
| Message | expiresAt, set at publish time from the project's retention |
| Responses and read state | Deleted with their message |
| Attachment file | Deleted with its message |
| Uploaded attachment never used in a message | 1 hour after upload |
| Accepted, expired or revoked invite | 30 days after it ends |
| Device not seen | 60 days after lastSeenAt |
| Expired access token | Kept, so it still shows as expired in the token list |
Changing a project's retention affects only new messages. Existing messages keep the expiresAt they were published with, so a mistaken setting never wipes history.
Cleanup job
A Cron Trigger (0 * * * *) runs the cleanup every hour. It is set in apps/server/wrangler.jsonc for local dev and in packages/infra/alchemy.run.ts for deploys, and calls the scheduled export of the server Worker. The cleanup itself is runRetention(db, { now }) in packages/api/src/retention.ts.
Open Attachments do not exist yet, so the file steps below are not implemented. The job deletes expired messages, old invites and stale devices only.
Find expired messages
Select a batch of up to 500 messages where expires_at < now, using the expires_at index.
Delete files first
Delete their R2 objects. If deleting a file fails, its message stays and the next run tries again, so no row ever points to a missing file.
Delete rows
Delete the messages; responses and read state cascade. Repeat until nothing is expired or the run's time budget (20 seconds) is used up; the next run continues where this one stopped.
Sweep the rest
Delete orphaned uploads, old invites and stale devices, also 500 at a time and within the same 20-second budget. Invites and devices are found without an index: there are only a few per user.
The apps and the API never show a message past its expiresAt, even if cleanup has not run yet.