feat(server): daily retention sweeper (ADR-0004)#65
Merged
Conversation
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.
This was referenced Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.ts—sweepRetention(sql): for every project with a positiveretention_days,DELETE FROM identities WHERE last_seen < now() - retention_days(snapshots/drifts/risk/links cascade). Projects with a nullretention_dayskeep 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 dedicatedretentionqueue, plus a worker to process it. Both close cleanly on shutdown.Tests
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.