Skip to content

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 ​

ClassWhat it coversDefaultSaaS range before plan and operator capsExpired rows are
contentPrompts, responses, tool payloads, queries, extracted text, page bodies, screenshots30 days1–90redacted: the content fields are cleared and the row stays
telemetryModel, tool, MCP, guardrail, Knowledge Engine, reranker, web search and vector query logs90 days30–400deleted
traceAgent trace sessions and their events, trace threads, browser sessions and steps30 days7–180deleted
jobsCrawl results, batch and OCR items, browser flow runs, vector migration and re-index runs90 days30–365deleted (never while running)
metricsInference server metrics, GPU fleet events45 days7–180deleted
alertsResolved alerts, resolved or closed incidents180 days90–730deleted (never while open)
auditAudit log, config change log, MCP server change log365 days365–3650deleted
usageDaily usage totals (billing and the usage reports)760 days400–1095deleted
resultsEvaluation, red-team and analysis runs, cost prescription reports365 days90–3650deleted (never while running)
deliveryWebhook and alert deliveries, scheduler claimsits own mechanism, see belowdeleted
conversationsChat history of agent sessions and portal chats, and the memory written from itkept until the user deletes it (0)1–3650deleted

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.

Presetcontenttelemetrytracejobsmetricsalertsauditusageresults
Standard (the built-in defaults)3090309045180365760365
Minimal73014304590365400180
EU AI Act high-risk30180180180453653657603650
Finance303659018045365109510951095

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.

CollectionDefaultSet by
agent_runs30 daysAGENT_RUN_RETENTION_DAYS
agent_session_events30 daysAGENT_SESSION_EVENT_RETENTION_DAYS
webhook_deliveries30 daysWEBHOOK_DELIVERY_RETENTION_DAYS
agent_trigger_deliveries7 daysbuilt in
alert_deliveries30 daysbuilt in
scheduler_claimsat most 7 daysthe expiry stored on each claim
entity_metrics45 daysENTITY_METRICS_RETENTION_DAYS
Agent session files30 dayseach 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:

  1. the class default (table above);
  2. the deployment default, RETENTION_<CLASS>_DAYS (for example RETENTION_TELEMETRY_DAYS=180);
  3. the workspace policy;
  4. 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 ​

  1. Run the inventory. It is read-only and works on MongoDB and SQLite:

    bash
    npm run retention:inventory
    npm run retention:inventory -- --tenant <slug-or-dbName>
    npm run retention:inventory -- --json

    It 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.

  2. Review the numbers, plan caps and pending grace deadlines. Adjust the policy or the RETENTION_<CLASS>_DAYS defaults if anything surprises you.

  3. Set RETENTION_DRY_RUN=false and 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.

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 content also 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:

  1. What to remove: Apply the policy now (what the next sweep would do, without waiting) or Everything older than... a number of days. 0 removes everything up to now in the chosen classes.
  2. Classes and project: pick the classes. The audit class cannot be purged here: the audit trail is append-only. A project is optional; collections without a project are skipped when you choose one.
  3. 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:

  • audit never goes below RETENTION_AUDIT_MIN_DAYS and usage never 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.

MethodPathPurpose
GET/api/retentionEffective classes with source, caps and pending caps, targets, mechanisms, bounded presets, engine state, last sweep, current purge
PUT/api/retention/policySave { preset, classes, projects } within current licensed/operator bounds
DELETE/api/retention/policy/pendingCancel a pending policy shortening
POST/api/retention/policy/previewRows a draft policy would delete or redact now
POST/api/retention/purge/previewRows a purge would touch
POST/api/retention/purgeStart 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/purgeStatus of the current or last purge
DELETE/api/retention/purgeCancel the running purge after its current batch
GET/api/retention/runsDestruction records (audit rows of service retention)
GET/api/retention/holdsThe workspace's legal holds, the operator's included (audit.read)
POST/api/retention/holdsPlace a hold: { name, scope: { kind: 'tenant' } | { kind: 'project', projectId }, classes: 'all' | [...], reason?, ref? }. Answers 201 (audit.admin)
DELETE/api/retention/holds/:idRelease a hold placed by the workspace (audit.admin). Operator holds cannot be released here.

Configuration ​

VariableDescriptionDefault
RETENTION_ENGINE_ENABLEDScheduled sweeps; with false only the scheduled sweeps stop, Clean now still workstrue
RETENTION_DRY_RUNWith no rollout selections, sweeps only count. false enforces every central-engine classtrue
RETENTION_ENFORCE_CLASSESComma-separated classes to enforce even in dry run; malformed or unknown classes stop startupunset
RETENTION_ENFORCE_TENANTSPer-tenant pilot selections, slug:class,class;slug2:class; malformed selections stop startupunset
RETENTION_INTERVAL_SECONDSHow often the cluster-wide tick queues the sweeps (minimum 60)3600
RETENTION_BUDGET_SECONDSHow long one sweep slice may run before it queues its continuation (10–840)240
RETENTION_BATCH_SIZERows per delete or redact batch (50–5000)500
RETENTION_SHORTEN_DELAY_HOURSHow long a shortened policy duration waits before it applies (0–168)24
RETENTION_PLAN_DOWNGRADE_GRACE_DAYSGrace for lower plan caps and new/lower gateway or agent-file caps (0–90)14
RETENTION_AUDIT_MIN_DAYSFloor for the audit class, for every tenant and every purge (minimum 30)365
RETENTION_RECORDS_DAYSHow long destruction records are kept (minimum 1095)1095
RETENTION_<CLASS>_DAYSDeployment 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_DAYSOptional operator cap; only lowers the deployment ceiling and does not override class floorsunset

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.

Studio · Pulse · Console · Agent SDK and more — the Cognipeer documentation hub · Contact Support