Skip to content

feat(server): daily retention sweeper (ADR-0004)#65

Merged
Isonimus merged 1 commit into
mainfrom
feat/retention-sweeper
Jun 18, 2026
Merged

feat(server): daily retention sweeper (ADR-0004)#65
Isonimus merged 1 commit into
mainfrom
feat/retention-sweeper

Conversation

@Isonimus

Copy link
Copy Markdown
Contributor

Fourth PR of the Consent & Data-Lifecycle workstream (ADR-0004).

What

A daily BullMQ repeatable job in the worker deletes data past each project's retention window:

  • pipeline/retention.tssweepRetention(sql): for every project with a positive retention_days, DELETE FROM identities WHERE last_seen < now() - retention_days (snapshots/drifts/risk/links cascade). Projects with a null retention_days keep data forever and are skipped. Idempotent; returns per-run counts.
  • worker.ts — schedules the repeatable job (daily 03:30 UTC; BullMQ dedupes by repeat key so re-adding on every boot is safe) on a dedicated retention queue, plus a worker to process it. Both close cleanly on shutdown.

Tests

  • Integration (retention.integration.test.ts): a 60-day-old identity is swept, a 1-day-old one is kept, and an identity under a null-retention project is untouched. Full server suite: 128 passing locally.

A BullMQ repeatable job in the worker (daily 03:30 UTC) deletes identities whose
last_seen is older than their project's retention_days; snapshots, drifts, risk
assessments, cluster merges, and account links cascade. Projects with a null
retention_days keep data indefinitely.

- pipeline/retention.ts: sweepRetention(sql) — idempotent, returns per-run counts.
- worker.ts: schedules the repeatable job (idempotent add) + a dedicated worker on
  a separate `retention` queue; both close cleanly on shutdown.
- retention.integration.test.ts: old identity swept, recent kept, null-retention
  project untouched.
@Isonimus Isonimus merged commit 38992f8 into main Jun 18, 2026
4 checks passed
@Isonimus Isonimus deleted the feat/retention-sweeper branch June 18, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant