Repository navigation
feat(portal): delete former clients' records after three years - #616
Conversation
@codex review for Retention purge: which clients are due (all client memberships, none active, last change older than 3 years), the dependency-ordered per-client deletion, the membership history of identities with no membership left, and the exclusive --retention-purge command running as the migration role |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 43ceefd569
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
43ceefd to
82f17c5
Compare
Codex review on #616: - Lock invitations and memberships, then recheck the client inside the purge transaction, so an invitation redeemed after the candidate query keeps the client. A pending invitation also keeps it. - Date a client's last membership change by the event that follows each of its events, so a member's move to another client counts. - Delete an identity's membership history only when its last change is also past the period, it holds no other client's membership, and no remaining work approval cites it. - Report how many clients lost records. The CronJob ships in the package beside the portal migration Job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codex review for Re-review of the retention purge after the three findings at 43ceefd: per-client recheck under a SHARE ROW EXCLUSIVE lock on invitations and memberships, successor events dating a client's last change, and history deletion only for identities whose whole history is past the period, hold no other membership and are cited by no remaining work approval. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82f17c51a6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
✅MegaLinter analysis: Success
See detailed reports in MegaLinter artifacts Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining
|
Code coverage overviewLanguages: Go Go / code-coverage/go
Line coverage data for the main branch is not yet available. View coverage of the 10 most covered files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
Codex review on #616 at 82f17c5: - Keep an identity's history while any other client its events name still has records, so purging one former client never removes the evidence that makes another due. That also covers a membership the identity still holds elsewhere. - Keep it while another identity's history continues from it (a renamed membership), so the self-referencing foreign key holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 71c241ee4c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The privacy notice (#614) keeps a former client's portal records for 3 years after their last portal membership ended, the general Danish limitation period, and the maintainer confirmed that period. - identity.PurgeExpiredClients deletes, one client per transaction, the records of every client whose memberships were all client memberships, none still active, last changed more than RetentionYears (3) ago: billing, email, work approvals, proposals, requests, contacts, invitations and memberships, and the membership history of identities with no membership left. - The executable's exclusive --retention-purge --migration-database-file mode runs it as the migration role, which owns the complete schema; the web runtime still has no DELETE on this history. It prints only how many former clients it purged. The platform runs it daily beside the migration job. Invoices and accounting stay 5 years in Numina and Stripe. Part of #21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex review on #616: - Lock invitations and memberships, then recheck the client inside the purge transaction, so an invitation redeemed after the candidate query keeps the client. A pending invitation also keeps it. - Date a client's last membership change by the event that follows each of its events, so a member's move to another client counts. - Delete an identity's membership history only when its last change is also past the period, it holds no other client's membership, and no remaining work approval cites it. - Report how many clients lost records. The CronJob ships in the package beside the portal migration Job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex review on #616 at 82f17c5: - Keep an identity's history while any other client its events name still has records, so purging one former client never removes the evidence that makes another due. That also covers a membership the identity still holds elsewhere. - Keep it while another identity's history continues from it (a renamed membership), so the self-referencing foreign key holds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex review on #616 at 71c241e: an identity renamed away and back made two identities depend on each other, so neither was ever deleted. A membership's history is one chain of events linked by previous_incarnation, across renames and moves. The purge now decides per chain and deletes whole chains, so no remaining event loses its predecessor and renames need no special case. A chain still stays while another client it names has records, or a remaining work approval cites it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tion After #618, the migration Job reads its connection through --migration-database-projection. The retention purge takes the same option, through the shared openMigrationPool, so its CronJob can mount the same Secret. Exactly one connection input is admitted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71c241e to
f7fecc0
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f7fecc0d2c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…etions out of the clock Codex review on #616 at f7fecc0: - A former client whose card subscription has no confirmed end, or whose monthly billing has not ended or been withdrawn, is not due: purging it would leave a subscription the portal could no longer stop. - Deleting a membership that was already revoked records an event today. A chain's age no longer counts such deletions, so a chain that had to wait for another client's purge is not kept three more years. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |

