Repository navigation
feat(retention): purge ports for soft-deleted work items and dispatched outbox rows - #336
Merged
Merged
Conversation
…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
temporarily deployed
to
preview-control-plane
November 19, 2026 05:43 — with
GitHub Actions
Inactive
This was referenced Nov 19, 2026
This branch was previously deployed
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.
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
Databasemethods, 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'sdeleted_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 intowork_itemsisNO 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 (Nonegone,Some(None)live,Some(Some(at))deleted).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
IssueActivity(per the issue's reading of the pin; the oracle'sdeletion_task.pyis not in this repo, so I did not re-run that reading). Keeping it would mean droppingwork_item_activities_work_item_id_fkey, which is the repo's first contract migration, andmigrate_preview_with(allow_contract: false) anddeploy-target.sh(--no-contract) refuse one. No read shows a deleted work item's history, so no response changes. Theactivityprojection, the project counter (a purged number is never handed out again, ADR-0043 B1) and the 90-day outbox stay.projects,states,labelsandassetsalso havedeleted_atnow; 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 saround 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).mutant_purge_at_cutoff,mutant_outbox_purge_by_ageandmutant_purge_ignores_childrenare rows 55 to 57 ofscripts/mutants.sh, each KILLED with its needle. On Postgres I broke, by hand, the parent-clearing step (FK violation), the children rule, the outboxdispatched_attest and the history delete; each failed the tests aimed at it.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