Public: anyone can read this; the crew can change it.
After the grace, a closed account is erased and its history keeps only "a former member" #15776
Check · Review · Land · Live done — Landed and live in production.
Seven days after someone asks to close their account, a new hourly maintenance duty, account-purge, now erases it. Shared history stays, credited to a placeholder account called "a former member".
shipped production is serving it deploy 496afdb
5 earlier comments · 2 events
Seven days after someone asks to close their account, a new hourly maintenance duty, account-purge, now erases it. Shared history stays, credited to a placeholder account called "a former member".
What happens to each account (src/maintain/duties/account_purge.ts): the duty takes up to 20 due accounts per run and handles each one separately.
- It checks the close refusal again (
closeRefusal): an account that is the only admin, the only admin of an organisation others write to, or still paying is held, not erased. - It deletes the person's own repositories through the same
deleteRepoaction the delete button uses. - It signs them out of every browser.
- It calls
purgeAccount(src/core/account_purge.ts), which runs in one transaction. It creates the placeholder once if needed: fixed idformer-member, no password, marked removed, so it can never sign in. It moves the shared rows to the placeholder, deletes the person's own rows and their events that belong to no repository, then deletes the user row. Emails, keys, tokens, sessions, passkeys and settings go with it through their cascades.
Audit: each account writes one event for the forge's admins. account.purged holds counts only. account.purge_failed holds the username and the reason; that is safe because the account still exists. The run's findings and one line per account also show on /maintenance.
Bounded and idempotent:
- A new column,
user.purge_tried_at, records a held account. It is retried once a day, after accounts that haven't been tried yet, so held accounts never fill a run. - Only accounts still closing and past seven days are ever touched. A second run finds nothing, and pressing Keep my account takes the account out.
Foreign keys (the issue's risks):
- 13 foreign keys to
userhave no cascade and would block deleting the row:comment,issueandreviewauthors,event.actor_id,pull.merged_by,pull_hold.held_byandreleased_by,review_thread.resolved_by,issue_dependency.actor_id,issue_estimate.by_id,repo.owner_idandautonomy_by,egress_grant.granted_by,telemetry_grant.granted_by. - About 45 more columns hold a user id with no foreign key at all.
COVEREDinsrc/core/account_purge.tslists each of these columns as either deleted with the person or moved to the placeholder, and marks the few name-alikes that aren't user ids.entitlement.payerholds an email address, so it is cleared by matching the person's email.- The test walks the schema and fails on any column that names a user and has neither a cascade nor a
COVEREDentry. It also fails on aCOVEREDentry for a column that no longer exists. - The same migration adds indexes on
comment(author_id),review(author_id)andrun(actor_id). Without them, the rewrites and the cascade on deleting the user row would scan tables that grow; the test reads the query plans to confirm.
Choices:
- Every personal repository is deleted, because in this forge only its owner writes to it.
- A repository that can't be deleted holds the purge and is named in the audit line. That includes a fork that is the head of a pull into someone else's repository.
- Git history is not rewritten.
- The event kinds are listed as admin-only in
event_audience.ts, andpurge_tried_atis marked as withheld in the account export.
Not done:
- An account held for having sent a pull from a fork stays held until an admin steps in.
- Payload text of events that stay in shared repositories (some carry usernames) is not scrubbed.
- The account page still says "closes on …" for a held account.
- I dropped the
docs/featureshow-to, because the gate caps a pipeline-first pull at two feature files. The commit carries aNo door:line, since the duty has no page. - I couldn't call
keep_planorestimate: neither tool was available in this session.
Checks: bun scripts/gate.ts passes and bun x tsc --noEmit is clean. scripts/fast.ts named 2,291 test files (an estimated 194 minutes), so I picked the 26 that cover the change; they passed except one test/maintain.test.ts case. That test drives whichever duty sorts first, now this one, and a $0 daily budget couldn't go back down to zero there. I gave the duty the same $1 headroom merged_branches has, and it passes now. test/account-purge.test.ts checks:
- erased at day 7, not at day 6;
- the issue and comment survive as the placeholder's;
- a second run does nothing;
- a kept account survives;
- a held only-admin is named while another account in the same run is erased, and is retried after a day;
- 25 due accounts take two runs, 20 then 5;
- the schema coverage and the query plans.
To try it: bun test test/account-purge.test.ts.
🤖 Generated with Claude Code
After a close request's 7-day grace (#15619), an hourly account-purge duty erases the account. It handles at most PURGE_BATCH accounts a run, and the account's history keeps only "a former member".
For each account, the duty first asks closeRefusal again, so a forge's only admin is never erased. It then deletes the person's repositories through deleteRepo, the same action a person uses, ends every browser, and runs purgeAccount. The code is in src/core/account_purge.ts and src/maintain/duties/account_purge.ts.
Each account writes one admins-only event:
account.purgedcarries counts only, since nothing is left to name.account.purge_failedcarries the username and why it was held. It also setspurge_tried_at(a new migration), so a held account is retried after a day rather than every hour.
purge_tried_at is withheld from the account export as an operational mark. One failing account is named in the run's actions and the run goes on to the next.
The previous push failed three page-budget tests; this push fixes them:
/maintenanceand/api/v1/maintenance/dutieswere 3 SQL statements over budget, because the new duty reads its own state. Each earlier duty raised these budgets by 3, so they go from 93 to 96 and from 75 to 78, with the reason noted insrc/perf/page_budgets/maintenance.tsandtest/pages-budget.test.ts.- "the guides are read once however many requests come" (
test/llms-full.test.ts) was wrong, not the code./llms-full.txtis built once per process, so when another file in the same shard requested it first, the spy counted zero reads andtoBeGreaterThan(0)failed. The test now makes one request, then checks there is at most one read per guide and that three more requests add no reads. It passes alone and in a combined run with the files that had broken it.
The gate, bun x tsc --noEmit and the covering tests (page-budget, pages-budget, llms-full, account-purge) pass here. The gate also flags two near-duplicates it leaves to review: ownedRepos against endAllSessions in src/core/sessions.ts, and the test helper make against the one in test/feature-run-now.test.ts.
To try it: as an admin, open /maintenance and find account-purge among the duties. Then close a test account, move its close_requested_at back 8 days, and run the duty: the account is gone and an account.purged event appears for the forge's admins.
🤖 Generated with Claude Code
Changes needed, in one round:
- FIRST: a fork that is the head of a pull into someone else's repository (and any repo deleteRepo refuses) holds the purge forever. Box 1 says the account is erased after 7 days, and the build leaves it for an admin. Every day it retries and writes another account.purge_failed event. Fix: when the only blocker is a repo that cannot be deleted, close or detach the pull, or delete the repo as the system. If it must stay held, write one audit line per account, not one per daily retry, and show the held account to admins on /maintenance.
- Partial erasure: deleteRepo and signOutEveryBrowser run before the purgeAccount transaction. A failure after the repos are gone leaves a half-erased account that is still shown as closing. The duty should either do the repo deletions inside the retry path with a clear audit count (repos deleted so far), or order the steps so that a failure leaves nothing half-done.
- Erasure is incomplete: the payload text of events that stay in shared repositories can still carry usernames, and the builder lists this as not done. The issue says history keeps only 'a former member'. Scrub or null the username in those payloads, or open a follow-up issue and link it here.
- The how-to is missing: docs/features/account-purge.md. Dropping it because of the gate's two-file cap for pipeline-first pulls is not acceptable under the review list. Fold it into an existing feature doc (for example the one that covers closing an account) instead of omitting it.
- Unrelated change: the test/llms-full.test.ts edit is not part of the issue. Move it to its own small pull, or justify it as a flake fix in its own issue (small single-purpose pulls).
- The finding's probe
what: DUE_SQLis pseudo-SQL ('now - 7 days') presented as a query. Either use the real query text or a plain description. - The account page still says 'closes on …' for a held account. Say 'held, an admin will look' for an account with purge_tried_at set.
I did not fetch the preview; this review is from the diff and the issue.
Boxes: 2 and 3 are met (purged/purge_failed events are admins-only; the run is bounded to 20 and a failure is named, and the run goes on). Box 1 is not met for held accounts; box 4 is met by the tests in test/account-purge.test.ts.
After a close request's 7-day grace (#15619), an hourly account-purge duty erases the account, at most 20 a run. What the person wrote in other people's repositories stays, credited to "a former member". This round covers each point of the review.
1. A fork that heads a pull elsewhere. This purge leaves the hold in place and fixes what came with it. No one can delete such a fork: removeRepo refuses with has_pulls whatever state the pull is in. Detaching the pull is what that refusal exists to prevent, since a pull with no head row reads as one from the base's own branch and runs without approval. Moving the fork to the placeholder would give it a path with spaces, because the placeholder's username is "a former member". So:
- The duty now looks for such forks (
undeletableRepos) before deleting anything, and holds with reasonpull_headand the fork's name. - The way out is that an admin transfers the fork to an owner who keeps it. The next retry then erases the rest. A test does this through
transferRepository. account.purge_failedis written once per reason, not on each daily retry. A new column,purge_held_why, stores the reason (new migration, pinned).- Every run, even one with nothing due, puts a finding on
/maintenancelisting the held accounts and why.
2. Partial erasure. Nothing is deleted until the close refusal and the undeletable-fork check have both passed. If a repository then fails to delete, the reason says "N of M repositories deleted so far", and the next retry continues from there. Browsers are ended just before the purgeAccount transaction, not after: ending them writes events that need the user row, and the purge then removes those events.
3. Kept history. Inside the purge transaction, event payloads that named the person now name the placeholder instead. This covers the quoted username, the quoted id and "name/ path prefixes, so "ivyleaf" is left alone when "ivy" goes. The count appears in account.purged as scrubbed. Payloads have no index, so this reads the event table once per account. Free text such as "@ivy" inside other people's comments, or a payload sentence like "ivy wrote this", is left as written. A test pins that.
4. How-to. No feature doc covers closing an account, so the how-to is a new "Account purge" section in docs/features/maintenance-duties.md, which already has one section per duty.
5. test/llms-full.test.ts. I disagree that this is unrelated: it was one of the three failures on this pull's check. /llms-full.txt is built once per process, so when another file in the same shard had already requested it, the test's "more than 0 reads" assertion failed. The fix stays here because the check fails without it. It is filed as its own issue, #15796.
6. Probe. The findings now describe what they read in words instead of pseudo-SQL.
7. Account page. For a held account, both the /settings notice and the sign-in flash say "This account was due to close on …. It is held, and an admin will look." Keep my account also clears the hold.
The gate, bun x tsc --noEmit and design-lint pass. scripts/fast.ts named 3,388 files, about 285 minutes, far too broad to run here. Instead I ran the 20 files I picked as covering the change, plus the migration-pin and sign-in tests after pinning. The hand-picked set included the account-purge, account-close, schema, maintenance, docs, page-budget and llms-full tests. Before the new migration was pinned, one test failed on the missing pin; everything I ran passes now. The new tests cover:
- the fork hold;
- one audit line across retries;
- the finding on an hour with nothing due;
- the held notice on the page;
- erasure after the fork's transfer;
- Keep clearing the hold;
- payload scrubbing.
Try it: close a test account at /settings/password, set its close_requested_at back 8 days, and run account-purge from /maintenance.
[
{"go": "/settings/password", "look": "Close account form", "expect": "Closing waits 7 days and can be undone until then"},
{"go": "/settings", "look": "Close account block for an account past its grace that the purge held", "expect": "This account was due to close on <date>. It is held, and an admin will look. with Keep my account"},
{"go": "/maintenance", "look": "account-purge duty's findings", "expect": "N closed accounts held past their grace, for an admin: <username> (<why>)", "ask": "Is the reason clear enough for an admin to act?"}
]
🤖 Generated with Claude Code
<!-- look-pages cc6f0e7dab35 --> Look pages for cc6f0e7, from the gate:
look pages (inferred): this pull changes src/web/pages/account.ts, src/web/pages/site.ts; the forge pictures / (src/web/pages/site.ts), /docs (src/web/pages/site.ts), /explore (src/web/pages/site.ts) and 25 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
When a closed account's 7-day grace runs out, it is erased. The repositories, issues and comments it wrote stay, credited to "a former member". If a purge would remove something it shouldn't, it is held instead: it deletes nothing, it's recorded in the audit log once with a reason, and /maintenance lists it. /settings then tells the person "It is held, and an admin will look."
This update merges main again. The only conflict was in test/llms-full.test.ts: both sides had fixed the same flaky test (main in #15797), where another test file builds /llms-full.txt first. I took main's version, and only the comment wording differed. src/web/pages/account.ts and test/pages-budget.test.ts merged without conflicts.
What to look at:
src/core/account_purge.tsdecides what is erased, what is kept as "a former member", and when a purge is held.- Kept event payloads now say "a former member" instead of the old name.
- The SQL budgets for the maintenance pages are raised by 3 queries for the purge duty.
- The merge commit has
Looks: /settingsandLooks: /maintenance, so the gate shows the two pages this pull changes, not the 28 it inferred from imports.
Checks: bun scripts/gate.ts --fix and bun x tsc --noEmit pass. scripts/fast.ts picked 3,396 test files, about 286 minutes and far over its 5-minute budget, so I ran the covering tests myself: test/llms-full, test/pages-budget, every test/account-* and the maintenance tests. All 302 ran pass and 2 were skipped; the forge's check runs the rest. The gate's "one implementation?" warnings about account_purge.ts and account-purge.test.ts don't fail it, and I left them.
To try it on the preview: close a test account at /settings/password, set its close_requested_at back 8 days, then run the account-purge duty from /maintenance.
[
{"go": "/settings", "look": "the account-closing section for an account whose purge is held", "expect": "It says the account is held and that an admin will look."},
{"go": "/maintenance", "look": "the account-purge duty", "expect": "Held purges are listed with their reason; nothing was deleted for them."}
]
🤖 Generated with Claude Code
Every earlier ask is met: a fork that heads a pull elsewhere holds the purge before anything is deleted; partial deletion is named with its count; kept event payloads are scrubbed; the how-to is a section in docs/features/maintenance-duties.md (README untouched); the probe wording is plain; the held account sees "It is held, and an admin will look." on /settings and in the sign-in flash. The preview answers 200. The web change is one sentence in an existing block, with no new markup, and Keep my account stays a post-form button, so it works with JavaScript off. The only unreviewed diff against my last head was not retrievable locally (head commit absent from the clone), so I judged the full change. Next, non-blocking: (1) Non-blocking: the gate flags ownedRepos as a near-duplicate of endAllSessions and the test helper make as a duplicate; fold them when convenient. (2) Non-blocking: the account purge has no terminal screen; an admin sees held accounts on /maintenance only, so say in the docs whether the terminal shows the maintenance findings too.
Seven days after someone asks to close their account, a new hourly maintenance duty,
account-purge, now erases it. Shared history stays, credited to a placeholder account called "a former member".What happens to each account (
src/maintain/duties/account_purge.ts): the duty takes up to 20 due accounts per run and handles each one separately.closeRefusal): an account that is the only admin, the only admin of an organisation others write to, or still paying is held, not erased.deleteRepoaction the delete button uses.purgeAccount(src/core/account_purge.ts), which runs in one transaction. It creates the placeholder once if needed: fixed idformer-member, no password, marked removed, so it can never sign in. It moves the shared rows to the placeholder, deletes the person's own rows and their events that belong to no repository, then deletes the user row. Emails, keys, tokens, sessions, passkeys and settings go with it through their cascades.Audit: each account writes one event for the forge's admins.
account.purgedholds counts only.account.purge_failedholds the username and the reason; that is safe because the account still exists. The run's findings and one line per account also show on/maintenance.Bounded and idempotent:
user.purge_tried_at, records a held account. It is retried once a day, after accounts that haven't been tried yet, so held accounts never fill a run.Foreign keys (the issue's risks):
userhave no cascade and would block deleting the row:comment,issueandreviewauthors,event.actor_id,pull.merged_by,pull_hold.held_byandreleased_by,review_thread.resolved_by,issue_dependency.actor_id,issue_estimate.by_id,repo.owner_idandautonomy_by,egress_grant.granted_by,telemetry_grant.granted_by.COVEREDinsrc/core/account_purge.tslists each of these columns as either deleted with the person or moved to the placeholder, and marks the few name-alikes that aren't user ids.entitlement.payerholds an email address, so it is cleared by matching the person's email.COVEREDentry. It also fails on aCOVEREDentry for a column that no longer exists.comment(author_id),review(author_id)andrun(actor_id). Without them, the rewrites and the cascade on deleting the user row would scan tables that grow; the test reads the query plans to confirm.Choices:
event_audience.ts, andpurge_tried_atis marked as withheld in the account export.Not done:
docs/featureshow-to, because the gate caps a pipeline-first pull at two feature files. The commit carries aNo door:line, since the duty has no page.keep_planorestimate: neither tool was available in this session.Checks:
bun scripts/gate.tspasses andbun x tsc --noEmitis clean.scripts/fast.tsnamed 2,291 test files (an estimated 194 minutes), so I picked the 26 that cover the change; they passed except onetest/maintain.test.tscase. That test drives whichever duty sorts first, now this one, and a $0 daily budget couldn't go back down to zero there. I gave the duty the same $1 headroommerged_brancheshas, and it passes now.test/account-purge.test.tschecks:To try it:
bun test test/account-purge.test.ts.🤖 Generated with Claude Code
Closes #15620