What
The privacy notice (#614) keeps a former client's portal records for 3 years after their last portal membership ended. That is the general Danish limitation period (forældelsesloven §3), and the maintainer confirmed it. This PR adds the deletion that keeps that promise. It is the second of the two gaps that blocked switching the portal on.
identity.PurgeExpiredClients. A client is due when:identity.RetentionYears(3) years back. A member's move to another client is recorded under the new client, so the event that follows each of the client's events counts too. The period is one constant, so another period is a one-line change.Each due client goes in one transaction. It first locks invitations and memberships (
SHARE ROW EXCLUSIVE, invitations first, the order redemption writes them) and checks the client again. An invitation redeemed during the purge therefore either shows in the recheck or waits and finds no invitation. Then it deletes, in dependency order:previous_incarnationacross renames and moves, whose last change is also past the period. A chain stays while it names another client that still has records (so that client can still be found), or while a remaining work approval cites it.--retention-purge --migration-database-file <file>, or--migration-database-projection <file>for a Kubernetes Secret projection as feat(portal): let a Kubernetes Job run the schema migration #618 added for the migration. An exclusive one-shot mode of the executable, with exactly one connection input. It runs as the migration role and first checks that the role owns the complete schema. The web runtime still has no DELETE on this history, and every other option is refused. Like--migrate, it discards ambientPG*settings, has bounded deadlines, and prints only how many former clients lost records, or a generic failure.Docs.
server/README.mdhas a new Retention purge job section.MIGRATIONS.mdrecords this purge as the one pruning of membership history.server/AGENTS.mdnotes the job.Invoices and other accounting records live in Numina and Stripe for 5 years, and backups age out after 30 days.
Rollout
The daily CronJob is #620, in the package beside the migration Job (#619). It runs this command through
--migration-database-projectionand must merge after this PR.Codex review
Each finding has a test that fails without its fix. The three findings at 43ceefd are fixed in 82f17c5:
TestRetentionRechecksUnderLockholds an uncommitted membership insert, sees the purge wait on the lock, commits, and the purge deletes nothing. A pending invitation keeps a former client too.TestRetentionCountsMoveToAnotherClient: a client whose member moved away today is kept; three years after the move it goes, and the moved member's membership and history stay.TestRetentionKeepsHistoryOtherApprovalsCite: a former operator who approved another client's work becomes a former client. The purge succeeds and keeps the cited history and the approval.The two findings at 82f17c5 are fixed in 71c241e:
TestRetentionKeepsEvidenceOtherClientsNeed: a member moves from A to B and the membership is deleted. Both clients are purged in one run and the shared history goes; before, purging A removed the history B needed to be found.TestRetentionKeepsHistoryARenamedIdentityContinues: the history a renamed membership continues from stays, so the self-referencing foreign key holds.The finding at 71c241e is fixed in b0decb9:
TestRetentionDeletesARenamedMembershipsWholeHistoryrenames a member away and back, and the chain goes as a whole.The two findings at f7fecc0 are fixed in 440ba9e:
TestRetentionWaitsForLiveSubscriptionskeeps a former client whose card subscription has no confirmed end and purges it once the end has passed.TestRetentionDeletionDoesNotRestartTheClockpurges two clients that share a moved member in one run, and the shared history goes.Tests run locally (PostgreSQL 17, Go 1.27.4)
TestRetentionPurgesFormerClientsAfterThreeYearsseeds every portal relation (the fixture-reset seed, now a shared helper) and checks:TestActualExecutableRetentionPurgeruns the real binary:--migrate,--runtime-roleand a relative file are refused.TestActualMigrationAcceptsKubeletProjectionalso runs the purge through a kubelet-shaped Secret projection, which the strict file option refuses.contactintegrationandcontacttrialintegration.Part of #21
🤖 Generated with Claude Code