Data retention
Every log the console writes ages out under one policy: model calls, tool and MCP calls, guardrail evaluations, Knowledge Engine and web search queries, agent traces, browser sessions, crawl results, batch and OCR items, alerts, usage totals and the audit log. A duration belongs to a data class, not to a table. The prompt stored with a model call is content and is cleared early. The call record itself is telemetry and is deleted later.
Every class has a built-in default, and every registered collection belongs to a class, so nothing is kept forever unless a policy says so.
Enterprise module
The retention engine runs in every edition, with the defaults below and the RETENTION_* environment variables. The Data retention screen, where you edit the policy, add project exceptions, clean on demand and read destruction records, is part of the enterprise edition. The page exists in the community build but shows an upgrade prompt. See Licensing.
Data classes
| Class | What it covers | Default | SaaS range before plan and operator caps | Expired rows are |
|---|---|---|---|---|
content | Prompts, responses, tool payloads, queries, extracted text, page bodies, screenshots | 30 days | 1–90 | redacted: the content fields are cleared and the row stays |
telemetry | Model, tool, MCP, guardrail, Knowledge Engine, reranker, web search and vector query logs | 90 days | 30–400 | deleted |
trace | Agent trace sessions and their events, trace threads, browser sessions and steps | 30 days | 7–180 | deleted |
jobs | Crawl results, batch and OCR items, browser flow runs, vector migration and re-index runs | 90 days | 30–365 | deleted (never while running) |
metrics | Inference server metrics, GPU fleet events | 45 days | 7–180 | deleted |
alerts | Resolved alerts, resolved or closed incidents | 180 days | 90–730 | deleted (never while open) |
audit | Audit log, config change log, MCP server change log | 365 days | 365–3650 | deleted |
usage | Daily usage totals (billing and the usage reports) | 760 days | 400–1095 | deleted |
results | Evaluation, red-team and analysis runs, cost prescription reports | 365 days | 90–3650 | deleted (never while running) |
delivery | Webhook and alert deliveries, scheduler claims | its own mechanism, see below | deleted | |
conversations | Chat history of agent sessions and portal chats, and the memory written from it | kept until the user deletes it (0) | 1–3650 | deleted |
On-premises deployments have no per-class maximum: editable classes can use the full valid range up to 3650 days unless an operator cap lowers it. Class minimums still apply.
conversations is product history, not a log: by default nothing expires and the user deletes a conversation themselves. A workspace policy or a project exception can set a number of days, counted from the conversation's last activity.
The audit trail is append-only: a workspace admin cannot purge it. A POST /api/retention/purge, or its preview, with audit in classes answers 400. Audit rows leave only through the retention duration of the class (never below RETENTION_AUDIT_MIN_DAYS) or through a purge the platform operator runs from the command line (npm run retention:purge, which only counts until --confirm <workspace slug> is given).
audit never goes below RETENTION_AUDIT_MIN_DAYS. The records retention leaves about its own deletions are kept for RETENTION_RECORDS_DAYS (three years by default), and nothing else can shorten that.
Presets
A workspace picks a starting point, then changes single classes if it needs to. The presets are engineering defaults, not legal advice.
The table shows the starting values. The screen and API clamp each preset to the tenant's current save bounds, including plan and operator caps, instead of suggesting an unsaveable number.
| Preset | content | telemetry | trace | jobs | metrics | alerts | audit | usage | results |
|---|---|---|---|---|---|---|---|---|---|
| Standard (the built-in defaults) | 30 | 90 | 30 | 90 | 45 | 180 | 365 | 760 | 365 |
| Minimal | 7 | 30 | 14 | 30 | 45 | 90 | 365 | 400 | 180 |
| EU AI Act high-risk | 30 | 180 | 180 | 180 | 45 | 365 | 365 | 760 | 3650 |
| Finance | 30 | 365 | 90 | 180 | 45 | 365 | 1095 | 1095 | 1095 |
EU AI Act high-risk keeps automatically generated logs for at least six months (art. 19, 26(6)) and evaluation results as technical documentation (art. 18). Check the effective preset against applicable obligations: a cap can lower these starting values.
Collections with their own mechanism
These were aged out before the central engine existed and keep their own mechanism. The retention page lists them with their default so every duration is in one place.
| Collection | Default | Set by |
|---|---|---|
agent_runs | 30 days | AGENT_RUN_RETENTION_DAYS |
agent_session_events | 30 days | AGENT_SESSION_EVENT_RETENTION_DAYS |
webhook_deliveries | 30 days | WEBHOOK_DELIVERY_RETENTION_DAYS |
agent_trigger_deliveries | 7 days | built in |
alert_deliveries | 30 days | built in |
scheduler_claims | at most 7 days | the expiry stored on each claim |
entity_metrics | 45 days | ENTITY_METRICS_RETENTION_DAYS |
| Agent session files | 30 days | each agent's attachments.retentionDays, bounded by the jobs cap after grace |
Gateway request metadata and captured content use their separate gateway retention settings, bounded by the telemetry and content caps respectively after grace. These settings are not gateway attachment retention.
How a duration is decided
The last of these that is set wins:
- the class default (table above);
- the deployment default,
RETENTION_<CLASS>_DAYS(for exampleRETENTION_TELEMETRY_DAYS=180); - the workspace policy;
- a project exception.
The result is then bounded by the class minimum and deployment ceiling, any operator cap (RETENTION_<CLASS>_MAX_DAYS), and the plan cap in force. SaaS licences can carry plan.limits.retention.<class>. On-premises deployments do not apply hosted plan caps or the SaaS class maximum; the valid upper bound remains 3650 days. An operator cap only lowers the applicable ceiling and cannot override a class floor.
Project exceptions. A project can keep a class longer or shorter than the rest of the workspace, for example a regulated project that keeps telemetry for a year, but cannot exceed the effective cap. Rows with no project follow the workspace duration.
Shortening waits. A policy save that would make anything expire sooner keeps the old number for RETENTION_SHORTEN_DELAY_HOURS (24 by default). The new policy shows as pending and can be cancelled until then. Lengthening applies at once. This delay is separate from the cap grace below.
Cap enforcement and downgrade grace
A newly observed or lower plan cap waits RETENTION_PLAN_DOWNGRADE_GRACE_DAYS (14 days by default) before it bounds workspace and project retention at runtime. An increased plan cap applies at once. Policy saves and presets are checked against the current licensed cap even while a lower cap is pending. Operator caps over the central policy apply directly; they do not receive the plan downgrade grace.
Gateway request/content settings and agent session-file settings previously had no such cap. Their first observed cap, and later lower caps, go through the same grace before their separate sweepers limit retention. This includes their class ceiling, operator cap and plan cap. Existing higher saved gateway or agent values remain editable: leaving a value unchanged or lowering it is allowed, even if it remains above the new cap. New values or increases must satisfy the cap. After grace, the sweep uses the cap even if the stored setting remains higher; a manual reduction is not a prerequisite for enforcement.
A further cut during a running grace keeps that grace's deadline. A new downgrade after the previous grace has expired starts a new grace period. Review pending caps and expected deletions before enforcement; raising a cap does not restore data already deleted.
How it runs
The engine runs on the queue provider: BullMQ when Redis is configured, the in-process queue otherwise. No database TTL index is involved. Every RETENTION_INTERVAL_SECONDS, one tick per cluster queues one sweep per tenant.
A sweep works through the tenant's collections in batches of RETENTION_BATCH_SIZE and for at most RETENTION_BUDGET_SECONDS, then queues its own continuation. Deletes run before redactions. A per-tenant lock in the cache keeps two sweeps, or a sweep and a manual purge, off the same tenant.
Redaction remembers how far it got (a watermark in the cache), so each sweep only looks at newly expired rows. Rows that arrive late with an old timestamp are left to the delete phase.
Check enforcement before upgrading
The central engine defaults to RETENTION_DRY_RUN=true, but operators can already have enabled enforcement globally or for selected classes or tenants. The independent gateway and agent-file sweepers have their own runtime behavior. Do not assume that a dry-run central engine makes every retention mechanism inactive. Review active enforcement and pending caps before rollout. A manual purge (Clean now) always acts.
Turn deletion on safely
Run the inventory. It is read-only and works on MongoDB and SQLite:
bashnpm run retention:inventory npm run retention:inventory -- --tenant <slug-or-dbName> npm run retention:inventory -- --jsonIt lists, per workspace and per collection, the row count and what the current policy would delete or redact now. For disk size use
npm run report:data-footprint.Review the numbers, plan caps and pending grace deadlines. Adjust the policy or the
RETENTION_<CLASS>_DAYSdefaults if anything surprises you.Set
RETENTION_DRY_RUN=falseand restart to enforce all central-engine classes. The next sweep deletes. To pilot selected classes or tenants, use the rollout controls below.
Delete or redact
The content class is redacted: the content fields are cleared and the row stays, so counts and costs remain correct. Every other class is deleted. Deletes run before redactions in a sweep.
Some rows are never touched: running jobs, running evaluation, red-team and analysis runs, and open alerts and incidents. Model calls from agents now carry the prompt, so those rows fall under content too.
On MongoDB each engine target gets an index on its age field, from the index manifest. Without it every batch would be a collection scan.
Stored files that belong to a row (screenshots, PDFs, OCR sources, batch output) are removed before their rows.
Legal holds
A legal hold keeps data past its retention for a dispute, an investigation or a regulator's request. A workspace admin (audit:admin) places and releases holds for the whole workspace or for one project, for chosen classes or for all of them (all is the safe choice). While a hold is in force, every sweep, Clean now purge and preview leaves the held data alone, whatever its age:
- A hold on
contentalso keeps the rows that carry that content. - A project hold skips the collections that have no project field, because their rows cannot be told apart.
- A hold placed while a sweep or purge runs applies from its next slice.
- Releasing a hold puts its data under the retention policy again: anything past its duration is removed by the next sweep.
Holds placed by the platform operator (npm run retention:hold) are listed but cannot be released through the API or the screen. Placing and releasing a hold write audit rows that are kept with the destruction records. A workspace can have at most 100 active holds.
Not covered: a hold on one user, conversation or record, and deleters outside the retention engine (a user deleting their own conversation, for example).
Settings screen (Enterprise)
Open Data retention from the settings navigation (workspace admins only). The header has two buttons, Clean now and Edit policy. Alerts at the top tell you when the engine is in dry run, when scheduled sweeps are off, and when Shorter durations are waiting.
Three cards sit above the tabs: the active policy (a preset name or Custom, and who changed it and when), the last sweep, and the current Clean now run.
The tabs are:
- Policy: the effective days of every class, where each value comes from (default, deployment, workspace or project), its allowed range, cap source and pending plan cap when present.
- Project exceptions: per-project overrides.
- Legal holds: the holds in force and the released ones (Hold, Covers, Placed, State). Place legal hold opens a full-screen form: a Name, a Reference (a case or ticket number), a Reason, the Scope (Whole workspace or One project) and the Data classes (All classes or Only some classes). Release ends a hold; a hold placed by the platform operator shows that only the operator can release it. A banner shows how many holds are in force, and the Clean now preview says that held data is not counted.
- Destruction records: what each sweep and purge deleted and redacted. Placing and releasing a hold are recorded here too.
- Collections: every collection, its edition, whether it is project-scoped, its phases and days, and whether the engine or its own mechanism ages it out. Gateway and agent-file mechanisms expose their cap in force and pending cap when present.
Edit policy
Edit policy opens a full-screen form with three steps: Starting point (a preset), Durations (one per class, with its allowed range) and Project exceptions (rows of project, class and days). A side summary, Impact now, shows how many rows would be deleted and how many would have their content cleared, per class. Durations that wait for the shortening delay are listed under Delayed. Use Cancel the change on the banner to drop a pending shortening.
Policy inputs and presets stay within current save bounds. The grandfathered editing rule for an existing over-cap gateway or agent value belongs to that entity's editor; it does not exempt central policy saves from cap validation.
Clean now
Clean now purges history on demand, in a full-screen form:
- What to remove: Apply the policy now (what the next sweep would do, without waiting) or Everything older than... a number of days.
0removes everything up to now in the chosen classes. - Classes and project: pick the classes. The
auditclass cannot be purged here: the audit trail is append-only. A project is optional; collections without a project are skipped when you choose one. - Confirm: type the workspace slug.
The preview shows the row counts before you confirm. After the start, the card shows the state (queued, running, waiting, done, cancelled or failed), a progress bar and the counts. Cancel stops after the current batch. Only one purge runs at a time.
Two limits always hold, for a sweep and for a purge:
auditnever goes belowRETENTION_AUDIT_MIN_DAYSandusagenever below its 400-day minimum;- running jobs and open incidents are never touched.
Reading the screen needs audit.read. Changing the policy and purging need audit.admin. The retention routes belong to the audit service in Permissions.
API
All routes are tenant-scoped session routes under /api/retention. Reads and the two preview calls need audit.read. Saving or cancelling a policy and starting or cancelling a purge need audit.admin.
| Method | Path | Purpose |
|---|---|---|
GET | /api/retention | Effective classes with source, caps and pending caps, targets, mechanisms, bounded presets, engine state, last sweep, current purge |
PUT | /api/retention/policy | Save { preset, classes, projects } within current licensed/operator bounds |
DELETE | /api/retention/policy/pending | Cancel a pending policy shortening |
POST | /api/retention/policy/preview | Rows a draft policy would delete or redact now |
POST | /api/retention/purge/preview | Rows a purge would touch |
POST | /api/retention/purge | Start a purge: { mode: 'policy' | 'olderThan', days?, classes?, projectId?, confirm }, where confirm is the workspace slug. Answers 202, or 409 while another purge runs |
GET | /api/retention/purge | Status of the current or last purge |
DELETE | /api/retention/purge | Cancel the running purge after its current batch |
GET | /api/retention/runs | Destruction records (audit rows of service retention) |
GET | /api/retention/holds | The workspace's legal holds, the operator's included (audit.read) |
POST | /api/retention/holds | Place a hold: { name, scope: { kind: 'tenant' } | { kind: 'project', projectId }, classes: 'all' | [...], reason?, ref? }. Answers 201 (audit.admin) |
DELETE | /api/retention/holds/:id | Release a hold placed by the workspace (audit.admin). Operator holds cannot be released here. |
Configuration
| Variable | Description | Default |
|---|---|---|
RETENTION_ENGINE_ENABLED | Scheduled sweeps; with false only the scheduled sweeps stop, Clean now still works | true |
RETENTION_DRY_RUN | With no rollout selections, sweeps only count. false enforces every central-engine class | true |
RETENTION_ENFORCE_CLASSES | Comma-separated classes to enforce even in dry run; malformed or unknown classes stop startup | unset |
RETENTION_ENFORCE_TENANTS | Per-tenant pilot selections, slug:class,class;slug2:class; malformed selections stop startup | unset |
RETENTION_INTERVAL_SECONDS | How often the cluster-wide tick queues the sweeps (minimum 60) | 3600 |
RETENTION_BUDGET_SECONDS | How long one sweep slice may run before it queues its continuation (10–840) | 240 |
RETENTION_BATCH_SIZE | Rows per delete or redact batch (50–5000) | 500 |
RETENTION_SHORTEN_DELAY_HOURS | How long a shortened policy duration waits before it applies (0–168) | 24 |
RETENTION_PLAN_DOWNGRADE_GRACE_DAYS | Grace for lower plan caps and new/lower gateway or agent-file caps (0–90) | 14 |
RETENTION_AUDIT_MIN_DAYS | Floor for the audit class, for every tenant and every purge (minimum 30) | 365 |
RETENTION_RECORDS_DAYS | How long destruction records are kept (minimum 1095) | 1095 |
RETENTION_<CLASS>_DAYS | Deployment default for one class (CONTENT, TELEMETRY, TRACE, JOBS, METRICS, ALERTS, AUDIT, USAGE, RESULTS, CONVERSATIONS; unset CONVERSATIONS keeps conversations until the user deletes them) | the class default |
RETENTION_<CLASS>_MAX_DAYS | Optional operator cap; only lowers the deployment ceiling and does not override class floors | unset |
Not covered yet
- Legal holds on one user or record (holds on the workspace or a project are covered, see Legal holds).
- Export before deletion.
- Data-subject requests (delete everything about one person).
- Moving the older mechanisms listed above into the engine.

