Repository navigation
fix(privacy): carry out account deletion requests after a 14-day grace period, with cancel (#1313) - #1320
Merged
Conversation
…e period, with cancel (#1313) A deletion request was a 'pending' row nothing read. It was in fact never written: POST /v1/account-deletion/worker answered 401 to every signed-in user because nothing on its path set supabaseAdmin. Now: - Migration 390: account_deletions gains scheduled_for (requested_at + 14 days, set by trigger, never by the client), cancelled_at, attempts, last_attempt_at and a 'cancelled' status, with one open request per worker. Every NO ACTION reference to a user becomes SET NULL (or CASCADE for a crew place and an interview booking), and inquiry_audit_log.actor_id is nullable, so the delete no longer fails on them. RESTRICT references stay as deliberate blockers. Service-only helpers: claim (SKIP LOCKED, retry delay), storage listing, purge of rows with no FK. - Migration 391: daily pg_cron at 06:15 UTC through a Vault-reading wrapper that raises when a secret is missing (377's pattern). - _shared/user-deletion.ts: the blocker check, reference release and delete, extracted from the office route, which keeps its behaviour (projects is now a blocker too; it used to 500). - account-deletion-process function + _shared/account-deletion: claim, blockers first, detach payment/background-check/ID rows, purge rows with no FK, remove files from every user-keyed bucket except background-check-documents, delete the auth user, send a confirmation email. Per-step flags in compliance_log (no PII); completed/partial/failed. Organization requests are left for manual handling. - API: GET /status and POST /cancel for the user; GET /v1/office/account-deletions for office. - App: a sign-in notice with the date and Cancel; the Settings panel shows a pending request; FAQ and org-deletion copy corrected. - Gated tests: processor against real DB/storage, REST routes, office delete. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… ratchet back within baseline - Regenerate types.ts (CI: "types.ts is stale"). - scheduled_for gets DEFAULT 'infinity', which the insert trigger reads as not given, so generated Insert types no longer require it. The two existing inserts (api route, legacy tRPC router) type-check again. - process.ts narrows result unions with `ok === false`: the shared functions/deno.json is not strict, so `!x.ok` did not narrow. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
|
CI fix pushed (19de233):
Migration 390 is amended in place: it hasn't been applied anywhere remote. Locally, the processor suite passes 6/6 and the edge type ratchet is within baseline. |
Contributor
📊 Performance Benchmark Results |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
📊 Performance Benchmark Results |
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.
Fixes #1313
Account deletion requests are now carried out. A request waits out a 14-day grace period, during which the user can sign in and cancel. After that a daily job deletes the account, keeps the legally retained records with the person's id removed, and emails a confirmation. That always lands inside the 30 days that Settings, the FAQ and the privacy policy promise.
Found on the way: no request has ever been recorded.
POST /v1/account-deletion/workeranswered 401 to every signed-in user, because nothing on its path setsupabaseAdmin(requireAuthonly). That explains whycore.account_deletionsis empty on all three projects. It is fixed here, and the gated REST test shows it red against the current runtime and green against this branch.What changed
Database (migrations 390, 391; local only, not applied anywhere else)
390
account_deletionsscheduled_for,cancelled_at,attempts,last_attempt_at, plus a'cancelled'status.scheduled_foris set by an insert trigger fromcore.account_deletion_grace_period()(14 days). That function is the only place the grace period lives.390 blocking foreign keys
Each foreign key is looked up by column, not by name, so an environment that skipped a migration does not fail.
account_deletions.requested_by_user_idorganization_payment_methods.created_bycredit_ledger.created_byhire_agreements.agreed_by_user_idapi_keys.created_by(now nullable)public.webhooks.created_byandpublic.webhooks.updated_byapplication_activity.actor_user_idprivacy_data_requests.processed_byeeo_reports.generated_byhiring_projects.created_byhiring_project_crew.assigned_byinterview_slots.proposed_by(now nullable)scheduling_links.created_by(now nullable)hris_connections.created_bybackground_check_providers.created_byuser_skills.verified_by,work_logs.verified_by_user_idandskill_evidence.verified_byhiring_project_crew.user_id,interview_bookings.candidate_id.inquiry_audit_log.actor_idis now nullable. It was NOT NULL with ON DELETE SET NULL, so deleting anyone who had acted on another person's inquiry raised an error. The test reproduces this before the migration.projects.created_by. These are content other people depend on.pg_constraintshows no NO ACTION reference to a user and no NOT NULL + SET NULL pair. Only those RESTRICT ones remain.390 service-only helpers
Each is
SECURITY DEFINER, usessearch_path = '', is revoked from PUBLIC/anon/authenticated and granted to service_role.claim_due_account_deletions:UPDATE … RETURNINGoverFOR UPDATE SKIP LOCKED. Retries wait 12 hours, and a row stuckin_progressis reclaimed after 1 hour. It never claims organization requests.account_deletion_storage_objects: lists a user's storage objects.account_deletion_purge_unlinked: clears rows that carry the user's id with no foreign key:archived_notifications,inquiry_comments.read_byandorganization_audit_log.actor_email.anonymize_worker_payment_data.391
core.run_account_deletion_processor()follows 377's pattern: it reads Vault and raises if a secret is missing.account-deletion-processruns daily at15 6 * * *.Shared deletion core
_shared/user-deletion.tsholdsfindDeletionBlockers,releaseNullableReferencesanddeleteAuthUser, extracted fromDELETE /v1/office/users/:id.blockedBy, 500 on a failed delete, and still 500 for an id that does not exist.projects.created_byis added to the blockers. That case used to 500 with an FK error.Edge function
account-deletion-processidsto re-run named requests, which are still only ones past their date._shared/account-deletion/process.ts):failed, the blocking tables are named, and nothing else is written.anonymize_worker_payment_data).compliance_log.steps, so a retry only redoes what did not finish. The log holds counts and timestamps only; the test asserts it contains neither the email nor the user id.completed,failed(stopped before anything was deleted, so the user can still cancel) orpartial(stopped after a deletion).error_messageis set for the last two. Retries continue up to 5 attempts._shared/account-deletion/policy.ts(buckets). The tables kept come fromanonymize_worker_payment_data, which that file names.needsManualHandling. The org panel's "All members will be notified" was false, and now says the team will carry it out within 30 days.API
POST /v1/account-deletion/workerscheduledForandcanCancel.GET /v1/account-deletion/status(new): the signed-in user's open request, ornull.POST /v1/account-deletion/cancel(new): one conditional UPDATE, so it can never race the processor's claim. Answers 404 when there is nothing to cancel, and 409 when deletion is already under way.GET /v1/office/account-deletions?filter=attention|all(new, office role): failed, partial, overdue (past 30 days) and organization requests.SDK (Scaffald/sdk#37, pointer bumped to that branch)
accountDeletion.getStatus(),cancel()andlistForOffice(), with MSW tests. Merge #37 first, then re-point the submodule to sdkmain.App
PendingDeletionNotice: on sign-in, a modal reads "Your account is scheduled for deletion on " with Cancel deletion and Close.(protected)/_layout.tsxas a sibling of<Slot />, never in place of it.AccountDeletionPanel):features/profile/utils/scheduledDeletion.ts, with a vitest test.How I verified (all local)
null value in column "actor_id" of relation "inquiry_audit_log".POST /worker→{"error":"Unauthorized"}for a signed-in user.tests/routers/account-deletion-process.test.ts(6/6) seeds a real user with: profile, csi skill, application, application message, notification, archived notification, an inquiry_audit_log row on someone else's inquiry, a background check, a payment transaction, avatar / resume / background-check-report files, and a task blocker. It asserts:{uid}/is empty exceptbackground-check-documents.account_deletionskeeps both user ids null and a PII-free log.scheduled_forand cancel-during-grace are covered.account-deletion-rest.test.ts(9/9) covers request, idempotency, status, cancel and its 404/409 cases, cross-user isolation, the trigger ignoring a client-sent date and status, anon 401, and the office list with a worker refused.office-users-delete-rest.test.ts(1/1): 409 withblockedBy, then success.GATED.txt.node scripts/check-migrations.mjspasses.node scripts/db/security-fingerprint.mjs check local: 0 new, 0 stale. Privileges checked on the objects withhas_function_privilege.deno fmt --checkanddeno lintpass infunctions/api, anddeno checkpasses on the new function and routes.tscfor scf-core and the app: 0 errors.nx run scf-core:test: 1631 passed, 0 failed.pnpm prepushpasses. Its gated tests ran against this branch's api, served on :8313, because the shared edge runtime serves another checkout.Deploy steps
For each env, in this order: dev, then preview, then prod. Nothing here has been applied or deployed.
edge_functions_urlandservice_role_keymust exist in Vault. They already do for the 337/362/377 crons, and 391's wrapper raises if they are missing. The service-role key must match the project's runtime key format (see fix(dev): migration 337 cannot be applied — dev is missing both vault secrets the notification cron depends on #564).RESEND_API_KEYmust be set for the confirmation email; without it the deletion still completes and the log records the email as not sent.390_account_deletion_processing.sql, then391_account_deletion_cron.sql(scripts/apply-migration.sh <env> …).node scripts/db/security-fingerprint.mjs check <env>andselect jobname, schedule from cron.job where jobname = 'account-deletion-process'.scripts/deploy-functions.sh <env>. It now includesaccount-deletion-processand shipsapi, which carries the new routes and the 401 fix.packages/sdkto sdkmainbefore this merges.select core.run_account_deletion_processor();then readnet._http_response. It should be a 200 withclaimed: 0.Needs legal sign-off
These are the working line Clay set on 2026-10-18 and may change. To change them, edit
_shared/account-deletion/policy.ts(buckets) orcore.anonymize_worker_payment_data(tables).payment_transactions.user_idsuccess_fees.worker_user_idbackground_checks.user_idbackground_check_consent.worker_user_idbackground_check_disputes.user_idid_verifications.worker_user_idbackground_checks: consent IP and user agent, consent signature, findings and summary, and encrypted results.background_check_consent: IP and user agent.id_verifications.verification_data(the Persona payload).background-check-documents/{uid}/…(background-check report files), until the FCRA retention period is confirmed.hire_agreements(agreed_by cleared)organization_audit_log(actor and actor email cleared)inquiry_audit_log(actor cleared)application_activity,circumvention_reports,content_reportsandoauth_app_audit_log(actor or user cleared)account_deletionsrow itself, including the free-textreasonthe user typedpublic.consent_records,public.audit_logandpublic.privacy_requests. They are keyed by user id with no foreign key; they may be compliance evidence or may be dead tables.oauth_apps.owner_email.🤖 Generated with Claude Code