Skip to content

feat(retention): purge ports for soft-deleted work items and dispatched outbox rows - #336

Merged
aRustyDev merged 2 commits into
mainfrom
feat/59-retention-ports
Nov 19, 2026
Merged

aRustyDev merged 2 commits into
mainfrom
feat/59-retention-ports

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

What

The first of three PRs for #59 (the daily hard-delete retention job, F-D10, D-001). It adds the database half and nothing calls it yet: four Database methods, both adapters, one additive migration, and the tests and mutation controls for them. run_retention, the admin routes and the schedule come in the next two PRs.

  • purgeable_work_items(sys, cutoff, after, limit) lists soft-deleted work items by (deleted_at, id), keyset-paged, across every tenant. A work item is purgeable when it was deleted strictly before the cutoff (Plane's deleted_at < now - days) and so was every work item under it, so a live or recent work item never keeps a parent that is gone. A self-parent or a loop is old, so each goes.
  • purge_work_items(sys, ids, cutoff) re-checks the rule under a row lock, then in one transaction clears the parent of any work item that stays under one that goes, deletes the assignee, label and history rows, and deletes the work items. Every foreign key into work_items is NO ACTION, so the order matters.
  • purge_outbox(sys, cutoff, limit) deletes the oldest dispatched outbox rows made before the cutoff. A row that was not dispatched is never deleted, however old.
  • work_item_deleted_at(sys, id) is the read for the test route in PR 2 (None gone, Some(None) live, Some(Some(at)) deleted).
  • Migration 0021_retention_indexes.sql: two partial indexes (work_items (deleted_at, id) WHERE deleted_at IS NOT NULL, outbox (created_at, event_id) WHERE dispatched_at IS NOT NULL). Indexes only, so the migration lint, the ledger and preview databases are unaffected.

Decisions this records

  • D-043 (owner, 2026-11-19): a purged work item's history is deleted with it. Plane keeps IssueActivity (per the issue's reading of the pin; the oracle's deletion_task.py is not in this repo, so I did not re-run that reading). Keeping it would mean dropping work_item_activities_work_item_id_fkey, which is the repo's first contract migration, and migrate_preview_with (allow_contract: false) and deploy-target.sh (--no-contract) refuse one. No read shows a deleted work item's history, so no response changes. The activity projection, the project counter (a purged number is never handed out again, ADR-0043 B1) and the 90-day outbox stay.
  • Scope is work items and the outbox. projects, states, labels and assets also have deleted_at now; I will draft a follow-up issue for them rather than widen this one.

How it is tested

  • crates/adapters/memory/tests/retention.rs (15 tests): a generated forest of work items (self-parents, loops, children deleted before or after their parent), a boundary matrix over two tenants and -2..2 s around the cutoff, an outbox property over shuffled insertion order, and named examples for ADR-0043 B1, D-043 and the "child that is not old" case.
  • crates/adapters/selfhosted/tests/retention/mod.rs (6 tests, real Postgres, one container): the same rules read back with SQL on the tables, a generator-coverage control, a microsecond cutoff matrix, and the one-batch shapes (self-parent, loop, chain, a survivor that loses its parent).
  • Controls (each shown failing, then the tree restored): memory mutants mutant_purge_at_cutoff, mutant_outbox_purge_by_age and mutant_purge_ignores_children are rows 55 to 57 of scripts/mutants.sh, each KILLED with its needle. On Postgres I broke, by hand, the parent-clearing step (FK violation), the children rule, the outbox dispatched_at test and the history delete; each failed the tests aimed at it.
  • One clause I wrote did not survive its control and is gone: excluding the work item itself from "its children" is dead logic, because a candidate is always old.

Not in this PR

run_retention, the config (THRUST_HARD_DELETE_AFTER_DAYS, THRUST_OUTBOX_RETENTION_DAYS), POST /internal/retention, the contract test, schedules.rs, the Worker cron and the server timer.

Refs: #59

🤖 Generated with Claude Code

aRustyDev and others added 2 commits November 19, 2026 00:39
…ed outbox rows

The database half of the daily hard delete (F-D10, D-001): nothing calls it yet.

- Database::purgeable_work_items lists soft-deleted work items by (deleted_at, id),
  keyset-paged, across tenants. One is purgeable when it was deleted strictly before
  the cutoff and so was every work item under it, so a live or recent work item never
  keeps a parent that is gone. A self-parent or a loop is old, so each goes.
- Database::purge_work_items re-checks the rule under a row lock, then in one
  transaction clears the parent of a work item that stays under one that goes, deletes
  the assignee, label and history rows, and deletes the work items (every foreign key
  into work_items is NO ACTION).
- Database::purge_outbox deletes the oldest dispatched rows made before the cutoff and
  never one that was not dispatched.
- Database::work_item_deleted_at is the read behind the test route that follows.
- Migration 0021 adds two partial indexes and nothing else.

D-043 (owner, 2026-11-19): a purged work item's history goes with it. Keeping it
would need the repo's first contract migration, which the preview path and
deploy-target.sh refuse. The activity projection, the project counter and the 90-day
outbox stay.

Tests: 15 on the memory adapter and 6 on real Postgres (a generated forest, a
boundary matrix, an outbox property, a generator-coverage control). Three memory
mutants are rows 55 to 57 of scripts/mutants.sh, each KILLED with its needle.

Refs: #59
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The conflicts were all one place: #332 added Database::ping and its adapter bodies
right after outbox_depth, where the retention methods go. Both are kept.

Refs: #59
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev temporarily deployed to preview-control-plane November 19, 2026 05:43 — with GitHub Actions Inactive
@aRustyDev
aRustyDev merged commit c00a47e into main Nov 19, 2026
48 checks passed
@aRustyDev
aRustyDev deleted the feat/59-retention-ports branch November 19, 2026 06:41

This branch was previously deployed

1 inactive deployment
preview-control-plane — 9b37b171 Deployed Nov 19, 2026 by aRustyDev via reconcile #240
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